{AKS} AI Manager Grant the caller built-in roles on create and namespace add - #10237
Conversation
On success, `az aimanager create` and `az aimanager namespace add` grant the caller the built-in 'Azure AIManager Contributor' (ARM RBAC) and 'Azure AIManager and namespace RBAC Reader' (Kubernetes RBAC) roles on the new resource's scope. Best-effort: a successful create/add never fails because of the grant; if the caller is not an Owner or User Access Administrator a warning with the `az role assignment create` remediation is printed. Idempotent; resolves the caller as a user or service principal. Skipped with --no-wait or the new --skip-role-assignments flag. Bump aimanager 1.4.1 -> 1.5.0.
|
Hi PugDeveloper, |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds a best-effort post-create RBAC bootstrap for the aimanager extension so that the caller automatically receives the built-in roles needed to manage/read newly created AI Managers and namespaces, plus introduces an opt-out flag and updates extension metadata/docs.
Changes:
- Grant the caller
Azure AIManager ContributorandAzure AIManager and namespace RBAC Readerafter successfulaz aimanager create/az aimanager namespace add(skipped on--no-waitand with--skip-role-assignments). - Introduce role/role-name constants and a new
_roleassignments.pyhelper with idempotent, best-effort assignment logic. - Bump extension version to
1.5.0and add unit tests covering wiring and role assignment behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/aimanager/setup.py | Bumps extension version to 1.5.0. |
| src/aimanager/HISTORY.rst | Documents the new caller role-grant behavior and opt-out flag. |
| src/aimanager/azext_aimanager/custom.py | Wires post-success role assignment into create/namespace add flows. |
| src/aimanager/azext_aimanager/constants.py | Adds role GUID constants and friendly names for warnings/remediation. |
| src/aimanager/azext_aimanager/_roleassignments.py | Implements best-effort, idempotent role assignment for the caller. |
| src/aimanager/azext_aimanager/_params.py | Adds --skip-role-assignments to create and namespace add. |
| src/aimanager/azext_aimanager/_help.py | Updates help text and examples to describe the new behavior. |
| src/aimanager/azext_aimanager/tests/latest/test_roleassignments.py | Unit tests for role assignment helper behavior (idempotency, mismatch retry, etc.). |
| src/aimanager/azext_aimanager/tests/latest/test_aimanager.py | Unit tests for command wiring and skip/no-wait behavior. |
Suppressed comments (1)
src/aimanager/azext_aimanager/tests/latest/test_aimanager.py:90
- Same issue as
test_create_skips_roles_when_flag_set: this test treatsskip_role_assignments=Trueas implying--no-wait(noLongRunningOperationcall). The flag should skip role grants but still wait for successful namespace creation unless--no-waitwas requested.
def test_namespace_add_skips_roles_when_flag_set(self, _construct, mock_assign, _sub, mock_lro):
custom.add_aimanager_namespace(
self.cmd, self.client, "rg", "aim", "team-alpha", skip_role_assignments=True)
mock_assign.assert_not_called()
mock_lro.assert_not_called()
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
--skip-role-assignments now only opts out of the caller role grant. The command still waits for the create LRO and returns the resource, matching the amg create pattern; only --no-wait returns the poller and skips the grant. Suppress the no-wait "roles skipped" warning when the caller also passed --skip-role-assignments. Fix the two skip-flag wiring tests and add combined --no-wait --skip-role-assignments coverage for the new branch.
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
AKS |
| with self.argument_context('aimanager create') as c: | ||
| c.argument('location', arg_type=get_location_type(self.cli_ctx), | ||
| validator=get_default_location_from_resource_group) | ||
| c.argument('skip_role_assignments', action='store_true', |
There was a problem hiding this comment.
Do we need to have this flag --skip-role-assignments? I think by default roles are assigned, user cannot skip
There was a problem hiding this comment.
ah no we do not, just notice was referencing another feature that had admin access. Removed
| return claims.get('oid'), principal_type | ||
|
|
||
|
|
||
| def assign_caller_roles(cmd, scope, role_definition_ids): |
There was a problem hiding this comment.
Totally I think we need to assign two roles. Just want to make sure when we assign the first role, if the role has been assigned by user themselves before the AIManager creation successfully, it will get something like "the role has existed". This returned message should not block the second role to be assigned.
There was a problem hiding this comment.
added a test to confirm this won't be an issue
|
Jessie (@techworldhello) please help to review, thanks |
…ssignments Remove the --skip-role-assignments opt-out. On success the caller is always granted the two built-in roles (best-effort), matching az aks create (Automatic SKU) and az fleet, neither of which exposes a caller opt-out. --no-wait still skips the grant and warns. Tests: drop the flag-specific cases; assert the --no-wait warning fires; add a test that an "already exists" response on the first role does not block the second.
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
--skip-role-assignments flag is mentioned in the PR description, maybe forget to update the PR description? |
| otherwise the poller. With --no-wait the grant is skipped and the poller is returned, since | ||
| the command returns before the operation completes and success cannot be confirmed. | ||
| """ | ||
| if no_wait: |
There was a problem hiding this comment.
If user entered --no-wait in the command line, the role assignment will not happen correct?
There was a problem hiding this comment.
Maybe the current approach is correct, I will approve it. If there is anything that needs to improve the code experience, we can update that in the follow up PR.
|
[Release] Update index.json for extension [ aimanager-1.5.0 ] : https://dev.azure.com/msazure/One/_build/results?buildId=177418534&view=results |
🤖 PR Validation — ️✔️ All clear
Related command
az aimanager create,az aimanager namespace addDescription
When an AI Manager or a namespace is created, the caller is now granted two built-in roles on the new resource's scope, so the creator can immediately manage and read what they created without a separate role-assignment step:
Azure AIManager Contributor(ARM / management-plane) —413f2675-4911-4010-be3b-c720b43a3c59Azure AIManager and namespace RBAC Reader(Kubernetes RBAC) —9c77f8a7-b0b9-4462-844c-de6e66add8baBehavior:
az aimanager create(aiManager scope) andaz aimanager namespace add(namespace scope), only after the create long-running operation succeeds.Microsoft.Authorization/roleAssignments/write), a warning with the exactaz role assignment createremediation is printed and the command continues.--no-wait(success cannot be confirmed) and with the new--skip-role-assignmentsopt-out flag.Extension version: aimanager
1.4.1->1.5.0.General Guidelines
azdev style aimanagerlocally? (pylint + flake8 PASSED)python scripts/ci/test_index.py -qlocally? (OK)--skip-role-assignmentsargument).About Extension Publish
Updated
setup.pyVERSION to1.5.0and added aHISTORY.rstentry;src/index.jsonnot modified.