Skip to content

Instantly share code, notes, and snippets.

@charbonnierg
Created September 3, 2023 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charbonnierg/5bb91ba9b3b9716fa0dac88bb1e8b82b to your computer and use it in GitHub Desktop.
Save charbonnierg/5bb91ba9b3b9716fa0dac88bb1e8b82b to your computer and use it in GitHub Desktop.
Remove Azure RBAC with unknown user
#!/usr/bin/env bash
set -euo pipefail
ROLES=$(az role assignment list --query '[].{id:id, principalName:principalName}' --all)
IDS=$(echo $ROLES | jq -r '.[] | select(.principalName == "") | .id')
for ID in $IDS; do
echo "Removing role with unknown user: $ID"
az role assignment delete --ids "$ID" &
done
wait $(jobs -p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment