-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[Core] Support getting SSH certificate inside Cloud Shell #22162
Conversation
PoC of support SSH Cert |
# Conflicts: # src/azure-cli-core/setup.py # src/azure-cli/requirements.py3.Linux.txt
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 |
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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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"]) |
Tested MSAL released to https://test.pypi.org/project/msal/ and it works well!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great team work! Ship it! #Approve
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