Skip to content

Commit bd45fdb

Browse files
Copilotisra-fel
authored andcommitted
Replace hardcoded cloud-to-scope mappings with static SSH auth scope and deprecate SshAuthScope parameter (#29228)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: isra-fel <11371776+isra-fel@users.noreply.github.com>
1 parent bc4c759 commit bd45fdb

File tree

6 files changed

+11
-17
lines changed

6 files changed

+11
-17
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Improved SSH certificate authentication for Az SSH cmdlets across all Azure clouds.
23+
- SSH certificate authentication now works across all Azure clouds without configuring the `-SshAuthScope` parameter.
24+
- The `-SshAuthScope` parameter in `Set-AzEnvironment` and `Add-AzEnvironment` does not take any effect.
2225
* Updated MSAL to 4.83.1 for bug fixes in IMDS endpoint cache.
2326

2427
## Version 5.3.3

src/Accounts/Accounts/Environment/AddAzureRMEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public string DataLakeAudience
226226
public string MicrosoftGraphUrl { get; set; }
227227

228228
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
229-
HelpMessage = "The scope for authentication when SSH to an Azure VM.")]
229+
HelpMessage = "This parameter is deprecated and will be removed in a future release. The SSH authentication scope is now determined automatically and does not need to be configured.")]
230230
public string SshAuthScope { get; set; }
231231

232232
protected override bool RequireDefaultContext()

src/Accounts/Accounts/Environment/SetAzureRMEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public string DataLakeAudience
197197
public string MicrosoftGraphUrl { get; set; }
198198

199199
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
200-
HelpMessage = "The scope for authentication when SSH to an Azure VM.")]
200+
HelpMessage = "This parameter is deprecated and will be removed in a future release. The SSH authentication scope is now determined automatically and does not need to be configured.")]
201201
public string SshAuthScope { get; set; }
202202

203203
protected override bool RequireDefaultContext()

src/Accounts/Accounts/help/Add-AzEnvironment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ Accept wildcard characters: False
679679
```
680680

681681
### -SshAuthScope
682-
The scope for authentication when SSH to an Azure VM.
682+
This parameter is deprecated and will be removed in a future release. The SSH authentication scope is now determined automatically and does not need to be configured.
683683

684684
```yaml
685685
Type: System.String

src/Accounts/Accounts/help/Set-AzEnvironment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ Accept wildcard characters: False
601601
```
602602

603603
### -SshAuthScope
604-
The scope for authentication when SSH to an Azure VM.
604+
This parameter is deprecated and will be removed in a future release. The SSH authentication scope is now determined automatically and does not need to be configured.
605605

606606
```yaml
607607
Type: System.String

src/Accounts/Authentication/Factories/SshCredentialFactory.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;
1717
using Microsoft.Azure.Commands.Common.Authentication.Properties;
18-
using Microsoft.Azure.Commands.Common.Exceptions;
1918
using Microsoft.Identity.Client.SSHCertificates;
2019
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2120

@@ -30,13 +29,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Factories
3029
{
3130
public class SshCredentialFactory : ISshCredentialFactory
3231
{
33-
// kept for backward-compatibility
34-
private readonly Dictionary<string, string> CloudToScope = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
35-
{
36-
{ EnvironmentName.AzureCloud, AzureEnvironmentConstants.AzureSshAuthScope },
37-
{ EnvironmentName.AzureChinaCloud, AzureEnvironmentConstants.ChinaSshAuthScope },
38-
{ EnvironmentName.AzureUSGovernment, AzureEnvironmentConstants.USGovernmentSshAuthScope },
39-
};
32+
private const string AadSshLoginForLinuxServerAppId = "ce6ff14a-7fdc-4685-bbe0-f6afdfcfa8e0";
4033

4134
private string CreateJwk(RSAParameters rsaKeyInfo, out string keyId)
4235
{
@@ -70,8 +63,7 @@ public SshCredential GetSshCredential(IAzureContext context, RSAParameters rsaKe
7063
}
7164

7265
var publicClient = tokenCacheProvider.CreatePublicClient(context.Environment.ActiveDirectoryAuthority, context.Tenant.Id);
73-
string scope = GetAuthScope(context.Environment)
74-
?? throw new AzPSKeyNotFoundException(string.Format(Resources.ErrorSshAuthScopeNotSet, context.Environment.Name));
66+
string scope = GetAuthScope();
7567
List<string> scopes = new List<string>() { scope };
7668
var jwk = CreateJwk(rsaKeyInfo, out string keyId);
7769

@@ -90,10 +82,9 @@ public SshCredential GetSshCredential(IAzureContext context, RSAParameters rsaKe
9082
return resultToken;
9183
}
9284

93-
private string GetAuthScope(IAzureEnvironment environment)
85+
private string GetAuthScope()
9486
{
95-
return environment.GetProperty(AzureEnvironment.ExtendedEndpoint.AzureSshAuthScope)
96-
?? CloudToScope.GetValueOrDefault(environment.Name.ToLower(), null);
87+
return $"{AadSshLoginForLinuxServerAppId}/.default";
9788
}
9889
}
9990
}

0 commit comments

Comments
 (0)