← Back to Pull requests

feat(backend): create MRG role assignments (IdentityRoleAssignments) #6784

Closed
unknown closed this pull request without merging on Sep 10, 2026 21:31 UTC
View on GitHub
unknown unknown commented on Sep 02, 2026 11:41 UTC
Author

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

  • Controller renamed 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, and docs/cosmos-data-flow.md are all updated). Doc comments flipped from "observes / strictly read-only" to "manages (creates + observes)".

  • syncRoleAssignments reconciles the expected control-plane / data-plane operator role assignments in two passes over the expected set:

  • - Pass 1 (classify): GetByID each expected assignment — existing → confirmed in AzureResources; missing → recorded in PendingAzureResources and 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 later GetByID.
  • Idempotency / error handling: role-assignment names are deterministic (UUIDv5 over principal + roleDefinition + scope), so a repeated same-name create is an update (PUT), not a conflict. Any Create error — including RoleAssignmentExists — 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.)

  • Cosmos precondition safety: if persisting the pending intent hits an optimistic-concurrency (precondition) failure, the cluster is re-enqueued after 10s and no create runs that pass — so pass 2 never runs on unpersisted/stale state.

  • Deterministic ordering: the expected slice is sorted before it is persisted, so map-iteration order does not cause redundant Cosmos writes / precondition churn.

  • Retention: a previously-confirmed assignment no longer in the expected set (e.g. after an identity/name-scheme change) is retained in AzureResources with a TODO; deletion is deferred to managed identity replacement support.

  • The cluster-create completion gate also gates on the role assignments being confirmed.
  • Earliest-recheck

    Re-verifies the confirmed set on a 6h interval with 50% jitter (window [now+6h, now+9h)), matching the EarliestRecheckTime convention documented on AzureMultiReference and 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, the roleassignments / operations / azure/client unit tests, and the repo-pinned golangci-lint all pass. Tests cover: not-found → persisted pending → create → confirmed on a later pass; create error (including RoleAssignmentExists) → 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.

    Diff: 498 lines (+373 / -125) across 6 files Reviewer: deads2k Review duration: 12109m
    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
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%
    Repository