Skip to content

Commit cf1781a

Browse files
committed
include-inherited
1 parent 89c41db commit cf1781a

File tree

1 file changed

+6
-2
lines changed
  • src/azure-cli/azure/cli/command_modules/role

1 file changed

+6
-2
lines changed

src/azure-cli/azure/cli/command_modules/role/custom.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def _search_role_assignments(cli_ctx, assignments_client, definitions_client,
578578
# "atScope()" and "principalId eq '{value}'" query cannot be used together (API limitation).
579579
# always use "scope" if provided, so we can get assignments beyond subscription e.g. management groups
580580
if scope:
581-
f = 'atScope()'
581+
f = 'atScope()' # atScope() excludes role assignments at subscopes
582582
if assignee_object_id and include_groups:
583583
f = f + " and assignedTo('{}')".format(assignee_object_id)
584584
assignments = list(assignments_client.list_for_scope(scope=scope, filter=f))
@@ -594,8 +594,12 @@ def _search_role_assignments(cli_ctx, assignments_client, definitions_client,
594594
worker = MultiAPIAdaptor(cli_ctx)
595595
if assignments:
596596
assignments = [a for a in assignments if (
597+
# If no scope, list all assignments
597598
not scope or
598-
include_inherited and re.match(worker.get_role_property(a, 'scope'), scope, re.I) or
599+
# If scope is provided with include_inherited, list assignments at and above the scope.
600+
# Note that assignments below the scope are already excluded by atScope()
601+
include_inherited or
602+
# If scope is provided, list assignments at the scope
599603
worker.get_role_property(a, 'scope').lower() == scope.lower()
600604
)]
601605

0 commit comments

Comments
 (0)