Skip to content

Commit ace12d6

Browse files
authored
Merge branch 'main' into network-2022-07-01
2 parents 480dc7f + 5d95e49 commit ace12d6

File tree

30 files changed

+305
-84
lines changed

30 files changed

+305
-84
lines changed

src/Accounts/Accounts/ChangeLog.md

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

2121
## Upcoming Release
22+
* Enabled caching tokens when logging in with a service principal. This could reduce network traffic and improve performance.
23+
* Upgraded target framework of Microsoft.Identity.Client to net461 [#20189]
2224

2325
## Version 2.10.3
2426
* Updated `Get-AzSubscription` to retrieve subscription by Id rather than listed all the subscriptions from server if subscription Id is provided. [#19115]

src/Resources/Resources/UX/Microsoft.Resources/subscriptions.json renamed to src/Accounts/Accounts/UX/Microsoft.Accounts/subscriptions.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"name":"Get-AzSubscription",
1010
"description":"Get subscriptions that the current account can access.",
11-
"path":"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/subscriptions",
11+
"path":"/subscriptions/{subscriptionId}",
1212
"confirmation":false,
1313
"help":{
1414
"learnMore":{
@@ -17,8 +17,7 @@
1717
"parameterSets":[
1818
{
1919
"parameters":[
20-
"[[-ResourceGroupName] <System.String>]",
21-
"[[-TenantId] <String>]"
20+
"[[-SubscriptionId] <String>]"
2221
]
2322
}
2423
]
@@ -28,16 +27,12 @@
2827
"description":"Get subscriptions that the current account can access.",
2928
"parameters":[
3029
{
31-
"name":"-ResourceGroupName",
32-
"value":"[path.resourceGroupName]"
33-
},
34-
{
35-
"name":"-TenantId",
36-
"value":"[path.TenantId]"
30+
"name":"-SubscriptionId",
31+
"value":"[path.subscriptionId]"
3732
}
3833
]
3934
}
4035
]
4136
}
4237
]
43-
}
38+
}

src/Accounts/Authentication.Test/AuthenticatorsTest/ServicePrincipalAuthenticatorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task ServicePrincipalSecretAuthenticationTest()
7171
//Setup
7272
var mockAzureCredentialFactory = new Mock<AzureCredentialFactory>();
7373
mockAzureCredentialFactory.Setup(f => f.CreateClientSecretCredential(
74-
It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SecureString>(), It.IsAny<ClientCertificateCredentialOptions>())).Returns(() => new TokenCredentialMock());
74+
It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SecureString>(), It.IsAny<ClientSecretCredentialOptions>())).Returns(() => new TokenCredentialMock());
7575

7676
AzureSession.Instance.RegisterComponent(nameof(AzureCredentialFactory), () => mockAzureCredentialFactory.Object, true);
7777
InMemoryTokenCacheProvider cacheProvider = new InMemoryTokenCacheProvider();
@@ -101,7 +101,7 @@ public async Task ServicePrincipalSecretAuthenticationTest()
101101
var token = await authenticator.Authenticate(parameter);
102102

103103
//Verify
104-
mockAzureCredentialFactory.Verify(f => f.CreateClientSecretCredential(TestTenantId, accountId, securePassword, It.IsAny<ClientCertificateCredentialOptions>()), Times.Once());
104+
mockAzureCredentialFactory.Verify(f => f.CreateClientSecretCredential(TestTenantId, accountId, securePassword, It.IsAny<ClientSecretCredentialOptions>()), Times.Once());
105105
Assert.Equal(fakeToken, token.AccessToken);
106106
Assert.Equal(TestTenantId, token.TenantId);
107107
}

src/Accounts/Authenticators/Factories/AzureCredentialFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public virtual TokenCredential CreateManagedIdentityCredential(string clientId)
2727
return new ManagedIdentityCredential(clientId);
2828
}
2929

30-
public virtual TokenCredential CreateClientSecretCredential(string tenantId, string clientId, SecureString secret, ClientCertificateCredentialOptions options)
30+
public virtual TokenCredential CreateClientSecretCredential(string tenantId, string clientId, SecureString secret, ClientSecretCredentialOptions options)
3131
{
3232
return new ClientSecretCredential(tenantId, clientId, secret.ConvertToString(), options);
3333
}

src/Accounts/Authenticators/ServicePrincipalAuthenticator.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ServicePrincipalAuthenticator : DelegatingAuthenticator
3030
{
3131
private const string AuthenticationFailedMessage = "No certificate thumbprint or secret provided for the given service principal '{0}'.";
3232

33-
//MSAL doesn't cache Service Principal into msal.cache
33+
// MSAL doesn't cache the secret of Service Principal, but it caches access tokens
3434
public override Task<IAccessToken> Authenticate(AuthenticationParameters parameters, CancellationToken cancellationToken)
3535
{
3636
var spParameters = parameters as ServicePrincipalParameters;
@@ -43,10 +43,12 @@ public override Task<IAccessToken> Authenticate(AuthenticationParameters paramet
4343
var authority = spParameters.Environment.ActiveDirectoryAuthority;
4444

4545
var requestContext = new TokenRequestContext(scopes);
46+
var tokenCachePersistenceOptions = spParameters.TokenCacheProvider.GetTokenCachePersistenceOptions();
4647
AzureSession.Instance.TryGetComponent(nameof(AzureCredentialFactory), out AzureCredentialFactory azureCredentialFactory);
4748

4849
var options = new ClientCertificateCredentialOptions()
4950
{
51+
TokenCachePersistenceOptions = tokenCachePersistenceOptions, // allows MSAL to cache access tokens
5052
AuthorityHost = new Uri(authority),
5153
SendCertificateChain = spParameters.SendCertificateChain ?? default(bool)
5254
};
@@ -63,10 +65,15 @@ public override Task<IAccessToken> Authenticate(AuthenticationParameters paramet
6365
else if (spParameters.Secret != null)
6466
{
6567
//Service principal with secret
66-
tokenCredential = azureCredentialFactory.CreateClientSecretCredential(tenantId, spParameters.ApplicationId, spParameters.Secret, options);
67-
parametersLog = $"- ApplicationId:'{spParameters.ApplicationId}', TenantId:'{tenantId}', Scopes:'{string.Join(",", scopes)}', AuthorityHost:'{options.AuthorityHost}'";
68+
var csOptions = new ClientSecretCredentialOptions()
69+
{
70+
TokenCachePersistenceOptions = tokenCachePersistenceOptions, // allows MSAL to cache access tokens
71+
AuthorityHost = new Uri(authority)
72+
};
73+
tokenCredential = azureCredentialFactory.CreateClientSecretCredential(tenantId, spParameters.ApplicationId, spParameters.Secret, csOptions);
74+
parametersLog = $"- ApplicationId:'{spParameters.ApplicationId}', TenantId:'{tenantId}', Scopes:'{string.Join(",", scopes)}', AuthorityHost:'{csOptions.AuthorityHost}'";
6875
}
69-
else if(!string.IsNullOrEmpty(spParameters.CertificatePath))
76+
else if (!string.IsNullOrEmpty(spParameters.CertificatePath))
7077
{
7178
if (spParameters.CertificateSecret != null)
7279
{
@@ -86,6 +93,7 @@ public override Task<IAccessToken> Authenticate(AuthenticationParameters paramet
8693
{
8794
throw new MsalException(MsalError.AuthenticationFailed, string.Format(AuthenticationFailedMessage, clientId));
8895
}
96+
8997
return MsalAccessToken.GetAccessTokenAsync(
9098
nameof(ServicePrincipalAuthenticator),
9199
parametersLog,

src/Aks/Aks.Sdk/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ directive:
3535
transform: $.name = "ResourceIdentityTypeForCommonTypes"
3636
- from: swagger-document
3737
where: $.definitions.ManagedClusterAgentPoolProfileProperties.properties.orchestratorVersion
38-
transform: $["description"] = $["description"].replaceAll("<", "(");
38+
transform: $["description"] = $["description"].replace(/</g, "(");
3939
- from: swagger-document
4040
where: $.definitions.ManagedClusterAgentPoolProfileProperties.properties.orchestratorVersion
41-
transform: $["description"] = $["description"].replaceAll(">", ")");
41+
transform: $["description"] = $["description"].replace(/>/g, ")");
4242
- from: swagger-document
4343
where: $.definitions.ManagedClusterAgentPoolProfileProperties.properties.currentOrchestratorVersion
44-
transform: $["description"] = $["description"].replaceAll("<", "(");
44+
transform: $["description"] = $["description"].replace(/</g, "(");
4545
- from: swagger-document
4646
where: $.definitions.ManagedClusterAgentPoolProfileProperties.properties.currentOrchestratorVersion
47-
transform: $["description"] = $["description"].replaceAll(">", ")");
47+
transform: $["description"] = $["description"].replace(/>/g, ")");
4848
- from: swagger-document
4949
where: $.definitions.ManagedClusterProperties.properties.kubernetesVersion
50-
transform: $["description"] = $["description"].replaceAll("<", "(");
50+
transform: $["description"] = $["description"].replace(/</g, "(");
5151
- from: swagger-document
5252
where: $.definitions.ManagedClusterProperties.properties.kubernetesVersion
53-
transform: $["description"] = $["description"].replaceAll(">", ")");
53+
transform: $["description"] = $["description"].replace(/>/g, ")");
5454
- from: swagger-document
5555
where: $.definitions.ManagedClusterProperties.properties.currentKubernetesVersion
56-
transform: $["description"] = $["description"].replaceAll("<", "(");
56+
transform: $["description"] = $["description"].replace(/</g, "(");
5757
- from: swagger-document
5858
where: $.definitions.ManagedClusterProperties.properties.currentKubernetesVersion
59-
transform: $["description"] = $["description"].replaceAll(">", ")");
59+
transform: $["description"] = $["description"].replace(/>/g, ")");
6060

6161
output-folder: Generated
6262
namespace: Microsoft.Azure.Management.ContainerService

src/ApiManagement/ApiManagement/ChangeLog.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21-
* Upgraded AutoMapper to Microsoft.Azure.PowerShell.AutoMapper 6.2.2 with fix [#18721]
2221

2322
## Version 4.0.1
2423
* Upgraded AutoMapper to Microsoft.Azure.PowerShell.AutoMapper 6.2.2 with fix [#18721]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### Example 1: Get a Run Command for VM
2+
3+
```powershell
4+
Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM -RunCommandName MyRunCommand
5+
```
6+
7+
Get a Run Command for VM without Instance View.
8+
9+
### Example 2: Get a Run Command for VM with Instance View
10+
11+
```powershell
12+
$x = Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM -RunCommandName MyRunCommand -Expand InstanceView
13+
$x.InstanceView
14+
```
15+
16+
```output
17+
ExecutionState : Succeeded
18+
ExecutionMessage :
19+
ExitCode : 0
20+
Output : Directory: C:\
21+
22+
23+
Mode LastWriteTime Length Name
24+
---- ------------- ------ ----
25+
-a---- 10/27/2022 9:10 PM 0 HelloWorld2022-10-27T21.10.54.9266231+00.00.txt
26+
27+
28+
Error :
29+
StartTime : 10/27/2022 9:10:52 PM
30+
EndTime : 10/27/2022 9:10:55 PM
31+
Statuses :
32+
```
33+
34+
Get a Run Command for VM with Instance View. Instance View contains execution state of run command (Succeeded, Failed, etc.), exit code, standard output and standard error generated by executing the script using Run Command. A non-zero ExitCode indicates an unsuccessful execution.
35+
36+
### Example 3: Get all Run Commands for a VM
37+
38+
```powershell
39+
Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM
40+
```
41+
42+
Get list of all Run Commands for a VM.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### Example 1: Get a Run Command for VMSS VM instance
2+
3+
```powershell
4+
Get-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 0 -RunCommandName MyRunCommand
5+
```
6+
7+
Get a Run Command for VM without Instance View.
8+
9+
### Example 2: Get a Run Command for VMSS VM instance with Instance View
10+
11+
```powershell
12+
$x = Get-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 0 -RunCommandName MyRunCommand -Expand InstanceView
13+
$x.InstanceView
14+
```
15+
16+
```output
17+
ExecutionState : Succeeded
18+
ExecutionMessage :
19+
ExitCode : 0
20+
Output : Directory: C:\
21+
22+
23+
Mode LastWriteTime Length Name
24+
---- ------------- ------ ----
25+
-a---- 10/27/2022 9:10 PM 0 HelloWorld2022-10-27T21.10.54.9266231+00.00.txt
26+
27+
28+
Error :
29+
StartTime : 10/27/2022 9:10:52 PM
30+
EndTime : 10/27/2022 9:10:55 PM
31+
Statuses :
32+
```
33+
34+
Get a Run Command for VM with Instance View. Instance View contains execution state of run command (Succeeded, Failed, etc.), exit code, standard output and standard error generated by executing the script using Run Command. A non-zero ExitCode indicates an unsuccessful execution.
35+
36+
### Example 3: Get all Run Commands for a VMSS VM instance
37+
38+
```powershell
39+
Get-AzVmssVMRunCommand -ResourceGroupName MyRG -VMScaleSetName MyVMSS -InstanceId 1
40+
```
41+
42+
Get list of all Run Commands for a VM.

0 commit comments

Comments
 (0)