Repository navigation
Create missing Cosmos containers under managed identity - #1969
Merged
Paul Lizer (paullizer) merged 2 commits intoNov 20, 2026
Merged
Paul Lizer (paullizer) merged 2 commits into
Paul Lizer (paullizer) merged 2 commits into
Conversation
Cosmos refuses data-plane container creation for Entra-authenticated callers, so a release that added a container failed to start after azd deploy on a managed-identity deployment. The app now creates the missing container through Azure Resource Manager when that 403 happens, locating the account from AZURE_SUBSCRIPTION_ID/AZURE_RESOURCE_GROUP or, when absent, from App Service's own platform variables. - Declare all app containers in Bicep (11 missing) and Terraform (14 missing); rebuild main.json - Terraform and Azure CLI deployers set the Cosmos location settings - Add Grant-CosmosContainerCreatePermission.ps1 for identities without Contributor on the Cosmos account - Version 0.261.474, deployers 1.0.41 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Development took 0.261.474 for the catalog publisher keys, so this change moves to 0.261.475 with its own release-notes section, and the release note pages are regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
At startup the app calls
create_container_if_not_existsfor every Cosmos container. With key auth that creates any container a new release adds. With managed identity, Cosmos refuses container creation on its data-plane endpoint (403, substatus 5300) whatever data-plane role the identity holds, so the app failed to start afterazd deploy.azd deploydoesn't re-run Bicep, and Bicep was missing 11 of the app's containers anyway. Terraform was missing 14.Changes
functions_cosmos_container_provisioning.py,config.py): when the data-plane create returns 403 under managed identity, the app creates the container through Azure Resource Manager with the same partition key, TTL and indexing policy. It uses the Contributor role the deployers already grant. If the container already exists it writes nothing, and on a 202 it waits on the container resource. Key auth is unchanged.AZURE_SUBSCRIPTION_ID/AZURE_RESOURCE_GROUP, or, when those are absent, from App Service's ownWEBSITE_OWNER_NAME/WEBSITE_RESOURCE_GROUP. If the database isn't found there, the app creates nothing and logs which settings to set.main.jsonis rebuilt with Bicep 0.44.1.AZURE_SUBSCRIPTION_ID,AZURE_RESOURCE_GROUPandAZURE_COSMOS_ACCOUNT_NAME.deployers/Grant-CosmosContainerCreatePermission.ps1: for an identity without Contributor on the Cosmos account. It grants a narrow custom role (container read and write only) or, with-UseBuiltInRole, DocumentDB Account Contributor. Supports-WhatIf.Testing
functional_tests/test_cosmos_container_arm_provisioning.py(12 tests) passes. It fails if a container the app creates is missing or has a different partition key in Bicep,main.jsonor Terraform. It also covers the fallback paths and the deployer settings.scripts/check_cosmos_response_boundaries.py: no review gaps.main(stale pinned versions and other existing gaps).🤖 Generated with Claude Code