feat(backend): create MRG role assignments (IdentityRoleAssignments) #6784
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 498 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.372
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #6784"
general
weight: 0.35
deads2k
Summary
Follow-up to #6681. Turns the managed-resource-group role-assignments controller from observe-only into a create lifecycle controller: the backend now creates the MRG-scoped role assignments for each control-plane and data-plane operator managed identity itself, instead of only observing the ones Cluster Service creates.
Scope is create only — deletion remains a no-op, since managed-resource-group deletion cascades the role assignments.
Behavior
ObserveRoleAssignments→IdentityRoleAssignments(the const is the single source of truth for the workqueue/metric name; wiring, the cluster-create-operation gate comment, the// Written by:status annotation, anddocs/cosmos-data-flow.mdare all updated). Doc comments flipped from "observes / strictly read-only" to "manages (creates + observes)".syncRoleAssignmentsreconciles the expected control-plane / data-plane operator role assignments in two passes over the expected set:- Pass 1 (classify):
GetByIDeach expected assignment — existing → confirmed inAzureResources; missing → recorded inPendingAzureResourcesand queued for creation. The pending/confirmed state is persisted to Cosmos before any create.- Pass 2 (create): create the queued missing assignments with
Properties{PrincipalID, RoleDefinitionID, PrincipalType: ServicePrincipal}(mirroring the Cluster Service steps). A freshly-created assignment stays pending this pass and is confirmed on a laterGetByID.Createerror — includingRoleAssignmentExists— is therefore surfaced and retried, not swallowed or promoted in-pass. (A future change will adopt an assignment that exists under a different name for the same principal + scope + roleDefinition; tracked by a TODO.)AzureResourceswith a TODO; deletion is deferred to managed identity replacement support.Earliest-recheck
Re-verifies the confirmed set on a 6h interval with 50% jitter (window
[now+6h, now+9h)), matching theEarliestRecheckTimeconvention documented onAzureMultiReferenceand the cadence used by the sibling identity-fetch controllers. A nil recheck time does one recheck on rollout, then a future time is set once pending is empty and all expected are confirmed. Any assignment that has since disappeared is re-created.Transition
Cluster Service continues to create these role assignments in parallel until this lands in production; the idempotent create makes the overlap safe, after which Cluster Service will stop creating them.
Testing
go build ./...,go vet, theroleassignments/operations/azure/clientunit tests, and the repo-pinnedgolangci-lintall pass. Tests cover: not-found → persisted pending → create → confirmed on a later pass; create error (includingRoleAssignmentExists) → surfaced, stays pending; existing → confirmed without create; pending intent persisted before any create; Cosmos precondition failure → re-enqueue, no create; deterministic expected ordering; steady-state → zero Azure calls; and the 6h recheck re-verify / re-create paths.---
AI-generated. Review for accuracy.