Skip to content
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

az role assignment delete fails if the assignee principal no longer exists #20349

Open
jiasli opened this issue Nov 16, 2021 · 3 comments
Open

Comments

@jiasli
Copy link
Member

jiasli commented Nov 16, 2021

Describe the bug

Customer is Trying to remove RBAC role assignments for users/groups/service principals that no longer exist using azure cli and he is receiving the below error message (this was working in the past but stopped working a week ago):

Command used:

az role assignment delete --role 'Monitoring Reader' --Assignee xxx --Scope xxx

Error message they are getting:

ERROR: Cannot find user or service principal in graph database for xxx'. If the assignee is an appId, make sure the corresponding service principal is created with 'az ad sp create --id xxx'`
@ghost ghost added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Nov 16, 2021
@jiasli jiasli self-assigned this Nov 16, 2021
@jiasli
Copy link
Member Author

jiasli commented Nov 16, 2021

Before deleting the role assignment, CLI will call _resolve_object_id_and_type to resolve the assignee to objectId:

If assignee is neither an appId or objectId, CLI raises error:

if not result:
raise CLIError("Cannot find user or service principal in graph database for '{assignee}'. "
"If the assignee is an appId, make sure the corresponding service principal is created "
"with 'az ad sp create --id {assignee}'.".format(assignee=assignee))

This behavior has been there since 2016-07-27 (#553) and the error message was later polished by #12617.

I am not sure if changing this behavior is a good idea, as it also affects

  • az role assignment create
  • az role assignment list

as _resolve_object_id_and_type is also called by these commands: non-existing objectId results in failure. Changing this behavior will certainly be a breaking change.

Workaround

Please use --ids argument to delete the role assignment if assignee doesn't exist anymore, such as:

az role assignment delete --ids /subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/acctestRG-ibt-24/providers/Microsoft.Authorization/roleAssignments/f2774385-1f67-4db6-ae57-6c15d8d69357

@jiasli jiasli added the RBAC az role label Nov 16, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Nov 16, 2021
@jiasli jiasli added this to the Backlog milestone Nov 16, 2021
@ShachafGoldstein
Copy link

Facing this issue as well.

az role assignment create has the option for --assignee-object-id, why not have that option for delete?

@lucashby
Copy link

lucashby commented Jan 25, 2024

Facing this issue as well.

az role assignment create has the option for --assignee-object-id, why not have that option for delete?

This is exactly what should happen even according to the error message when attempting to use --assignee. The error message is telling me to use something that doesn't exist.

When I attempt with --assignee I get:

az : WARNING: Failed to query xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx by invoking Graph API. If you don't have permission to query Graph API, please specify
--assignee-object-id and --assignee-principal-type.

When I switch to the 2 arguments it just told me to use, I get:

az : ERROR: unrecognized arguments: --assignee-object-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --assignee-principal-type User

Now we are in an endless loop of error.

Please fix and add support to the delete operation for --assignee-object-id and --assignee-principal-type same as the "create" operation has.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants