Skip to content

Support agent principal types in role assignments - #33810

Open
jruttle wants to merge 1 commit into
Azure:devfrom
jruttle:jruttle/agent-principaltype
Open

Support agent principal types in role assignments#33810
jruttle wants to merge 1 commit into
Azure:devfrom
jruttle:jruttle/agent-principaltype

Conversation

@jruttle

@jruttle jruttle commented Jul 29, 2026

Copy link
Copy Markdown
Member

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests
⚠️ None ️✔️ 130/130
⚠️AzureCLI-BreakingChangeTest
⚠️role
rule cmd_name rule_message suggest_message
⚠️ 1010 - ParaPropUpdate role assignment create cmd role assignment create update parameter assignee_principal_type: updated property choices from ['ForeignGroup', 'Group', 'ServicePrincipal', 'User'] to ['AgentServicePrincipal', 'AgentUser', 'ForeignGroup', 'Group', 'ServicePrincipal', 'User']

Summary

  • allow AgentUser and AgentServicePrincipal for az role assignment create --assignee-principal-type
  • map Microsoft Graph agentUser and agentIdentity objects to the matching Azure RBAC principal types
  • preserve agent principal types when resolving assignees by object ID, UPN, or service principal name

Testing

  • python -m unittest azure.cli.command_modules.role.tests.latest.test_role_custom

The values are part of the stable 2022-04-01 Authorization contract after Azure/azure-rest-api-specs#44846.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4c68fc8b-b668-4d31-bff0-292712a310b2
@jruttle
jruttle requested a review from a team as a code owner July 29, 2026 07:52
Copilot AI review requested due to automatic review settings July 29, 2026 07:52
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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 extends the role command module to support Azure RBAC agent principal types by (1) allowing AgentUser / AgentServicePrincipal for az role assignment create --assignee-principal-type, and (2) preserving those types when resolving assignees via Microsoft Graph lookups.

Changes:

  • Added RoleAssignmentPrincipalType enum (including agent principal types) and wired it into role assignment create argument parsing.
  • Extended Microsoft Graph @odata.type → ARM RBAC principalType mapping for agent objects and used it when resolving assignees by UPN/SPN.
  • Added unit tests covering the new enum values and resolution behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/azure-cli/azure/cli/command_modules/role/tests/latest/test_role_custom.py Adds tests validating agent principal type enum values and Graph-based resolution behavior.
src/azure-cli/azure/cli/command_modules/role/custom.py Adds agent principal type constants/mapping and preserves principal type based on Graph @odata.type during assignee resolution.
src/azure-cli/azure/cli/command_modules/role/_params.py Introduces a shared RoleAssignmentPrincipalType enum and uses it for --assignee-principal-type.

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

Comment on lines 381 to 384
# A temporary fix for https://github.com/Azure/azure-cli/issues/11594
# As only 'User', 'Group' or 'ServicePrincipal' are allowed values, the REST spec contains invalid values
# (like MSI) which are used only internally by the service. So hide them.
# https://github.com/Azure/azure-rest-api-specs/blob/962013a1cf9bf5b87e3aad75a14c7dd620acda62/specification/authorization/resource-manager/Microsoft.Authorization/preview/2020-04-01-preview/authorization-RoleAssignmentsCalls.json#L508-L522
@a0x1ab

a0x1ab commented Jul 29, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

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