[AKS] Set principalType when creating role assignments#33586
Open
FumingZhang wants to merge 1 commit into
Open
[AKS] Set principalType when creating role assignments#33586FumingZhang wants to merge 1 commit into
FumingZhang wants to merge 1 commit into
Conversation
Default the principal type to ServicePrincipal for internal AKS role assignments (service principals and managed identities), and User for the Automatic SKU cluster-admin grant to the signed-in user. Providing the principal type lets the Authorization RP skip the Entra ID existence check, avoiding PrincipalNotFound failures from replication delay for freshly created identities.
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces flakiness in AKS role-assignment creation by explicitly setting principalType in role assignment create requests, avoiding Microsoft Entra ID replication-delay PrincipalNotFound failures when the Authorization RP performs existence checks.
Changes:
- Default
add_role_assignment()to sendprincipalType=ServicePrincipalwhen the caller doesn’t specify an override. - For Automatic SKU’s cluster-admin grant to the signed-in interactive user, send
principalType=User. - Add clarifying comments explaining why the principal type is deterministic for these call paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py |
Sets assignee_principal_type="User" for Automatic SKU cluster-admin role assignment created for the signed-in interactive user. |
src/azure-cli/azure/cli/command_modules/acs/_roleassignments.py |
Defaults role assignment creation to principalType=ServicePrincipal when unspecified, while preserving explicit user overrides. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
AKS |
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.
Related command
az aks create,az aks update,az aks nodepool add(and any AKS command that creates role assignments, e.g.--attach-acr, app routing, kubelet identity, Automatic SKU cluster-admin grant)Description
AKS commands create a number of role assignments on behalf of the user (attach-acr, app routing DNS zone / key vault, VNet subnet, kubelet identity, Automatic SKU cluster-admin, etc.). Until now these assignments were created without specifying the
principalTypein the request body, except for--attach-acrwhen the user explicitly passed--assignee-principal-type.When
principalTypeis omitted, the Authorization RP performs an existence check against Microsoft Entra ID for the principal. For freshly created identities (e.g. a just-provisioned managed identity), Entra ID replication delay can cause this check to fail withPrincipalNotFound, leading to flaky cluster create/update operations that have to be retried.This PR sets
principalTypeexplicitly for the role assignments created by AKS:add_role_assignmentnow defaultsprincipalTypetoServicePrincipal. Every internal caller targets either a service principal or a managed identity, both of which are represented as aServicePrincipalin Microsoft Entra ID. The explicit value lets the Authorization RP skip the Entra ID existence check.principalType=User. This path resolves the assignee via Microsoft Graph/me, which only succeeds for a delegated (interactive) user, so the principal is always aUser.A user-supplied
--assignee-principal-typecontinues to take precedence and is unaffected.Testing Guide
az aks create -g <rg> -n <name> --attach-acr <acr>against a brand-new managed identity / ACR and confirm the role assignment succeeds withoutPrincipalNotFoundretries.az aks create -g <rg> -n <name> --sku automaticas an interactive user and confirm the cluster-admin role assignment is created withprincipalType=User.History Notes
[AKS]
az aks create/update: SetprincipalTypewhen creating role assignments to avoidPrincipalNotFoundfailures caused by Microsoft Entra ID replication delay