Secrets in a Service
π€ Generated with Claude Code
β οΈ Not yet reviewed
Co-Authored-By: Claude (noreply@anthropic.com)
Every secret a service needs β connection strings, API keys, certificates β lives in Azure Key Vault. Your repository holds a reference to it, never the value.
This page is the developer half. The vault side β which vaults exist, how servers authenticate, how a secret is actually created β is Infrastructure β Secrets.
Reading a secret from your serviceβ
Add Tis.Hosting.Extensions.Configuration.Secrets, point appsettings.json at a vault and
a prefix, and load it at start-up:
{
"KeyVault": {
"VaultName": "at-tgca-tis-f-default",
"Prefix": "meineapp"
}
}
builder.Configuration.AddAzureKeyVaultFromConfig();
Every secret carrying that prefix is then an ordinary IConfiguration value. Nothing in
your code refers to Key Vault after this line.
Finding the name your configuration expectsβ
Secrets follow {prefix}--{section}--{key}, with : becoming -- and _ becoming -:
| Configuration path | Secret name in the vault |
|---|---|
ConnectionStrings:Default | meineapp--ConnectionStrings--Default |
ExternalAuth:Oidc:ClientSecret | meineapp--ExternalAuth--Oidc--ClientSecret |
When a value is empty at start-up, that mapping is the first thing to check β a secret named against the wrong pattern is simply never loaded, and nothing fails loudly.
Local developmentβ
Developers have read access to the development vault, and DefaultAzureCredential
picks up your Visual Studio subscription automatically. A service therefore usually runs
locally with no secret setup at all.
Two things follow from that:
-
It is read access, and only to the development vault. Fachtest, Stage and Prod authenticate as an Enterprise Application, not as you β see Infrastructure β Secrets.
-
For a value the development vault does not have, use user secrets rather than
appsettings.Development.json, which is in git:dotnet user-secrets set "ConnectionStrings:Default" "β¦"
Requesting a new secretβ
Who does this: DevOps team β developers have no write access to the key vaults. Ask them, and do not put the value into configuration while you wait.
Bring three things: the application prefix, the environments the secret is needed in, and the configuration path your service reads it from. They create the secret; you reference it by name.
This happens rarely enough not to be a bottleneck, but it is not self-service β so raise it when you start the work, not when you are ready to deploy.
What must never happenβ
- A secret value MUST NOT be committed β not to
appsettings.json, not to a test fixture, not to a branch that is deleted afterwards. Git keeps it. - If one is committed, it MUST be rotated. Tell the DevOps team immediately. Deleting the line, force-pushing or rewriting history does not undo it; treat the value as compromised.
- A pull request that touches
appsettings*.jsonMUST be checked for plaintext values during review. This is the cheapest place to catch it.
Relatedβ
| Topic | Where |
|---|---|
Vault inventory, naming, server authentication, tis-secrets | Infrastructure β Secrets |
| Keeping secrets out of git | git/ |
| Service project layout | api-services/ |