Skip to content

[AKS] Set principalType when creating role assignments#33586

Open
FumingZhang wants to merge 1 commit into
Azure:devfrom
FumingZhang:acs/role-assignment-principal-type
Open

[AKS] Set principalType when creating role assignments#33586
FumingZhang wants to merge 1 commit into
Azure:devfrom
FumingZhang:acs/role-assignment-principal-type

Conversation

@FumingZhang

Copy link
Copy Markdown
Member

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 principalType in the request body, except for --attach-acr when the user explicitly passed --assignee-principal-type.

When principalType is 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 with PrincipalNotFound, leading to flaky cluster create/update operations that have to be retried.

This PR sets principalType explicitly for the role assignments created by AKS:

  • add_role_assignment now defaults principalType to ServicePrincipal. Every internal caller targets either a service principal or a managed identity, both of which are represented as a ServicePrincipal in Microsoft Entra ID. The explicit value lets the Authorization RP skip the Entra ID existence check.
  • The Automatic SKU cluster-admin grant to the signed-in user now passes principalType=User. This path resolves the assignee via Microsoft Graph /me, which only succeeds for a delegated (interactive) user, so the principal is always a User.

A user-supplied --assignee-principal-type continues 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 without PrincipalNotFound retries.
  • az aks create -g <rg> -n <name> --sku automatic as an interactive user and confirm the cluster-admin role assignment is created with principalType=User.
  • Existing acs unit tests for role assignment continue to pass.

History Notes
[AKS] az aks create/update: Set principalType when creating role assignments to avoid PrincipalNotFound failures caused by Microsoft Entra ID replication delay

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.
Copilot AI review requested due to automatic review settings June 19, 2026 08:11
@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 19, 2026

Copy link
Copy Markdown
️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.14
️✔️acs
️✔️latest
️✔️3.12
️✔️3.14
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.14
️✔️ams
️✔️latest
️✔️3.12
️✔️3.14
️✔️apim
️✔️latest
️✔️3.12
️✔️3.14
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.14
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️aro
️✔️latest
️✔️3.12
️✔️3.14
️✔️backup
️✔️latest
️✔️3.12
️✔️3.14
️✔️batch
️✔️latest
️✔️3.12
️✔️3.14
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.14
️✔️billing
️✔️latest
️✔️3.12
️✔️3.14
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.14
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.14
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.14
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.14
️✔️config
️✔️latest
️✔️3.12
️✔️3.14
️✔️configure
️✔️latest
️✔️3.12
️✔️3.14
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.14
️✔️container
️✔️latest
️✔️3.12
️✔️3.14
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.14
️✔️core
️✔️latest
️✔️3.12
️✔️3.14
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.14
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.14
️✔️dls
️✔️latest
️✔️3.12
️✔️3.14
️✔️dms
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.14
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.14
️✔️find
️✔️latest
️✔️3.12
️✔️3.14
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.14
️✔️identity
️✔️latest
️✔️3.12
️✔️3.14
️✔️iot
️✔️latest
️✔️3.12
️✔️3.14
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.14
️✔️lab
️✔️latest
️✔️3.12
️✔️3.14
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️maps
️✔️latest
️✔️3.12
️✔️3.14
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.14
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.14
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.14
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.14
️✔️network
️✔️latest
️✔️3.12
️✔️3.14
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.14
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.14
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.14
️✔️profile
️✔️latest
️✔️3.12
️✔️3.14
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.14
️✔️redis
️✔️latest
️✔️3.12
️✔️3.14
️✔️relay
️✔️latest
️✔️3.12
️✔️3.14
️✔️resource
️✔️latest
️✔️3.12
️✔️3.14
️✔️role
️✔️latest
️✔️3.12
️✔️3.14
️✔️search
️✔️latest
️✔️3.12
️✔️3.14
️✔️security
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.14
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.14
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.14
️✔️sql
️✔️latest
️✔️3.12
️✔️3.14
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.14
️✔️storage
️✔️latest
️✔️3.12
️✔️3.14
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.14
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.14
️✔️util
️✔️latest
️✔️3.12
️✔️3.14
️✔️vm
️✔️latest
️✔️3.12
️✔️3.14

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 19, 2026

Copy link
Copy Markdown
️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 send principalType=ServicePrincipal when 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.

@yonzhan

yonzhan commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

AKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants