{Keyvault} Fix #22540: Create keyvault with service principal#22543
Merged
{Keyvault} Fix #22540: Create keyvault with service principal#22543
Conversation
evelyn-ys
approved these changes
May 20, 2022
calvinhzy
approved these changes
May 20, 2022
jiasli
commented
May 20, 2022
Comment on lines
-311
to
-313
| current_user = graph_client.signed_in_user_get() | ||
| if current_user and current_user.get('id', None): # pylint:disable=no-member | ||
| return current_user['id'] # pylint:disable=no-member |
Member
Author
There was a problem hiding this comment.
I did leave a comment for this weird behavior of checking the existence of id (#22203 (comment)).
graph_client.signed_in_user_get will ALWAYS return a user object which MUST have id property UNLESS GraphError is raised.
Takeaways:
- Pylint error is a sign of abnormality and should NOT be disabled brutally.
- For anything unusual like
current_user.get('id', None)orexcept CloudError, comments MUST be left to explain its behavior. Otherwise, it should not be there.
jiasli
commented
May 20, 2022
Comment on lines
-314
to
-315
| except GraphError: | ||
| pass |
Member
Author
There was a problem hiding this comment.
We got tripped by some code written almost 6 years ago! (cb0faa8)
Collaborator
|
Good catch ! |
Member
Author
|
I have confirmed the new RPM has the correct code: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related command
az keyvault createDescription
#22203 changed
msrestazure.azure_exceptions.CloudErrortoazure.cli.command_modules.role.GraphErrorinazure.cli.command_modules.keyvault.custom._get_current_user_object_id.Some background:
azure-graphrbacPython SDK raises inconsistent exceptions for Graph errors:DomainsOperations.getraisesCloudError:https://github.com/Azure/azure-sdk-for-python/blob/dfa109c36598d93aaf74238feded516352c20f4c/sdk/graphrbac/azure-graphrbac/azure/graphrbac/operations/domains_operations.py#L150-L153
SignedInUserOperations.getraisesGraphErrorException:https://github.com/Azure/azure-sdk-for-python/blob/dfa109c36598d93aaf74238feded516352c20f4c/sdk/graphrbac/azure-graphrbac/azure/graphrbac/operations/signed_in_user_operations.py#L79-L80
Since
SignedInUserOperations.getdoesn't raiseCloudError, thisexcept CloudErrorwill never be hit:azure-cli/src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Lines 312 to 317 in 1451bd5
Therefore, this
except CloudErrorclause has no effect and should NOT be replaced byGraphError. Doing so will makeGraphErrorbe intercepted and the outerexcept GraphErrorhave no effect:azure-cli/src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Lines 747 to 750 in cac3f06
This PR lets
_get_current_user_object_idraiseGraphErrorso that it can be caught by outerexcept GraphError.Testing Guide
az ad sp create-for-rbac --role Owner --scopes /subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590 --verbose # Copy the login command from log and run: az login --service-principal --username 558c5061-b77b-4dfa-8118-168068c9be4a --password xxx --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a az group create -n my-kv-testrg -l eastasia az keyvault create -n my-kv-test -g my-kv-testrg