Skip to content

Security proposition for KeyVault secret usage #20175

Description

@FranckSix

In many Azure services, we can use Key Vault references directly in configuration values:

@Microsoft.KeyVault(SecretUri=https://MyDevKv.vault.azure.net/secrets/SqlPassword)

This approach keeps the secret inside Key Vault and allows the application to resolve it at runtime.

With ARM templates, this scenario was natively supported through Key Vault parameter references:

"keyVaultSqlPassword": {
   "reference": {
      "keyVault": {
         "id": "/subscriptions/id/resourceGroups/rgName/providers/Microsoft.KeyVault/vaults/MyDevkv"
      },
      "secretName": "SqlPassword"
   }
}

With Bicep, the closest equivalent is:
kv.getSecret('SqlPassword')
or
az.getSecret(id, rgName, MyDevkv, SqlPassword)

However, this retrieves the actual secret value during deployment. and in WepApp Environnement variable.

Before (ARM / Key Vault Reference)

{
    "name": "SqlPassword",
    "value": "@Microsoft.KeyVault(SecretUri=https://MyDevkv.vault.azure.net/secrets/SqlPassword)",
    "slotSetting": false
}

The application setting contains only a reference to Key Vault.

After (Bicep with getSecret())

{
    "name": "ApplicationInsightKey",
    "value": "MySuperStrongPassword!",
    "slotSetting": false
}

The actual secret value is stored in the Web App configuration.

Why this matters
Secrets are no longer isolated in Key Vault.
Application administrators can potentially view sensitive values.
Secret rotation becomes more complicated.
The intent is less clear during code reviews.
It encourages retrieving secrets rather than referencing them.

Proposed enhancement

Add support for a Key Vault reference API that expresses intent clearly:

Usage:

appSettings: {
   SqlPassword: kv.getReference('SqlPassword')
}

Which would compile to:
@Microsoft.KeyVault(SecretUri=https://MyDevKv.vault.azure.net/secrets/SqlPassword)

This would provide a secure and intuitive migration path from ARM templates while promoting the principle of keeping secrets in Key Vault whenever possible.

Metadata

Metadata

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions