Skip to content

Commit 943b05e

Browse files
authored
Support multi-tenant authentication in Key Vault (Azure#24558)
* Support multi-tenant authentication in Key Vault Resolves Azure#18359 * Resolve PR feedback * Update to Azure.Identity 1.5.0
1 parent bbfa2b4 commit 943b05e

File tree

12 files changed

+295
-25
lines changed

12 files changed

+295
-25
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<PackageReference Update="Azure.Messaging.EventGrid" Version="4.7.0" />
8686
<PackageReference Update="Azure.Messaging.ServiceBus" Version="7.4.0" />
8787
<PackageReference Update="Azure.Messaging.WebPubSub" Version="1.0.0-beta.2" />
88-
<PackageReference Update="Azure.Identity" Version="1.4.0" />
88+
<PackageReference Update="Azure.Identity" Version="1.5.0" />
8989
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
9090
<PackageReference Update="Azure.Security.KeyVault.Keys" Version="4.2.0" />
9191
<PackageReference Update="Azure.Security.KeyVault.Certificates" Version="4.2.0" />

sdk/keyvault/Azure.Security.KeyVault.Administration/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Support multi-tenant authentication against Managed HSM when using Azure.Identity 1.5.0 or newer. ([#18359](https://github.com/Azure/azure-sdk-for-net/issues/18359))
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/keyvault/Azure.Security.KeyVault.Certificates/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features Added
66

77
- Added `KeyVaultCertificateIdentifier.TryCreate` to parse certificate URIs without throwing an exception when invalid. ([#23146](https://github.com/Azure/azure-sdk-for-net/issues/23146))
8+
- Support multi-tenant authentication against Key Vault and Managed HSM when using Azure.Identity 1.5.0 or newer. ([#18359](https://github.com/Azure/azure-sdk-for-net/issues/18359))
89

910
### Breaking Changes
1011

sdk/keyvault/Azure.Security.KeyVault.Keys/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Added `KeyClient.GetCryptographyClient` to get a `CryptographyClient` that uses the same options, policies, and pipeline as the `KeyClient` that created it. ([#23786](https://github.com/Azure/azure-sdk-for-net/issues/23786))
99
- Added `KeyRotationPolicy` class and new methods including `KeyClient.GetKeyRotationPolicy`, `KeyClient.RotateKey`, and `KeyClient.UpdateKeyRotationPolicy`.
1010
- Added `KeyVaultKeyIdentifier.TryCreate` to parse key URIs without throwing an exception when invalid. ([#23146](https://github.com/Azure/azure-sdk-for-net/issues/23146))
11+
- Support multi-tenant authentication against Key Vault and Managed HSM when using Azure.Identity 1.5.0 or newer. ([#18359](https://github.com/Azure/azure-sdk-for-net/issues/18359))
1112

1213
### Breaking Changes
1314

sdk/keyvault/Azure.Security.KeyVault.Secrets/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features Added
66

77
- Added `KeyVaultSecretIdentifier.TryCreate` to parse secret URIs without throwing an exception when invalid. ([#23146](https://github.com/Azure/azure-sdk-for-net/issues/23146))
8+
- Support multi-tenant authentication against Key Vault and Managed HSM when using Azure.Identity 1.5.0 or newer. ([#18359](https://github.com/Azure/azure-sdk-for-net/issues/18359))
89

910
### Breaking Changes
1011

sdk/keyvault/Azure.Security.KeyVault.Secrets/src/Azure.Security.KeyVault.Secrets.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReference Include="System.Text.Json" />
2626
<PackageReference Include="System.Threading.Tasks.Extensions" />
2727
</ItemGroup>
28-
28+
2929
<ItemGroup>
3030
<Compile Include="$(AzureCoreSharedSources)AppContextSwitchHelper.cs" LinkBase="Shared" />
3131
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="Shared" />

sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/Azure.Security.KeyVault.Secrets.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
<ProjectReference Include="$(AzureCoreTestFramework)" />
1919
<ProjectReference Include="..\src\Azure.Security.KeyVault.Secrets.csproj" />
2020
</ItemGroup>
21+
2122
</Project>

sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretClientLiveTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Text;
78
using System.Threading.Tasks;
89
using NUnit.Framework;
10+
using Azure.Core;
911
using Azure.Core.TestFramework;
10-
using System.Text;
1112
using NUnit.Framework.Constraints;
1213

1314
namespace Azure.Security.KeyVault.Secrets.Tests
@@ -460,5 +461,19 @@ public async Task GetDeletedSecrets()
460461
AssertSecretPropertiesEqual(deletedSecret.Properties, returnedSecret.Properties, compareId: false);
461462
}
462463
}
464+
465+
[Test]
466+
public async Task AuthenticateCrossTenant()
467+
{
468+
TokenCredential credential = GetCredential(Recording.Random.NewGuid().ToString());
469+
SecretClient client = GetClient(credential);
470+
471+
string secretName = Recording.GenerateId();
472+
473+
Response<KeyVaultSecret> response = await client.SetSecretAsync(secretName, "secret");
474+
RegisterForCleanup(secretName);
475+
476+
Assert.AreEqual(200, response.GetRawResponse().Status);
477+
}
463478
}
464479
}

sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretsTestBase.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using System.Collections.Concurrent;
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
8+
using Azure.Core;
89
using Azure.Core.TestFramework;
10+
using Azure.Identity;
911
using Azure.Security.KeyVault.Tests;
1012
using NUnit.Framework;
1113

@@ -41,12 +43,12 @@ protected SecretsTestBase(bool isAsync, SecretClientOptions.ServiceVersion servi
4143
_serviceVersion = serviceVersion;
4244
}
4345

44-
internal SecretClient GetClient()
46+
internal SecretClient GetClient(TokenCredential credential = default)
4547
{
4648
return InstrumentClient
4749
(new SecretClient(
4850
new Uri(TestEnvironment.KeyVaultUrl),
49-
TestEnvironment.Credential,
51+
credential ?? TestEnvironment.Credential,
5052
InstrumentClientOptions(
5153
new SecretClientOptions(_serviceVersion)
5254
{
@@ -256,5 +258,23 @@ protected Task WaitForSecret(string name)
256258
return TestRetryHelper.RetryAsync(async () => await Client.GetSecretAsync(name).ConfigureAwait(false), delay: PollingInterval);
257259
}
258260
}
261+
262+
protected TokenCredential GetCredential(string tenantId)
263+
{
264+
if (Mode == RecordedTestMode.Playback)
265+
{
266+
return new MockCredential();
267+
}
268+
269+
return new ClientSecretCredential(
270+
tenantId ?? TestEnvironment.TenantId,
271+
TestEnvironment.ClientId,
272+
TestEnvironment.ClientSecret,
273+
new ClientSecretCredentialOptions()
274+
{
275+
AuthorityHost = new Uri(TestEnvironment.AuthorityHostUrl),
276+
}
277+
);
278+
}
259279
}
260280
}

sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SessionRecords/SecretClientLiveTests/AuthenticateCrossTenant.json

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)