Secrets in Azure for .NET apps: Key Vault with Managed Identity and DefaultAzureCredential

xUnit Testing & CI/CD in .NET November 13, 2026 csharp

In Azure Key Vault, accessed through Managed Identity: no connection strings or passwords in the repo or pipeline.

csharp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// ======================================================================
// Q: Where do secrets live in Azure?
//
// In Azure Key Vault, accessed through Managed Identity: no connection strings
// or passwords in the repo or pipeline. For the database: Entra ID
// authentication where possible. Locally: dotnet user-secrets.
// Observability: Application Insights / OpenTelemetry, structured logging
// without PII, health checks (/health/ready checking the DB and the ERP), alerts
// on outbox and DLQ size.
// ======================================================================

builder.Configuration.AddAzureKeyVault(
    new Uri(builder.Configuration["KeyVault:Uri"]!), new DefaultAzureCredential());