Skip to content

[Ssh] az ssh: Allow SSH certificate flow in Cloud Shell - #33860

Merged
xuming-ms merged 1 commit into
Azure:devfrom
xuming-ms:allow-vm-ssh-in-cloudshell
Aug 7, 2026
Merged

[Ssh] az ssh: Allow SSH certificate flow in Cloud Shell#33860
xuming-ms merged 1 commit into
Azure:devfrom
xuming-ms:allow-vm-ssh-in-cloudshell

Conversation

@xuming-ms

@xuming-ms xuming-ms commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests
️✔️ None ️✔️ 130/130

Related command
az ssh vm -n <vm-name> -g <resource-group>

Description
#33534 restored a guard in get_msal_token() that rejects both managed identity and Cloud Shell. The managed identity half is correct, but the Cloud Shell half is an over-block that breaks az ssh vm for users signed in with their own account in Cloud Shell.

Testing Guide

# In Cloud Shell, signed in as your own account (the default):
az ssh vm -n myVM -g myRG
# Expected: SSH connection succeeds

# Managed identity remains blocked:
az login --identity
az ssh vm -n myVM -g myRG
# Expected: AuthenticationError: VM SSH currently doesn't support managed identity.

Unit tests: test_get_msal_token_cloud_shell now asserts the call succeeds and that scopes and data reach the credential unchanged. CloudShellCredentialStub was discarding **kwargs, so it could not have caught a dropped data; it now records it.

History Notes
[Ssh] az ssh: Allow SSH certificate flow in Cloud Shell

@xuming-ms
xuming-ms requested review from a team as code owners August 6, 2026 22:00
Copilot AI lite review requested due to automatic review settings August 6, 2026 22:00
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Cloud Shell speaks the managed identity protocol but brokers a user token, and
MSAL forwards the `data` parameter through acquire_token_interactive to its
Cloud Shell endpoint, which accepts the CheckMyAccess/Linux scope and issues an
SSH certificate. Blocking it stops `az ssh vm` from working for users signed in
with their own account in Cloud Shell.

Keep the guard for managed identity, where acquire_token_for_client() takes no
`data` and would silently return a plain access token instead of a certificate.
@xuming-ms
xuming-ms force-pushed the allow-vm-ssh-in-cloudshell branch from a0e1000 to 8d63a67 Compare August 6, 2026 22:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Enables az ssh vm SSH-certificate flow to work in Cloud Shell by removing an overly broad Cloud Shell block while keeping managed identity blocked (since it drops SSH-cert data).

Changes:

  • Relaxed Profile.get_msal_token() guard to only reject managed identity (not Cloud Shell).
  • Updated unit tests to validate Cloud Shell passes through scopes and data unchanged to the credential.
  • Improved the managed-identity error message and adjusted test coverage accordingly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/azure-cli-core/azure/cli/core/_profile.py Removes Cloud Shell from the SSH-cert unsupported guard; keeps managed identity blocked.
src/azure-cli-core/azure/cli/core/tests/test_profile.py Reworks Cloud Shell test to assert data propagation and updates MI error message expectation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/azure-cli-core/azure/cli/core/tests/test_profile.py
if managed_identity_type or (in_cloud_console() and account[_USER_ENTITY].get(_CLOUD_SHELL_ID)):
raise AuthenticationError("VM SSH currently doesn't support managed identity or Cloud Shell.")
if managed_identity_type:
# MSAL's ManagedIdentityClient.acquire_token_for_client() takes no `data`, so the
@isra-fel

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@xuming-ms

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@xuming-ms
xuming-ms merged commit 171de4a into Azure:dev Aug 7, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants