[Core] Support getting SSH certificate inside Cloud Shell#22162
Merged
Conversation
Collaborator
|
PoC of support SSH Cert |
rayluo
commented
Apr 27, 2022
rayluo
commented
May 5, 2022
rayluo
commented
May 5, 2022
rayluo
commented
May 13, 2022
# Conflicts: # src/azure-cli-core/setup.py # src/azure-cli/requirements.py3.Linux.txt
Member
|
My test steps in Cloud Shell: python -m venv cli-env
. cli-env/bin/activate
git clone https://github.com/Azure/azure-cli
cd azure-cli
git checkout cloudshell-imds
pip install -U pip
pip install azdev
azdev setup -c
# Working, in sub ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78
az ssh vm -g rayluo-eastus2 -n LinuxVM
# Not working, in sub 0b1f6471-1bf0-4dda-aec3-cb9272f09590
az ssh vm -g jiasli-ssh-rg -n jiasli-ssh2
# output
A Cloud Shell credential problem occurred. When you report the issue with the error below, please mention the hostname 'cc-f29c4d42-7cd5855d5c-gpgrf'
token_type ssh-cert is not supported by this version of Azure Portal
Please explicitly log in with:
az login --scope https://pas.windows.net/CheckMyAccess/Linux/.default |
rayluo
commented
May 18, 2022
Comment on lines
+25
to
+34
| import msal | ||
| from .util import check_result, build_sdk_access_token | ||
| from .identity import AZURE_CLI_CLIENT_ID | ||
| app = msal.PublicClientApplication( | ||
| AZURE_CLI_CLIENT_ID, # Use a real client_id, so that cache would work | ||
| # TODO: This PoC does not currently maintain a token cache; | ||
| # Ideally we should reuse the real MSAL app object which has cache configured. | ||
| # token_cache=..., | ||
| ) | ||
| result = app.acquire_token_interactive(list(scopes), prompt="none", data=kwargs["data"]) |
Contributor
Author
There was a problem hiding this comment.
If the real central MSAL instance is somehow available here, I think we can reuse it, so that its already configured token_cache behavior will automatically be used to store SSH certs, and then this section can probably be refactored into something like below.
However, you do NOT have to make this change in this PR. We can merge this PR as-is (perhaps after MSAL 1.18 ships?) and postpone this cache improvement to a later date.
Suggested change
| import msal | |
| from .util import check_result, build_sdk_access_token | |
| from .identity import AZURE_CLI_CLIENT_ID | |
| app = msal.PublicClientApplication( | |
| AZURE_CLI_CLIENT_ID, # Use a real client_id, so that cache would work | |
| # TODO: This PoC does not currently maintain a token cache; | |
| # Ideally we should reuse the real MSAL app object which has cache configured. | |
| # token_cache=..., | |
| ) | |
| result = app.acquire_token_interactive(list(scopes), prompt="none", data=kwargs["data"]) | |
| from .util import check_result, build_sdk_access_token | |
| app = somehow_get_the_central_app_that_already_initialized() # TODO | |
| result = app.acquire_token_silent_with_error(list(scopes), data=kwargs["data"]) | |
| if result is None or "error" in result: | |
| result = app.acquire_token_interactive(list(scopes), prompt="none", data=kwargs["data"]) |
rayluo
commented
May 18, 2022
Member
|
Tested MSAL released to https://test.pypi.org/project/msal/ and it works well! |
rayluo
commented
May 19, 2022
rayluo
commented
May 19, 2022
Contributor
Author
rayluo
left a comment
There was a problem hiding this comment.
Great team work! Ship it! #Approve
jiasli
approved these changes
May 19, 2022
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.
Close #22063
This is a proof-of-concept to acquire SSH Cert from inside Cloud Shell.
Prerequisite: An MSAL prototype from this PR AzureAD/microsoft-authentication-library-for-python#420
@jiasli