-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[Role] az role assignment list/delete: Add --assignee-object-id
#30469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -209,7 +209,7 @@ def create_role_assignment(cmd, role, scope, | |||||||||||||||||||
| assignment_name=assignment_name) | ||||||||||||||||||||
| except Exception as ex: # pylint: disable=broad-except | ||||||||||||||||||||
| if _error_caused_by_role_assignment_exists(ex): # for idempotent | ||||||||||||||||||||
| return list_role_assignments(cmd, assignee=assignee, role=role, scope=scope)[0] | ||||||||||||||||||||
| return list_role_assignments(cmd, assignee_object_id=object_id, role=role, scope=scope)[0] | ||||||||||||||||||||
| raise | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -232,14 +232,19 @@ def _create_role_assignment(cli_ctx, role, assignee, resource_group_name=None, s | |||||||||||||||||||
| condition=condition, condition_version=condition_version) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=None, # pylint: disable=too-many-locals | ||||||||||||||||||||
| scope=None, include_inherited=False, | ||||||||||||||||||||
| def list_role_assignments(cmd, # pylint: disable=too-many-locals, too-many-branches | ||||||||||||||||||||
| assignee=None, assignee_object_id=None, | ||||||||||||||||||||
| role=None, | ||||||||||||||||||||
| resource_group_name=None, scope=None, | ||||||||||||||||||||
| include_inherited=False, | ||||||||||||||||||||
| show_all=False, include_groups=False, include_classic_administrators=False, | ||||||||||||||||||||
| fill_role_definition_name=True, fill_principal_name=True): | ||||||||||||||||||||
| ''' | ||||||||||||||||||||
| :param include_groups: include extra assignments to the groups of which the user is a | ||||||||||||||||||||
| member(transitively). | ||||||||||||||||||||
| ''' | ||||||||||||||||||||
|
Comment on lines
-239
to
-242
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||
| if assignee and assignee_object_id: | ||||||||||||||||||||
| raise CLIError('Usage error: Provide only one of --assignee or --assignee-object-id.') | ||||||||||||||||||||
| if assignee_object_id and include_classic_administrators: | ||||||||||||||||||||
| raise CLIError('Usage error: --assignee-object-id cannot be used with --include-classic-administrators. ' | ||||||||||||||||||||
| 'Use --assignee instead.') | ||||||||||||||||||||
|
Comment on lines
+244
to
+246
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Classic admin assignments use
When azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py Lines 471 to 478 in 7fbe2fe
This will trigger Graph call which is against the initial purpose. Moreover, as |
||||||||||||||||||||
|
|
||||||||||||||||||||
| if include_classic_administrators: | ||||||||||||||||||||
| logger.warning(CLASSIC_ADMINISTRATOR_WARNING) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -256,8 +261,10 @@ def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=Non | |||||||||||||||||||
| scope = _build_role_scope(resource_group_name, scope, | ||||||||||||||||||||
| definitions_client._config.subscription_id) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if assignee and not assignee_object_id: | ||||||||||||||||||||
| assignee_object_id = _resolve_object_id(cmd.cli_ctx, assignee, fallback_to_object_id=True) | ||||||||||||||||||||
| assignments = _search_role_assignments(cmd.cli_ctx, assignments_client, definitions_client, | ||||||||||||||||||||
| scope, assignee, role, | ||||||||||||||||||||
| scope, assignee_object_id, role, | ||||||||||||||||||||
| include_inherited, include_groups) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| results = todict(assignments) if assignments else [] | ||||||||||||||||||||
|
|
@@ -522,13 +529,19 @@ def _get_displayable_name(graph_object): | |||||||||||||||||||
| return graph_object['displayName'] or '' | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_group_name=None, | ||||||||||||||||||||
| scope=None, include_inherited=False, | ||||||||||||||||||||
| def delete_role_assignments(cmd, ids=None, | ||||||||||||||||||||
| assignee=None, assignee_object_id=None, | ||||||||||||||||||||
| role=None, | ||||||||||||||||||||
| resource_group_name=None, scope=None, | ||||||||||||||||||||
| include_inherited=False, | ||||||||||||||||||||
| yes=None): # pylint: disable=unused-argument | ||||||||||||||||||||
| # yes is currently a no-op | ||||||||||||||||||||
| if not any((ids, assignee, role, resource_group_name, scope)): | ||||||||||||||||||||
| if not any((ids, assignee, assignee_object_id, role, resource_group_name, scope)): | ||||||||||||||||||||
| raise ArgumentUsageError('Please provide at least one of these arguments: ' | ||||||||||||||||||||
| '--ids, --assignee, --role, --resource-group, --scope') | ||||||||||||||||||||
| '--ids, --assignee, --assignee-object-id, --role, --resource-group, --scope') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if assignee and assignee_object_id: | ||||||||||||||||||||
| raise CLIError('Usage error: Provide only one of --assignee or --assignee-object-id.') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| factory = _auth_client_factory(cmd.cli_ctx, scope) | ||||||||||||||||||||
| assignments_client = factory.role_assignments | ||||||||||||||||||||
|
|
@@ -559,8 +572,11 @@ def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_gr | |||||||||||||||||||
|
|
||||||||||||||||||||
| scope = _build_role_scope(resource_group_name, scope, | ||||||||||||||||||||
| assignments_client._config.subscription_id) | ||||||||||||||||||||
| # Delay resolving object ID, because if ids are provided, no need to resolve | ||||||||||||||||||||
| if assignee and not assignee_object_id: | ||||||||||||||||||||
| assignee_object_id = _resolve_object_id(cmd.cli_ctx, assignee, fallback_to_object_id=True) | ||||||||||||||||||||
| assignments = _search_role_assignments(cmd.cli_ctx, assignments_client, definitions_client, | ||||||||||||||||||||
| scope, assignee, role, include_inherited, | ||||||||||||||||||||
| scope, assignee_object_id, role, include_inherited, | ||||||||||||||||||||
| include_groups=False) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if assignments: | ||||||||||||||||||||
|
|
@@ -571,11 +587,7 @@ def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_gr | |||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def _search_role_assignments(cli_ctx, assignments_client, definitions_client, | ||||||||||||||||||||
| scope, assignee, role, include_inherited, include_groups): | ||||||||||||||||||||
| assignee_object_id = None | ||||||||||||||||||||
| if assignee: | ||||||||||||||||||||
| assignee_object_id = _resolve_object_id(cli_ctx, assignee, fallback_to_object_id=True) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| scope, assignee_object_id, role, include_inherited, include_groups): | ||||||||||||||||||||
| # https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-list-rest | ||||||||||||||||||||
| # "atScope()" and "principalId eq '{value}'" query cannot be used together (API limitation). | ||||||||||||||||||||
| # always use "scope" if provided, so we can get assignments beyond subscription e.g. management groups | ||||||||||||||||||||
|
|
||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
object_idinstead ofassigneesaves one Graph query foraz role assignment create.