feat(infra) grant Cosmos data-plane RBAC to developer principal in Bicep#60
Merged
Conversation
Caught on the first --ensure-cosmos-containers smoke-test after the
Phase 1 deploy: Cosmos NoSQL containers need a SEPARATE data-plane
role assignment (sqlRoleAssignments) on top of the ARM-level RBAC.
Without it, every read/write fails with:
Forbidden (403); Substatus: 5301; Reason: Request blocked by Auth ...
principal does not have required RBAC permissions to perform action
[Microsoft.DocumentDB/databaseAccounts/readMetadata] on resource [/]
The original Bicep author flagged this gap explicitly in the
developer-RBAC comment block as 'data-plane; assigned via az SQL
role-assignment, not RBAC role-assignment - out of scope here'. Time
to close it.
Adds:
resource cosmosDataContributor
'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2024-08-15'
Granting role 00000000-0000-0000-0000-000000000002 (Cosmos DB Built-in
Data Contributor) scoped to the Cosmos account root. Gates on
!empty(developerObjectId) only, NOT on deployPhase2 — Cosmos itself
is Phase 1, and read/write is needed to validate the deploy via
--ensure-cosmos-containers.
The developer-RBAC comment block is updated: the 'out of scope here'
note for the Cosmos role is removed, replaced with a description of
how Cosmos data-plane uses a SEPARATE Bicep namespace from the
standard Microsoft.Authorization/roleAssignments used by the other
RBAC entries.
Idempotent re-deploy against the existing Phase 1 account: only the
new role assignment is added; everything else is no-op. After this
PR lands, future Phase 1 deploys will not need the manual
'az cosmosdb sql role assignment create' workaround.
Pre-push self-audit: 7-item mechanical (all pass). /local-review
skipped — single Bicep resource addition with a doc-comment update;
the role definition GUID is Azure's well-known built-in.
This was referenced May 4, 2026
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.
Summary
Closes the Cosmos data-plane RBAC gap that the original Bicep author explicitly deferred:
Caught it on the first
--ensure-cosmos-containerssmoke-test post-deploy:ARM-level RBAC (the other 5 role assignments in the developer-RBAC block) doesn't cover Cosmos NoSQL data-plane operations. Cosmos uses a separate Bicep type —
Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments— under the database account itself. Built-in role00000000-0000-0000-0000-000000000002(Cosmos DB Built-in Data Contributor) covers the read/write needed byCosmosBootstrapper.EnsureCreatedAsyncand the productionMachineRepository/IngestionSourceRepositorypaths.Gates on
!empty(developerObjectId)only — NOT ondeployPhase2. Cosmos itself is Phase 1 and read/write is needed to validate the deploy.The developer-RBAC comment block is updated: removed the "out of scope here" note for the Cosmos role; added a paragraph explaining the Bicep-namespace difference so the next reader doesn't try to consolidate this with the standard
Microsoft.Authorization/roleAssignmentsblock.Test Plan
az bicep build-> exit 0 (Bicep compiles clean)dotnet build/dotnet test-> 503 / 503 unchanged (pure IaC change)pwsh ./infra/scripts/Deploy-SharedResources.ps1 -Environment devagainst the existing Phase 1 deploy. ARM is idempotent for everything that already exists; only the newcosmosDataContributorresource is added. Thendotnet run --project src/PinballWizard.Cli -- --ensure-cosmos-containersshould print:Out of Scope
if (deployPhase2 && ...). Splitting into separate blocks adds noise without clarity.Cosmos DB Built-in Data Contributoron their managed identities; a follow-up PR adds those role assignments at the same time the ACA env is provisioned.Checklist
TODO/FIXME/ commented-out code committedPre-push self-audit
Step 0 —
/local-review(qualitative)Step 1 — Mechanical checklist
*Optionsproperty has at least one real getter call insrc/— N/A (no code change)sqlRoleAssignmentsresource sits alongside the 5 existingMicrosoft.Authorization/roleAssignmentsresources; gating differs (Cosmos is Phase 1) and that's documented in the comment blockcatch { }— N/AISourceScraper? — N/Adotnet buildunaffected;az bicep buildclean)git log -1 --format='%an <%ae>'shows personal noreply, not work email