{Role} az ad sp create-for-rbac: Fix "One or more properties contains invalid values"
#17433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix IcM 232405459: Running az ad sp create-for-rbac results in failure
Symptom
az ad sp create-for-rbacfails with:Cause
For example:
CLI first checks the existence of the Service Principal by searching for Service Principal whose
servicePrincipalNamescontainshttp://sp-prod:azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Line 1414 in 50ccb24
Normally, the result will look like:
Under some unknown cases, in AAD's response of a Service Principal, the order is reversed:
So CLI uses the 1st item
1f440000-0000-0000-0000-000000000000asname:azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Line 1418 in 50ccb24
Then CLI uses
name(1f440000-0000-0000-0000-000000000000) asidentifierUrito create an Application:azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Lines 1437 to 1440 in 50ccb24
It first checks whether there is an Application whose
identifierUriscontains1f440000-0000-0000-0000-000000000000:azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Line 784 in 50ccb24
This will certainly fail as
1f440000-0000-0000-0000-000000000000is theappId, notidentifierUri:So CLI will use
1f440000-0000-0000-0000-000000000000as aidentifierUrito create a new Application:azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Lines 820 to 822 in 50ccb24
This is why
PUTis called, instead ofPATCH. This will certainly fail as1f440000-0000-0000-0000-000000000000is not a valididentifierUri(should start withhttp://).Change
As the query for searching Service Principal already uses
name(http://sp-prod):azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Line 1414 in 50ccb24
there is simply no need to re-set
nameto the first item:azure-cli/src/azure-cli/azure/cli/command_modules/role/custom.py
Line 1418 in 50ccb24
In other words,
namealready has correct value (http://sp-prod).Temporary mitigation
As the Service Principal's response is not always consistent, the user should delete the old Application with
az ad app deleteand runaz ad sp create-for-rbacfrom scratch (without existing Service Principal and Application.)