Orchard Core Azure Key Vault - Prompt Templates
Load Configuration From Azure Key Vault
You are an Orchard Core expert. Wire Azure Key Vault as a configuration source so secrets such as connection strings and API keys are pulled from Key Vault instead of appsettings.
Guidelines
- Azure Key Vault support ships in the
OrchardCore.Configuration.KeyVaultlibrary. It is a host configuration provider, not a tenant feature, so you enable it in your startup code, not through a recipe or the admin Features screen. - Add a package reference to
OrchardCore.Configuration.KeyVaultin the web (startup) project. - Register the provider by calling
AddOrchardCoreAzureKeyVaulton the builder. Overloads exist forIHostBuilder,IWebHostBuilder, andConfigurationManager. - Authentication defaults to
DefaultAzureCredential(Azure Identity). In Azure, prefer a Managed Identity; locally, sign in through Visual Studio, VS Code, or the Azure CLI. You may pass a customTokenCredentialto override this. - Configure the vault with the
OrchardCore:KeyVault:Azuresection (in appsettings or environment variables, since it is read before Key Vault is added): provideKeyVaultNameorVaultURI, and optionallyReloadInterval(in seconds) to poll for changes. LeaveReloadIntervalblank to disable reloading. - Secret-name translation: Key Vault forbids
:and_, so Orchard Core'sAzureKeyVaultSecretManagertranslates---to_and--to:when mapping a secret name back to a configuration key. - All C# classes must use the
sealedmodifier, except View Models.
Package Reference (web project)
<ItemGroup>
<PackageReference Include="OrchardCore.Configuration.KeyVault" Version="3.*" />
</ItemGroup>
Registering Key Vault in Program.cs
Using the minimal hosting model with ConfigurationManager:
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddOrchardCoreAzureKeyVault();
builder.Services
.AddOrchardCms();
var app = builder.Build();
app.UseOrchardCore();
app.Run();
Using the generic host builder:
Host.CreateDefaultBuilder(args)
.AddOrchardCoreAzureKeyVault()
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
Passing a custom credential (for example a specific user-assigned managed identity):
var credential = new ManagedIdentityCredential("<client-id>");
builder.Configuration.AddOrchardCoreAzureKeyVault(credential);
Configuration Section
{
"OrchardCore": {
"KeyVault": {
"Azure": {
"KeyVaultName": "my-vault",
"VaultURI": "",
"ReloadInterval": "60"
}
}
}
}
Environment variable form: OrchardCore__KeyVault__Azure__KeyVaultName=my-vault.
- Provide either
KeyVaultName(short name) orVaultURI(full vault host URI).VaultURItakes precedence when set. A missing or invalid value throws at startup with a message naming theOrchardCore:KeyVault:Azure:*key. ReloadIntervalis a number of seconds; when present the provider re-polls the vault on that interval.
Secret Name Translation
Key Vault secret names cannot contain : or _. Orchard Core maps them back to configuration keys:
| Key Vault secret name | Resolved configuration key |
|---|---|
| OrchardCore--Shells--Database--ConnectionString | OrchardCore:Shells:Database:ConnectionString |
| OrchardCore--Media--Azure--ConnectionString | OrchardCore:Media:Azure:ConnectionString |
| OrchardCore--DataProtection--Azure--ConnectionString | OrchardCore:DataProtection:Azure:ConnectionString |
| OrchardCore--Redis--Configuration | OrchardCore:Redis:Configuration |
| OrchardCore--Email--Smtp--Password | OrchardCore:Email:Smtp:Password |
| OrchardCore--SignalR--Azure--ConnectionString | OrchardCore:SignalR:Azure:ConnectionString |
| ConnectionStrings--Default | ConnectionStrings:Default |
Orchard Core 4.0 configuration sections are grouped by service without the
OrchardCore_ prefix, so most secret names no longer need the triple dash. Use
--- only for keys that really contain _.
Rules applied by AzureKeyVaultSecretManager:
--(double dash) becomes:(section separator).---(triple dash) becomes_(underscore inside a key segment).
Common Uses
- Store the shells/database connection string, SMTP credentials, OpenID signing secrets, and external provider API keys in Key Vault, then reference them through normal configuration keys elsewhere in the app.
- Combine with
OrchardCore.DataProtection.Azure(data-protection key storage) for a fully externalized secret and key management setup.
Configuration Provider vs. the Secrets Module Store
Orchard Core 4.0 also ships OrchardCore.Secrets.AzureKeyVault, a tenant
feature that makes Key Vault a store of the Secrets module (store name
AzureKeyVault, configured under OrchardCore:Secrets:AzureKeyVault with a
host-registered keyed SecretClient). The two are independent:
| | OrchardCore.Configuration.KeyVault | OrchardCore.Secrets.AzureKeyVault |
|---|---|---|
| Kind | Host configuration provider | Tenant feature (store of OrchardCore.Secrets) |
| Consumers | Any configuration key | Settings that reference a secret by *SecretName, and ISecretManager |
| Entry names | --/--- encoded configuration keys | Prefix, tenant, and name with a hash, plus ownership tags |
| Managed in | Azure only | Orchard admin (Tools → Security → Secrets) |
Credentials supplied through configuration (including this provider), such as
OrchardCore--Email--Smtp--Password, still work in 4.0 but log a
LegacySecretConfiguration warning (event 8100) for the integrations that
support secrets. To retire them, create the secret in the Secrets module (in the
AzureKeyVault or Database store), select it in the integration's settings,
then delete the configuration entry. See orchardcore-secrets.
Notes
- Because Key Vault is a host-level configuration provider, its values are available to every tenant through the shared host configuration.
- If a secret does not resolve, verify the double/triple-dash encoding of the secret name and that the authenticating identity has
get/listsecret permissions on the vault.
Upgrading from 3.x
- Rename the
OrchardCore:OrchardCore_KeyVault_Azuresection toOrchardCore:KeyVault:Azure(env varOrchardCore__KeyVault__Azure__KeyVaultName). The old name is deprecated but still read. - Rename secrets that target renamed sections, for example
OrchardCore--OrchardCore---Media---Azure--ConnectionStringtoOrchardCore--Media--Azure--ConnectionStringandOrchardCore--OrchardCore---Redis--ConfigurationtoOrchardCore--Redis--Configuration. Old section names still bind, and the new name wins when both are present. - Configuration credentials of integrations that support the Secrets module (SMTP, Azure email and SMS, Azure AI Search, Facebook, GitHub, Google, Microsoft Account, X) now log
LegacySecretConfiguration; plan to move them to secrets.