-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Role] Fix --role filter failing at non-subscription scopes
#32534
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
base: dev
Are you sure you want to change the base?
Changes from 2 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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -540,7 +540,7 @@ def _search_role_assignments(assignments_client, definitions_client, | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if role: | ||||||||||||||||||||||||||
| role_id = _resolve_role_id(role, scope, definitions_client) | ||||||||||||||||||||||||||
| assignments = [ra for ra in assignments if ra.role_definition_id == role_id] | ||||||||||||||||||||||||||
| assignments = [ra for ra in assignments if ra.role_definition_id and ra.role_definition_id.endswith(role_id)] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # filter the assignee if "include_groups" is not provided because service side | ||||||||||||||||||||||||||
| # does not accept filter "principalId eq and atScope()" | ||||||||||||||||||||||||||
|
|
@@ -567,24 +567,25 @@ def _build_role_scope(resource_group_name, scope, subscription_id): | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def _resolve_role_id(role, scope, definitions_client): | ||||||||||||||||||||||||||
| role_id = None | ||||||||||||||||||||||||||
| if re.match(r'/subscriptions/.+/providers/Microsoft.Authorization/roleDefinitions/', | ||||||||||||||||||||||||||
| role, re.I): | ||||||||||||||||||||||||||
| role_id = role | ||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| if is_guid(role): | ||||||||||||||||||||||||||
| role_id = '/subscriptions/{}/providers/Microsoft.Authorization/roleDefinitions/{}'.format( | ||||||||||||||||||||||||||
| definitions_client._config.subscription_id, role) | ||||||||||||||||||||||||||
| if not role_id: # retrieve role id | ||||||||||||||||||||||||||
| role_defs = list(definitions_client.list(scope, "roleName eq '{}'".format(role))) | ||||||||||||||||||||||||||
| if not role_defs: | ||||||||||||||||||||||||||
| raise CLIError("Role '{}' doesn't exist.".format(role)) | ||||||||||||||||||||||||||
| if len(role_defs) > 1: | ||||||||||||||||||||||||||
| ids = [r.id for r in role_defs] | ||||||||||||||||||||||||||
| err = "More than one role matches the given name '{}'. Please pick a value from '{}'" | ||||||||||||||||||||||||||
| raise CLIError(err.format(role, ids)) | ||||||||||||||||||||||||||
| role_id = role_defs[0].id | ||||||||||||||||||||||||||
| return role_id | ||||||||||||||||||||||||||
| """Resolve a role to its full role definition resource ID from | ||||||||||||||||||||||||||
| - role definition resource ID (returned as-is) | ||||||||||||||||||||||||||
| - role definition GUID | ||||||||||||||||||||||||||
| - role name (e.g. 'Reader') | ||||||||||||||||||||||||||
atomassi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| if re.match(r'(/subscriptions/.+)?/providers/Microsoft.Authorization/roleDefinitions/', role, re.I): | ||||||||||||||||||||||||||
atomassi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
| return role | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if is_guid(role): | ||||||||||||||||||||||||||
| return f"/providers/Microsoft.Authorization/roleDefinitions/{role}" | ||||||||||||||||||||||||||
|
Member
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. I assume this is only a dummy resource ID because the
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. this is because this method is also used by the create role assignment path and it needs a full resource ID (not just a guid). azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py Lines 208 to 219 in 63606b2
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| role_defs = list(definitions_client.list(scope, "roleName eq '{}'".format(role))) | ||||||||||||||||||||||||||
| if not role_defs: | ||||||||||||||||||||||||||
| raise CLIError("Role '{}' doesn't exist.".format(role)) | ||||||||||||||||||||||||||
| if len(role_defs) > 1: | ||||||||||||||||||||||||||
| ids = [r.id for r in role_defs] | ||||||||||||||||||||||||||
| err = "More than one role matches the given name '{}'. Please pick a value from '{}'" | ||||||||||||||||||||||||||
| raise CLIError(err.format(role, ids)) | ||||||||||||||||||||||||||
| return role_defs[0].id | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def create_application(cmd, client, display_name, identifier_uris=None, | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.