Skip to content

Update "AKS RBAC Writer" role scope to managed ns#2003

Open
bosesuneha wants to merge 1 commit intoAzure:mainfrom
bosesuneha:update-role-scope
Open

Update "AKS RBAC Writer" role scope to managed ns#2003
bosesuneha wants to merge 1 commit intoAzure:mainfrom
bosesuneha:update-role-scope

Conversation

@bosesuneha
Copy link
Member

This pull request refactors the role assignment logic for managed namespaces in the AKS OIDC setup command. The main change is to unify the scope used for both Kubernetes data-plane RBAC and ARM operations by removing the separate Kubernetes namespace scope and using the managed namespace scope instead.

Role assignment scope simplification:

  • Removed the use of getScopeForKubernetesNamespace and now use getScopeForManagedNamespace for both RBAC and ARM role assignments, simplifying the logic and reducing potential confusion about scope usage. [1] [2] [3]

@Tatsinnit Tatsinnit requested review from Copilot and gambtho and removed request for gambtho March 19, 2026 23:19
@Tatsinnit Tatsinnit added the enhancement 🚀 New feature or request or improvements on existing code. label Mar 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors managed-namespace role assignment scoping in the AKS OIDC setup flow, aiming to simplify scope handling by using the managed namespace scope for multiple role assignments.

Changes:

  • Removes use of the Kubernetes namespace (/namespaces/{ns}) scope for managed namespaces.
  • Uses the managed namespace (/managedNamespaces/{ns}) scope for the AKS RBAC Writer assignment in managed namespaces.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 683 to 692
// Assign all roles concurrently — they are independent
const [rbacResult, nsContribResult, acrResult, acrTasksResult] = await Promise.all([
// K8s data-plane access (deployments, configmaps, etc.)
createRoleAssignment(
authClient,
subscriptionId,
principalId,
AKS_RBAC_WRITER_ROLE_ID,
k8sNsScope,
managedNsScope,
"ServicePrincipal",
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes the managed-namespace role assignment scope for AKS RBAC Writer, but there are no unit tests in oidcSetup.test.ts covering role assignment/scoping behavior. Adding a test that stubs createRoleAssignment and asserts the expected scope(s) for managed namespaces would help prevent regressions in deployment permissions.

Copilot uses AI. Check for mistakes.
Comment on lines 688 to 692
subscriptionId,
principalId,
AKS_RBAC_WRITER_ROLE_ID,
k8sNsScope,
managedNsScope,
"ServicePrincipal",
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AKS_RBAC_WRITER_ROLE_ID is described elsewhere as a Kubernetes data-plane RBAC role that scopes to /namespaces/{ns} (not /managedNamespaces/{ns}). Switching the role assignment scope to managedNsScope here is likely to make the AKS RBAC Writer assignment ineffective for kubectl operations in managed namespaces, despite the comment saying this grants data-plane access. Consider restoring the /namespaces/{ns} scope for AKS RBAC Writer (and keep /managedNamespaces/{ns} for the ARM-only AKS Namespace Contributor role), or update the scope helpers/docs if Azure now truly supports data-plane RBAC on managedNamespaces.

Copilot uses AI. Check for mistakes.
@Tatsinnit Tatsinnit requested a review from davidgamero March 20, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 🚀 New feature or request or improvements on existing code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants