-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[Core] Support getting SSH certificate inside Cloud Shell #22162
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
Changes from all commits
34e27b7
07294da
6810cdb
9bcef33
a92447e
fdeb53f
2d13106
4bfa303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,12 +16,29 @@ class MSIAuthenticationWrapper(MSIAuthentication): | |||||||||||||||||||||||||||||||
| # This method is exposed for Azure Core. Add *scopes, **kwargs to fit azure.core requirement | ||||||||||||||||||||||||||||||||
| # pylint: disable=line-too-long | ||||||||||||||||||||||||||||||||
| def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument | ||||||||||||||||||||||||||||||||
| logger.debug("MSIAuthenticationWrapper.get_token invoked by Track 2 SDK with scopes=%s", scopes) | ||||||||||||||||||||||||||||||||
| logger.debug("MSIAuthenticationWrapper.get_token: scopes=%r, kwargs=%r", scopes, kwargs) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if 'data' in kwargs: | ||||||||||||||||||||||||||||||||
| from azure.cli.core.util import in_cloud_console | ||||||||||||||||||||||||||||||||
| if in_cloud_console(): | ||||||||||||||||||||||||||||||||
rayluo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
| # Use MSAL to get VM SSH certificate | ||||||||||||||||||||||||||||||||
| 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"]) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+34
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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
|
||||||||||||||||||||||||||||||||
| check_result(result, scopes=scopes) | ||||||||||||||||||||||||||||||||
| return build_sdk_access_token(result) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| from azure.cli.core.azclierror import AuthenticationError | ||||||||||||||||||||||||||||||||
| raise AuthenticationError("VM SSH currently doesn't support managed identity or Cloud Shell.") | ||||||||||||||||||||||||||||||||
| raise AuthenticationError("VM SSH currently doesn't support managed identity.") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Use msrestazure to get access token | ||||||||||||||||||||||||||||||||
| resource = scopes_to_resource(_normalize_scopes(scopes)) | ||||||||||||||||||||||||||||||||
| if resource: | ||||||||||||||||||||||||||||||||
| # If available, use resource provided by SDK | ||||||||||||||||||||||||||||||||
|
|
@@ -55,7 +72,7 @@ def set_token(self): | |||||||||||||||||||||||||||||||
| import traceback | ||||||||||||||||||||||||||||||||
| from azure.cli.core.azclierror import AzureConnectionError, AzureResponseError | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| super(MSIAuthenticationWrapper, self).set_token() | ||||||||||||||||||||||||||||||||
| super().set_token() | ||||||||||||||||||||||||||||||||
| except requests.exceptions.ConnectionError as err: | ||||||||||||||||||||||||||||||||
| logger.debug('throw requests.exceptions.ConnectionError when doing MSIAuthentication: \n%s', | ||||||||||||||||||||||||||||||||
| traceback.format_exc()) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.