-
Notifications
You must be signed in to change notification settings - Fork 642
Add CertificateClient and KeyClient support to Aspire.Azure.Security.KeyVault #8408
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
Add CertificateClient and KeyClient support to Aspire.Azure.Security.KeyVault #8408
Conversation
…ifferent ConnectionStrings configuration keys
…verwriting ConnectionName
…named to SecretClientConformanceTests
… Vault so no connection can be made yet.
Conscious the build analysis is failing. There is a bypass which I won't use personally but the changes are backwards compatible with existing code, the previous tests are all green as well as the new ones. I'm unable to see the full failure list without being in the MS tenancy so I could do with some assistance fixing any issues if they are valid though 👍 |
Those pipelines should be visible to you. Also you made a breaking API change that’s why it’s complaining |
I can see the first couple of issues but it's truncated, when I log into
This is a personal MS account though.
Makes sense, thanks. Do I need to address anything in that case? |
@eerhardt Apologies for the nudge, is there anything outstanding from my end? Appreciate the builds are shouting a bit, nothing actually breaks from the old API but the return type has changed from |
Minimally, we won't break the API, we need a different proposal that is non breaking. |
@davidfowl Understood, however this doesn't break the previous behaviour. Updating from the current version to one with this change in would compile and work the same way, the signatures and configuration are the same. The previous return type was The registration of the public static AzureKeyVaultClientBuilder AddAzureKeyVaultClient(
this IHostApplicationBuilder builder,
string connectionName,
Action<AzureSecurityKeyVaultSettings>? configureSettings = null,
Action<IAzureClientBuilder<SecretClient, SecretClientOptions>>? configureClientBuilder = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);
return new AzureKeyVaultClientBuilder(builder, connectionName, configureSettings)
.AddSecretClient(configureClientBuilder);
} Underneath it still immediately calls // tests/Components/Aspire.Azure.Security.KeyVault.Tests/AspireKeyVaultExtensionsTests.cs
public void VaultUriCanBeSetInCode(bool useKeyed)
{
var vaultUri = new Uri(ConformanceConstants.VaultUri);
var builder = Host.CreateEmptyApplicationBuilder(null);
builder.Configuration.AddInMemoryCollection([
new KeyValuePair<string, string?>("ConnectionStrings:secrets", "https://unused.vault.azure.net/")
]);
if (useKeyed)
{
builder.AddKeyedAzureKeyVaultClient("secrets", settings => settings.VaultUri = vaultUri);
}
else
{
builder.AddAzureKeyVaultClient("secrets", settings => settings.VaultUri = vaultUri);
}
using var host = builder.Build();
var client = useKeyed ?
host.Services.GetRequiredKeyedService<SecretClient>("secrets") :
host.Services.GetRequiredService<SecretClient>();
Assert.Equal(vaultUri, client.VaultUri);
} The Would you still consider this breaking with this context? Maybe I'm misunderstanding what you mean by a breaking change but I've made absolute sure that the existing implementation isn't impacted at all. |
@james-gould - check out https://learn.microsoft.com/dotnet/core/compatibility for how we thinking breaking changes/compatibility. The change you are proposing is what we call a "Binary breaking change". If a library is already built calling |
…onal Extended extension method instead
@sebastienros are you okay with leaving |
@james-gould if the change is breaking then sure it's fine to disable the warning locally with a comment. I "personally" don't feel like this code suggestion is useful. |
src/Components/Aspire.Azure.Security.KeyVault/AzureKeyVaultClientBuilderSecretExtensions.cs
Outdated
Show resolved
Hide resolved
It did have an issue with the configuration source, I've added the comment from @eerhardt to the 3 components. |
/// <param name="configureClientBuilder">An optional method that can be used for customizing the <see cref="IAzureClientBuilder{TClient, TOptions}"/>.</param> | ||
/// <remarks>Reads the configuration from "Aspire:Azure:Security:KeyVault:{name}" section.</remarks> | ||
/// <exception cref="InvalidOperationException">Thrown when mandatory <see cref="AzureSecurityKeyVaultSettings.VaultUri"/> is not provided.</exception> | ||
public static void AddKeyedAzureKeyVaultKeyClient( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol - lots of "key"s in this method name.
src/Components/Aspire.Azure.Security.KeyVault/Aspire.Azure.Security.KeyVault.csproj
Outdated
Show resolved
Hide resolved
src/Components/Aspire.Azure.Security.KeyVault/AbstractAzureKeyVaultComponent.cs
Outdated
Show resolved
Hide resolved
internal sealed class AzureKeyVaultKeysComponent : AbstractAzureKeyVaultComponent<KeyClient, KeyClientOptions> | ||
{ | ||
protected override IHealthCheck CreateHealthCheck(KeyClient client, AzureSecurityKeyVaultSettings settings) | ||
=> throw new NotImplementedException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to throw if settings.DisableHealthChecks == false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@james-gould I think you need to add this is the two components that don't provide the health-check
protected override bool GetHealthCheckEnabled(AzureSecurityKeyVaultSettings settings)
{
return false;
}
I will add it myself and approve the PR, unless you think it's wrong and we can then change it.
src/Components/Aspire.Azure.Security.KeyVault/AzureKeyVaultCertificatesComponent.cs
Show resolved
Hide resolved
…VaultComponent.cs Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
…urity.KeyVault.csproj Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
…uld/aspire into AdditionalClientSupport
Description
Adds the new
builder.AddExtendedAzureKeyVaultClient
method to provideKeyClient
andCertificateClient
support. While these are significantly less used thanSecrets
they still are useful and often required. Users are having to mix theAspire
andAzure.Security
libraries together to achieve the functionality currently.I've extended several large internal applications at work to make use of
.NET Aspire
and these two clients missing from the new package was a bit frustrating.An example of what these extensions provide:
With included support for
Keyed
clients too:The implementation was loosely based off the existing
Aspire.OpenAI
package which also makes use of abuilder
pattern. I've also made sure to migrate thenamespaces
of the extension method classes toMicrosoft.Extensions.Hosting
as well to avoid needing to introduce moreusing
statements.I'm aware that secrets are the main use-case for KV which is why these two clients weren't implemented previously, I'm hoping this implementation is both useful to customers/users (myself included) but also conforms to the principle of secrets first.
Fixes issues:
#8099
#3930
Additional dependencies
Adds in the Certificates.CertificateClient and Keys.KeyClient packages from Azure.Security, alongside the existing Secrets.SecretClient dep.
Checklist