A real-world migration of ASP.NET Core configuration to Azure Key Vault and Azure App Configuration with managed identity: inventory and classification, RBAC roles, AddAzureKeyVault versus App Configuration Key Vault references, labels per environment, sentinel-key refresh and Key Vault reload intervals, rotation with overlapping secret versions, passwordless Entra ID auth, start-up resilience and replicas, feature flags with Microsoft.FeatureManagement, and the rollout plan.
I'd inventory and classify every setting first: secrets, environment-specific values, shared values, and which must change live. Secrets go to Key Vault. Non-secret settings and feature flags go to Azure App Configuration with a label per environment, and secrets are referenced from there through Key Vault references. The app authenticates with its managed identity using least-privilege roles, and where possible secrets disappear entirely through passwordless Entra ID auth to SQL, Storage and Service Bus.
For refresh, use a sentinel key with a refresh interval and a secret refresh interval, and read live values through IOptionsMonitor. Rotation uses overlapping versions, so old and new both work during the window. Add start-up timeouts and replicas, and keep ValidateOnStart.
The trade-off: central, audited, rotatable configuration, in exchange for a network dependency at start-up that you must design for.
"I'd treat it as a migration, not a library swap. Step one is an inventory: every key in every appsettings file and every portal setting, classified as secret or not, per-environment or shared, restart-only or live. That usually shows half the 'secrets' don't need to exist: the SQL password, the storage key and the Service Bus connection string can all go away with managed identity and Entra ID auth. What's left, third-party API keys and SMTP credentials, goes into Key Vault, one vault per environment, with the app's managed identity granted only Key Vault Secrets User.
Non-secret settings and feature flags go into App Configuration, with one store and a label per environment, and secrets appear there as Key Vault references that the app resolves with its own identity. In the app I call
AddAzureAppConfiguration, connect with the managed identity, select unlabelled keys plus the environment's label, register a sentinel key withrefreshAll, set a refresh interval of about 30 seconds, and add theUseAzureAppConfigurationmiddleware so refresh is triggered by traffic. Live settings are read throughIOptionsMonitor; restart-only ones stayIOptions.For example, at [company] we migrated [eight] services this way. Rotation used to mean a deployment and an outage window; afterwards we added a new secret version, waited one refresh interval plus a margin, then disabled the old one, with zero downtime. The thing people miss is start-up: the app now depends on two network services before it can serve. So I set a start-up timeout, use App Configuration replicas in Australia East and Southeast, and decide per source whether a failure should stop the app or fall back. Moving secrets is easy; designing refresh, rotation and failure behaviour is the senior part."
| Kind | Destination | Why |
|---|---|---|
| Azure resource credentials (SQL, Storage, Service Bus) | Nowhere: managed identity, Entra ID auth | No secret to leak or rotate |
| Third-party secrets (Stripe, SMTP) | Key Vault, referenced from App Configuration | Encrypted, RBAC, audit, versions |
| Shared non-secret settings | App Configuration, no label | One place, change history |
| Per-environment settings | App Configuration, label = environment | Same keys, different values |
| Operational switches | App Configuration feature flags | Change live, targeting, audit |
| Safe defaults | appsettings.json | App still has sensible values offline |
| Concern | Mechanism |
|---|---|
| Settings change | Update the keys, then bump the sentinel; the next refresh reloads everything |
| Refresh trigger | UseAzureAppConfiguration middleware (web) or IConfigurationRefresher.TryRefreshAsync (workers) |
| Secret refresh | Key Vault reference secret refresh interval, or ReloadInterval with AddAzureKeyVault |
| Rotation | New version enabled, wait longer than the refresh interval, disable the old one |
| Long-lived objects | Rebuild clients on change (IOptionsMonitor.OnChange) or read per use |
After the migration, a leaked SMTP credential was rotated in [12 minutes] without a deployment: a new Key Vault version, a sentinel bump, confirmation in logs that all instances had reloaded, then the old version disabled. Previously the same change had needed a release and a [30-minute] maintenance window.
Checks whether the candidate can design and run a secrets and configuration migration end to end, including the parts that fail in production.
Green flags
IOptionsMonitor.Red flags
+---------------------------+
| App Configuration store | labels: (none), Test, Production
app (managed --->| settings + feature flags | Key Vault references for secrets
identity) +-------------+-------------+
| | reference (URI only)
| v
+------------------> Key Vault (per environment) RBAC: Key Vault Secrets User
|
+------------------> Azure SQL / Storage / Service Bus Entra ID auth, no secret
The app resolves Key Vault references itself, so App Configuration never sees secret values, and access to secrets stays governed by Key Vault RBAC and audit logs.
FROM EXTERNAL PROVIDER for SQL.ManagedIdentityCredential (or restrict DefaultAzureCredential) so start-up does not probe several credential types; locally developers use DefaultAzureCredential with their own login.request -> UseAzureAppConfiguration middleware
| interval elapsed?
v
GET sentinel key (cheap, one request)
| changed?
v
reload all selected keys -> IConfiguration change token -> IOptionsMonitor rebuilds
Refresh is triggered by activity, and it is non-blocking for the request. Watching a single sentinel avoids one request per key, which matters for the store's request quotas. Workers without HTTP traffic call IConfigurationRefresher.TryRefreshAsync on a timer.
t0 add secret version v2 (v1 still enabled)
t1 apps refresh (secret refresh interval) -> now use v2
t2 wait > refresh interval + margin; confirm via logs or metrics
t3 disable v1 at the provider
For third-party keys that allow two active keys (Stripe, storage keys), alternate between key A and key B. Clients built once at start-up (an SMTP client, an SDK client holding the key) must be rebuilt on change, or the new value never reaches them.
AddAzureAppConfiguration throws, and the app fails to start. That is right for required secrets and wrong if it turns a regional blip into a full outage. Options: a start-up timeout, optional: true with safe defaults for non-critical settings, and replicas (Australia East primary, Southeast replica).GetDebugView (masked) between old and new.ValidateOnStart to the template.optional: true.Program.cs for a service using App Configuration with Key Vault references, sentinel refresh, feature flags and passwordless SQL.
// Packages: Microsoft.Azure.AppConfiguration.AspNetCore, Microsoft.FeatureManagement.AspNetCore, Azure.Identity
using Azure.Identity;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.FeatureManagement;
var builder = WebApplication.CreateBuilder(args);
// Locally: developer login. In Azure: the app's managed identity only, no credential probing.
Azure.Core.TokenCredential credential = builder.Environment.IsDevelopment()
? new DefaultAzureCredential()
: new ManagedIdentityCredential();
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(new Uri(builder.Configuration["AppConfig:Endpoint"]!), credential)
.Select(KeyFilter.Any, LabelFilter.Null) // shared values
.Select(KeyFilter.Any, builder.Environment.EnvironmentName) // environment overrides win
.ConfigureKeyVault(kv =>
{
kv.SetCredential(credential); // resolve references as the app
kv.SetSecretRefreshInterval(TimeSpan.FromMinutes(5)); // pick up rotated versions
})
.ConfigureRefresh(refresh => refresh
.Register("Shop:Sentinel", refreshAll: true) // bump this to reload everything
.SetRefreshInterval(TimeSpan.FromSeconds(30)))
.UseFeatureFlags(flags => flags.SetRefreshInterval(TimeSpan.FromSeconds(30)));
});
builder.Services.AddAzureAppConfiguration();
builder.Services.AddFeatureManagement();
builder.Services.AddOptions<CheckoutOptions>().BindConfiguration("Checkout").ValidateDataAnnotations().ValidateOnStart();
var app = builder.Build();
app.UseAzureAppConfiguration(); // triggers refresh on incoming requests
app.MapGet("/checkout/limits", async (
Microsoft.Extensions.Options.IOptionsMonitor<CheckoutOptions> options,
IFeatureManager features) =>
{
var newFlow = await features.IsEnabledAsync("NewCheckoutFlow");
return Results.Ok(new { options.CurrentValue.MaxItems, newFlow }); // CurrentValue: sees refreshed values
});
app.Run();
public sealed class CheckoutOptions
{
[System.ComponentModel.DataAnnotations.Range(1, 500)] public int MaxItems { get; init; } = 100;
}
// appsettings.json: safe defaults and endpoints only; SQL is passwordless
{
"AppConfig": { "Endpoint": "https://appcs-shop-aue.azconfig.io" },
"ConnectionStrings": { "Default": "Server=tcp:sql-shop-aue.database.windows.net;Database=Shop;Authentication=Active Directory Default;Encrypt=True" },
"Checkout": { "MaxItems": 100 }
}
refreshAll: true and bump it after a set of changes.UseAzureAppConfiguration or a refresher in workers. Why it is wrong: Nothing triggers refresh, so values never change. Instead: Add the middleware for web apps and call TryRefreshAsync on a timer in workers.The migration is mostly about decisions, not code: what should not be a secret at all, what may change live, which source wins, and what happens when the configuration service is down. I write those down in an ADR and in infrastructure as code. I also keep the blast radius small: one vault per environment (and per application where teams differ), labels rather than separate stores for environments, and feature flags with an owner and an expiry so they don't become permanent configuration.
After the migration, configuration needs the same observability as code. I send Key Vault and App Configuration diagnostic logs to Log Analytics and alert on denied secret reads, unexpected readers and secrets near expiry (Key Vault raises Event Grid events for that). App Configuration's revision history and snapshots give an audit trail and a quick rollback for a bad change. For disaster recovery, Key Vault keeps soft delete and purge protection on, App Configuration has a replica in Australia Southeast, and the restore steps for both are rehearsed alongside the application runbook.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
AddAzureKeyVault directly |
One app, few secrets, no App Configuration | Loads every secret in the vault unless filtered | Many apps sharing a vault |
| App Configuration + Key Vault references | Several services, labels, feature flags | Two services to run and secure | A single tiny app |
| Platform Key Vault references (App Service, Container Apps) | No code changes, secrets as environment variables | Restart to pick up changes | Settings that must change live |
| Passwordless Entra ID | Azure SQL, Storage, Service Bus | Role and database user set-up | Third-party APIs |
User secrets (the Secret Manager) keep developer-only secrets out of the repository. dotnet user-secrets init adds a UserSecretsId to the project file, and dotnet user-secrets set "Stripe:ApiKey" "sk_test_..." writes the value to a plain-text secrets.json in your user profile (%APPDATA%\Microsoft\UserSecrets\<id> on Windows, ~/.microsoft/usersecrets/<id> on Linux and macOS).
CreateBuilder loads them only in the Development environment, as a provider after the appsettings files, so code reads them like any other key.
They are not encryption: anyone or anything running as you can read the file. In production use Azure Key Vault with managed identity, Key Vault references, or platform secrets, and passwordless Entra ID authentication where the service supports it. The trade-off: zero setup for developers, but no protection beyond "not in git".
All three give you the same bound options; they differ in lifetime and freshness.
IOptions<T>: singleton, built once on first .Value, never changes, no named options. The default for settings that need a restart anyway.IOptionsSnapshot<T>: scoped, rebuilt once per request (per scope), supports Get(name). A request sees one consistent value. It can't go into singletons, and it rebinds on every request.IOptionsMonitor<T>: singleton, CurrentValue is cached and rebuilt when the configuration change token fires, supports Get(name) and OnChange. Use it in singletons and BackgroundService.Changes only arrive if a provider reloads (JSON files, App Configuration refresh), never from environment variables. The trade-off: fresher values mean code that must cope with values changing under it.
How to tell it (STAR)
**S:** At [company], our [eight] services kept SQL passwords and API keys in appsettings files and portal settings, and an audit flagged it; every rotation needed a release and a maintenance window. **T:** I led moving configuration to Key Vault and App Configuration without downtime. **A:** I started with an inventory and found most secrets could disappear by switching SQL, Storage and Service Bus to managed identity. The rest went into Key Vault, referenced from App Configuration with environment labels and a sentinel key for refresh. We migrated one service per sprint behind ValidateOnStart, then rotated everything that had ever been committed and turned on push protection. **R:** Committed credentials went from [23] to zero, and rotations became a [12-minute] no-downtime task instead of a release.
Last updated 23 Nov 2026.