-
Notifications
You must be signed in to change notification settings - Fork 845
[New Azure Integration Pkgs] Port configuration provider to use the new Azure.Security.KeyVault.Secrets #2618
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
Changes from 21 commits
150b922
98347c5
39a2d5a
48f8655
7bf5fd2
5145b03
0aa5ed2
6e4a9ae
8c3842c
730d390
25f7eb4
e33ae31
d38de46
07db2b0
1849f82
d13a8dd
0758415
fabaf14
bd2bb7b
b918b49
58b0123
e5c0e25
6613888
ae30d30
1dc7c51
d7f607e
43330a3
d38ba00
2159d1c
78c6e7e
a3543ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Workaround namespace conflicts with Azure.* and Microsoft.Extensions.Azure.* | ||
| M:Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions.AddAzureKeyVault(Microsoft.Extensions.Configuration.IConfigurationBuilder,Azure.Security.KeyVault.Secrets.SecretClient,Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager) | ||
| M:Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions.AddAzureKeyVault(Microsoft.Extensions.Configuration.IConfigurationBuilder,System.Uri,Azure.Core.TokenCredential) | ||
| M:Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions.AddAzureKeyVault(Microsoft.Extensions.Configuration.IConfigurationBuilder,System.Uri,Azure.Core.TokenCredential,Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager) | ||
| M:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.AzureKeyVaultConfigurationOptions.#ctor(System.Uri,Azure.Core.TokenCredential) | ||
| P:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.AzureKeyVaultConfigurationOptions.Client | ||
| M:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.AzureKeyVaultConfigurationOptions.set_Client(Azure.Security.KeyVault.Secrets.SecretClient) | ||
| T:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager | ||
| M:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager.GetKey(Azure.Security.KeyVault.Secrets.KeyVaultSecret) | ||
| M:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager.Load(Azure.Security.KeyVault.Secrets.SecretProperties) | ||
| M:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.DefaultKeyVaultSecretManager.GetKey(Azure.Security.KeyVault.Secrets.KeyVaultSecret) | ||
| M:Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.DefaultKeyVaultSecretManager.Load(Azure.Security.KeyVault.Secrets.SecretProperties) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project> | ||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- These projects depend on a 3rd party source. --> | ||
| <ExcludeFromSourceBuild>true</ExcludeFromSourceBuild> | ||
BrennanConroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <PreReleaseVersionLabel>$(AzureKeyVaultSecretsPreReleaseVersionLabel)</PreReleaseVersionLabel> | ||
| <DotNetFinalVersionKind /> | ||
| </PropertyGroup> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
|
||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.Extensions.Configuration | ||
| { | ||
| public static partial class AzureKeyVaultConfigurationExtensions | ||
BrennanConroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddAzureKeyVault(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, global::Azure.Security.KeyVault.Secrets.SecretClient client, Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager manager) { throw null; } | ||
| public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddAzureKeyVault(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, System.Uri vault, global::Azure.Core.TokenCredential credential) { throw null; } | ||
BrennanConroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddAzureKeyVault(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, System.Uri vault, global::Azure.Core.TokenCredential credential, Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager manager) { throw null; } | ||
| } | ||
| } | ||
| namespace Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets | ||
| { | ||
| public partial class AzureKeyVaultConfigurationOptions | ||
| { | ||
| public AzureKeyVaultConfigurationOptions(System.Uri vault, global::Azure.Core.TokenCredential credential) { } | ||
BrennanConroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public global::Azure.Security.KeyVault.Secrets.SecretClient Client { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } | ||
| } | ||
| public partial class DefaultKeyVaultSecretManager : Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager | ||
| { | ||
| public virtual string GetKey(global::Azure.Security.KeyVault.Secrets.KeyVaultSecret secret) { throw null; } | ||
| public virtual bool Load(global::Azure.Security.KeyVault.Secrets.SecretProperties secret) { throw null; } | ||
| } | ||
| public partial interface IKeyVaultSecretManager | ||
| { | ||
| string GetKey(global::Azure.Security.KeyVault.Secrets.KeyVaultSecret secret); | ||
| bool Load(global::Azure.Security.KeyVault.Secrets.SecretProperties secret); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!-- This file is automatically generated. --> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
| </PropertyGroup> | ||
| <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> | ||
| <Compile Include="Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.netstandard2.0.cs" /> | ||
| <Compile Include="Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.Manual.cs" /> | ||
| <Reference Include="Azure.Security.KeyVault.Secrets" /> | ||
| <Reference Include="Azure.Identity" /> | ||
| <Reference Include="Microsoft.Extensions.Configuration" /> | ||
| <Reference Include="Microsoft.Extensions.Configuration.FileExtensions" /> | ||
| </ItemGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.Extensions.Configuration | ||
| { | ||
| public static partial class AzureKeyVaultConfigurationExtensions | ||
| { | ||
| public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddAzureKeyVault(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.AzureKeyVaultConfigurationOptions options) { throw null; } | ||
| public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddAzureKeyVault(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, System.Uri vault) { throw null; } | ||
| public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddAzureKeyVault(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, System.Uri vault, Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager manager) { throw null; } | ||
| } | ||
| } | ||
| namespace Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets | ||
| { | ||
| public partial class AzureKeyVaultConfigurationOptions | ||
| { | ||
| public AzureKeyVaultConfigurationOptions() { } | ||
| public Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets.IKeyVaultSecretManager Manager { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } | ||
| public System.TimeSpan? ReloadInterval { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } | ||
| } | ||
| public partial class DefaultKeyVaultSecretManager | ||
| { | ||
| public DefaultKeyVaultSecretManager() { } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using Azure.Security.KeyVault.Secrets; | ||
| using Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets; | ||
|
|
||
| namespace ConsoleApplication | ||
| { | ||
| public class EnvironmentSecretManager : DefaultKeyVaultSecretManager | ||
| { | ||
| private readonly string _environmentPrefix; | ||
|
|
||
| public EnvironmentSecretManager(string environment) | ||
| { | ||
| _environmentPrefix = environment + "-"; | ||
| } | ||
|
|
||
| public override bool Load(SecretProperties secret) | ||
| { | ||
| return HasEnvironmentPrefix(secret.Name); | ||
| } | ||
|
|
||
| public override string GetKey(KeyVaultSecret secret) | ||
| { | ||
| var keyName = base.GetKey(secret); | ||
|
|
||
| return HasEnvironmentPrefix(keyName) | ||
| ? keyName.Substring(_environmentPrefix.Length) | ||
| : keyName; | ||
| } | ||
|
|
||
| private bool HasEnvironmentPrefix(string name) | ||
| { | ||
| return name.StartsWith(_environmentPrefix); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$(DefaultNetCoreTargetFramework);net472</TargetFrameworks> | ||
| <DebugType>portable</DebugType> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="settings.json" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="Microsoft.Extensions.Configuration.Azure.KeyVault.Secrets" /> | ||
| <Reference Include="Microsoft.Extensions.Configuration.Json" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Security.Cryptography.X509Certificates; | ||
| using Azure.Identity; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace ConsoleApplication | ||
| { | ||
| public class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| var builder = new ConfigurationBuilder(); | ||
| builder.AddJsonFile("settings.json"); | ||
|
|
||
| var config = builder.Build(); | ||
|
|
||
| var store = new X509Store(StoreLocation.CurrentUser); | ||
|
||
| store.Open(OpenFlags.ReadOnly); | ||
| var cert = store.Certificates.Find(X509FindType.FindByThumbprint, config["CertificateThumbprint"], false); | ||
|
|
||
| builder.AddAzureKeyVault( | ||
| new Uri(config["Vault"]), | ||
| new ClientCertificateCredential( | ||
| config["TenantId"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see "TenantId" declared below in settings.json. |
||
| config["ClientId"], | ||
| cert.OfType<X509Certificate2>().Single()), | ||
| new EnvironmentSecretManager("Development")); | ||
| store.Close(); | ||
|
|
||
| config = builder.Build(); | ||
|
|
||
| Console.WriteLine(config["ConnectionString"]); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "CertificateThumbprint": "", | ||
| "Vault": "", | ||
BrennanConroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "ClientId": "" | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.