{"id":8793,"date":"2024-10-09T07:00:46","date_gmt":"2024-10-09T14:00:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=8793"},"modified":"2024-10-11T08:17:33","modified_gmt":"2024-10-11T15:17:33","slug":"introducing-rbac-authentication-and-more-for-the-azure-cosmos-db-integrated-cache","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/introducing-rbac-authentication-and-more-for-the-azure-cosmos-db-integrated-cache\/","title":{"rendered":"Introducing RBAC Authentication and more for the Azure Cosmos DB Integrated Cache"},"content":{"rendered":"<p>We\u2019re excited to announce new features for the Azure Cosmos DB integrated cache! The integrated cache is built into the <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/dedicated-gateway\">dedicated gateway<\/a>, and now there\u2019s new ways to authenticate your requests. Security is top of mind for many organizations, and you can now use Role-Based Access Control (RBAC) with Microsoft Entra ID to authenticate to the dedicated gateway, eliminating the security risks and complications that come with key-based authentication. Additionally, there\u2019s a new request option that gives you fine grained control over which requests populate the integrated cache.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai.jpg\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-8802\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai-1024x585.jpg\" alt=\"Pixelated image of a lock and pixelated people standing around it.\" width=\"1024\" height=\"585\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai-1024x585.jpg 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai-300x171.jpg 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai-768x439.jpg 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai-1536x878.jpg 1536w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/10\/rbac_ai.jpg 1792w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<h2>RBAC authentication with Microsoft Entra ID<\/h2>\n<p>One of the most exciting updates is support for RBAC authentication using Microsoft Entra ID. You no longer have to rely on your Azure Cosmos DB account&#8217;s primary key for authenticating to the dedicated gateway and integrated cache. Now, you can connect with Entra ID, which improves security and streamlines managing access permissions. Entra ID&#8217;s integration allows for more granular control over who can access your data, making it easier to adhere to your organization&#8217;s security policies.<\/p>\n<p>The dedicated gateway uses the same permissions, role definitions and role assignments as Azure Cosmos DB. If you already have RBAC configured for data plane operations in your Azure Cosmos DB account, you can also use it for authenticating to the dedicated gateway. The permission model is based on <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/security\/reference-data-plane-actions\">actions<\/a> that map to database operations (create item, read item etc.), and there are no actions or roles specific to operations that use the dedicated gateway or integrated cache.<\/p>\n<h3>How to configure RBAC roles and assignments<\/h3>\n<p>Learn how to configure RBAC roles and assignments for the dedicated gateway. If you already have RBAC configured for data plane operations in your Azure Cosmos DB account, you can skip this section and move on to updating your application to use RBAC with the dedicated gateway.<\/p>\n<p>Role definitions contain a list of permissions for allowed user actions. For some cases, the built-in role definitions are sufficient, or you can <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/security\/how-to-grant-data-plane-role-based-access?tabs=custom-definition%2Ccsharp&amp;pivots=azure-interface-cli#prepare-role-definition\" target=\"_blank\" rel=\"noopener\">create your own custom role definitions<\/a>. The<a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/security\/reference-data-plane-roles\" target=\"_blank\" rel=\"noopener\"> two built-in role definitions<\/a> are Cosmos DB Built-in Data Reader and Cosmos DB Built-in Data Contributor.<\/p>\n<p>Once you have a role definition, assign it to a user. To assign role permissions, you\u2019ll need the ID of the role definition and the ID of the user account or service principal that will connect to the dedicated gateway. For this example, we\u2019ll use the Cosmos DB Built-in Data Contributor role and a user account.<\/p>\n<ol>\n<li>Sign in to the Azure CLI and find or change your current subscription.<\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">az login\r\naz account set --subscription \"&lt;subscription ID or name&gt;\"<\/code><\/pre>\n<ol start=\"2\">\n<li>Retrieve the details of your account using the <em>az ad user show <\/em>command<em>.<\/em>\u00a0Copy the value of the <em>id<\/em> property and save it for use in the next step.<\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">az ad user show -\u2013id \u201c&lt;Your email address&gt;\u201d<\/code><\/pre>\n<ol start=\"3\">\n<li>Assign the built-in Cosmos DB Built-in Data Contributor role to your user account using the <em>az cosmosdb sql role assignment create<\/em> Each built-in role has its own ID, and you can find them in the <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/cosmos-db\/how-to-setup-rbac#built-in-role-definitions\" target=\"_blank\" rel=\"noopener\">built-in role definitions chart<\/a>.<\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">az cosmosdb sql role assignment create \\\r\n    --account-name &lt;Your Azure Cosmos DB account name&gt; \\\r\n    --resource-group &lt;Your resource group name&gt; \\\r\n    --scope \"\/\" \\\r\n    --principal-id &lt;Your user id from step 2&gt;  \\\r\n    --role-definition-id \u201c00000000-0000-0000-0000-000000000002\u201d\r\n<\/code><\/pre>\n<h3>Update your application to use RBAC with the dedicated gateway<\/h3>\n<p>Once you\u2019ve created your roles and role assignments, you can use <em>DefaultAzureCredential()<\/em> from the <em>Azure.Identity<\/em> package to authenticate your <em>CosmosClient<\/em>. There are no other application changes required to use RBAC authentication with the dedicated gateway. This example uses the Azure Cosmos DB .NET SDK, however RBAC authentication is supported in all SDKs.<\/p>\n<ol>\n<li>Install the <em>Azure.Identity<\/em> package<\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">dotnet add package Azure.Identity<\/code><\/pre>\n<ol start=\"2\">\n<li>Add the following code at the top of your file where the <em>CosmosClient<\/em> is created<\/li>\n<\/ol>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">using Azure.Identity;<\/code><\/pre>\n<ol start=\"3\">\n<li>Modify the code to create your <em>CosmosClient<\/em>. All dedicated gateway endpoints follow the same pattern <em>&lt;Your Azure Cosmos DB account name&gt;.sqlx.cosmos.azure.com<\/em><\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">CosmosClient client = new(\r\n    accountEndpoint: \u201chttps:\/\/&lt;Your Azure Cosmos DB account name&gt;.sqlx.cosmos.azure.com:443\/\u201d, \r\n    tokenCredential: new DefaultAzureCredential()\r\n);<\/code><\/pre>\n<h2>Fine-grained options for caching requests<\/h2>\n<p>Azure Cosmos DB&#8217;s dedicated gateway now includes an <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/integrated-cache#bypass-the-integrated-cache\" target=\"_blank\" rel=\"noopener\">option to bypass the integrated cache<\/a> per request. By selectively bypassing the cache, you can ensure that only the most critical and frequently accessed data occupies the limited cache space. This reduces the likelihood of important data being evicted, optimizing the performance for high-priority queries and items. Requests that bypass the cache are still routed through the dedicated gateway and are served from the backend, costing RUs.<\/p>\n<h3>Strategic cache management<\/h3>\n<p>The ability to bypass the integrated cache empowers you to make strategic decisions about cache usage. All read and write requests from clients configured with the dedicated gateway endpoint populate the cache by default. By directing one-off requests not to use the cache, you free up space for data and queries that are more likely to be repeated. This helps maintain a high cache hit rate and increase RU savings potential. For example, if a query is frequently repeated, but users rarely request the second or third page of data, you can bypass the cache on these trips while keeping the first page in the cache.<\/p>\n<h3>How to bypass the integrated cache<\/h3>\n<p>The bypass integrated cache request option is available in the Azure Cosmos DB .NET, Java and JavaScript SDKs. The following example shows how to bypass the integrated cache for a query using the .NET SDK.<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">FeedIterator&lt;MyClass&gt; myQuery = container.GetItemQueryIterator&lt;MyClass&gt;(new QueryDefinition(\"SELECT * FROM c\"), requestOptions: new QueryRequestOptions\r\n        {\r\n            DedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions \r\n            { \r\n                BypassIntegratedCache = true\r\n            }\r\n        }\r\n);\r\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>Azure Cosmos DB&#8217;s latest updates to the dedicated gateway and integrated cache offer enhanced flexibility and control, making it easier to manage authentication and optimize cache usage. Whether you are seeking to improve security with RBAC authentication via Microsoft Entra ID or aiming to fine-tune your cache strategy with selective bypass options, these features provide powerful tools to help you achieve your goals.<\/p>\n<h2>Learn more<\/h2>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/integrated-cache\" target=\"_blank\" rel=\"noopener\">Azure Cosmos DB integrated cache | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/dedicated-gateway\" target=\"_blank\" rel=\"noopener\">Azure Cosmos DB dedicated gateway | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/how-to-configure-integrated-cache#bypass-the-integrated-cache\" target=\"_blank\" rel=\"noopener\">How to configure the Azure Cosmos DB integrated cache | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/security\/how-to-grant-data-plane-role-based-access\" target=\"_blank\" rel=\"noopener\">Use data plane role-based access control &#8211; Azure Cosmos DB for NoSQL | Microsoft Learn<\/a><\/li>\n<\/ul>\n<h2><b>Leave a review<\/b><\/h2>\n<p>Tell us about your Azure Cosmos DB experience! Leave a review on PeerSpot and we\u2019ll gift you $50. <a href=\"https:\/\/peerspotdotcom.my.site.com\/proReviews\/?SalesOpportunityProduct=00kPy000004TKXJIA4&amp;productPeerspotNumber=30881&amp;CalendlyAccount=peerspot&amp;CalendlyFormLink=peerspot-product-reviews-ps-gc-vi-sf-50&amp;giftCard=50\">Get started here<\/a>.<\/p>\n<h2><b>About Azure Cosmos DB<\/b><\/h2>\n<p>Azure Cosmos DB is a fully managed and serverless NoSQL and vector database for modern app development, including AI applications. With its SLA-backed speed and availability as well as instant dynamic scalability, it is ideal for real-time NoSQL and MongoDB applications that require high performance and distributed computing over massive volumes of NoSQL and vector data.<\/p>\n<p><a href=\"https:\/\/cosmos.azure.com\/try\/\">Try Azure Cosmos DB for free here.<\/a> To stay in the loop on Azure Cosmos DB updates, follow us on <a href=\"https:\/\/twitter.com\/AzureCosmosDB\" target=\"_blank\" rel=\"noopener\">X<\/a>, <a href=\"https:\/\/aka.ms\/AzureCosmosDBYouTube\" target=\"_blank\" rel=\"noopener\">YouTube<\/a>, and <a href=\"https:\/\/www.linkedin.com\/company\/azure-cosmos-db\/\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re excited to announce new features for the Azure Cosmos DB integrated cache! The integrated cache is built into the dedicated gateway, and now there\u2019s new ways to authenticate your requests. Security is top of mind for many organizations, and you can now use Role-Based Access Control (RBAC) with Microsoft Entra ID to authenticate to [&hellip;]<\/p>\n","protected":false},"author":94159,"featured_media":8802,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-8793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-sql-api"],"acf":[],"blog_post_summary":"<p>We\u2019re excited to announce new features for the Azure Cosmos DB integrated cache! The integrated cache is built into the dedicated gateway, and now there\u2019s new ways to authenticate your requests. Security is top of mind for many organizations, and you can now use Role-Based Access Control (RBAC) with Microsoft Entra ID to authenticate to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/8793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/94159"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=8793"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/8793\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/8802"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=8793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=8793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=8793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}