-
Notifications
You must be signed in to change notification settings - Fork 201
Create a Azure KeyVault based configuration provider #487
Comments
@brentschmaltz We haven't started any real work yet, just some initial discussion and design. |
Given two vaults:
I'd like to do the following things:
To support most of this, we ended up building a solution that uses a two step process for loading secrets - we have a config file which defines the mappings and this is then used to load the secrets. This is how we use it:
{
"KeyVaults": {
"myvault1": {
"Secrets": {
"DbConnectionString": "Sql-ConnectionString",
"Module1/SqlConnectionString": "Sql-ConnectionString",
"Module2/SqlConnectionString": "Sql-ConnectionString-Module2",
"ApplicationInsightsKey": "ApplicationInsightsKey"
}
}
}
}
{
"ClientID": "75e92952-701b-43f7-9f8b-8769bdd804de",
"CertThumbprint": "a909502dd82ae41433e6f83886b00d4277a32a7b",
"StoreLocation": "LocalMachine",
"KeyVaults": {
"myvault1": {
"KeyVaultName": "myvault1-europe"
}
}
} On startup, we first load this configuration with a I could provide some code if you're interested - it's not really beautiful though 😄 |
Is the selection of europe vs us known at startup and doesn't change? or is it that some code paths want to use one and some want to use the other? |
Our current scenario is that we have different vaults for different environments. this means, it is known at startup and doesn't change. If we would scale-out one service to additional data centers we might just use another environment key and create another mapping file. So this case would also be known at startup. (We don't yet have this scenario so I haven't given much thought into it) We also don't yet regularly refresh secrets, so Key Vault outages while our application is running are no concern for us atm. Not sure what requirements people have that use multi-tenancy etc. |
Ok cool, so connecting to different key vault instances in different environments is fine then, with some code when you add it. However, the ability to ask for "ConnStr" and have that map to two different named keys in the vault isn't something that I had thought about at all. You want this because you don't control the vaults and they end up with slightly different names. Right? |
exactly! let's say we have one big Key Vault for our application that contains connection strings for all modules (each uses a separate DB). In Key Vault, you would have to give them different names - e.g. "CustomersConnectionString", "SalesConnectionString", ... In code, you might have separate libraries for each module and each might have an options class - e.g. If you want to use |
of course, all of this might be pretty advanced - maybe having just a 1:1 mapping covers most people?! but for us, this was/is essential. |
Is your app ASP.NET Core or are you dumping all the things you needed for a different app? |
we use one key vault per bounded context. one bounded context usually contains an ASP.NET Core based web API and there might also be background workers that process stuff from Azure Service Bus / Azure Event Hubs etc. |
I'd like to separate key vaults based on the risks they pose. So you end with something like this:
As @cwe1ss mentioned, access control is per vault, not per secret, so the number of vaults used by an application depends on its business need. Vaults are often deployed to each site (westus, eastus) to ensure disaster recovery. Secrets are uniquely named across vaults to ensure we're able to move a secret from one vault to another. The name doesn't include the location. Secrets follows a naming convention such as
The dashes are used to ease parsing. So like environment variables, I'd rather register one or more vaults with the configuration system and optionally add a prefix (e.g. You can also use tags to categorize secrets. For example, have a tag The pattern here is no different than that of ini files or environment variables, with some additional capabilities to benefit from additional metadata. |
One problem is azure key vault secret names cannot contain a colon yet this is what Configuration uses for sub-property names. Maybe add support for overriding name through the use of a "ConfigKey" tag like your article uses https://azure.microsoft.com/en-us/documentation/articles/guidance-multitenant-identity-keyvault/#implementation Another idea is automatically replace |
@bloudraak What you are describing sounds pretty much exactly like what we were thinking of. @mcm-ham This is a problem with other sources as well, the environment variable one for example. IIRC we just use |
sad to see this closed without any further discussion. I'm afraid the current solution will only cover the most basic requirements. Unfortunately, I don't have enough time right now to finish #502, but maybe it's useful for somebody. |
@cwe1ss we are definitely going to iterate on KeyVault provider more, We just want to get simpler prerelease version out so people can actually start using it. |
I'm not sure if this is the same KeyVaultProvider as this: Microsoft.SqlServer.Management.AlwaysEncrypted.AzureKeyVaultProvider. I need the above to work with .NET Core. The above lib is currently incompatible with NetStandard. Looks like it is dependent on the old Microsoft.Azure.KeyVault 1.0.0, which is incompatible. However the latest version of Microsoft.Azure.KeyVault is 2.0.6, which is compatible with NetStandard. Is it possible to update your provider library to use Microsoft.Azure.KeyVault 2.0.6 so that it is .NET Core compatible? |
@moraleslos the provider in this repo is neither of those things -- it's an ASP.NET Core Configuration provider. Perhaps you're looking for this repo: https://github.com/Azure/azure-sdk-for-net |
I had the chance to play around with this last weekend and found that most stuff was configurable and extendable for most of my use case. You can see my secret manager here: https://gist.github.com/pksorensen/6f067c2d2e62db05e996c39254790acd#file-configuration-cs-L256 Now the thing I would like added is, that for each secret to control what is added to Data from IKeyVaultSecretManager. Right now it just add the value as a string. So you have to do IOption to get it out. I just prefixed all keys with "KeyVault--" allowing me to do a KeyVaultOption with all secrets using configuraiton. We have metadata stored in tags and also would liek access to attributes and content type of the secrets. So if the source called the secretmanager to actually populate Data, then we could extend it to add value as a value key, tags under a tags key ect. And basicly you can have a model for your secret that can be resolved from configuration also and not just the value. |
@pksorensen I am not able to understand what you are describing, but if this is a feature request for the KeyValue provider, please create a new issue. |
CoreCLR based KeyVault SDK will be ready late August per @glennc.
Let's sit down and come up with the design.
The text was updated successfully, but these errors were encountered: