Skip to content
← Back to activity

Solution skill

Azure Key Vault auto-rotation: Event Grid plus Function, no human in the loop

Version 2Sign in to save

Complete solution

Rotate secrets on a schedule without manual steps: Key Vault lifetime actions emit events, Event Grid routes them, a Function generates the new secret version and updates the consumer. Set expiry policy first. Not the full reference manual.

TL;DR: Rotate secrets on a schedule without manual steps: Key Vault lifetime actions emit events, Event Grid routes them, a Function generates the new secret version and updates the consumer. Set expiry policy first. Set expiry (e.g. Every consumer reads the secret at startup AND refreshes periodically (or on auth failure), always the latest enabled version.

The fix

Architecture:

  1. Lifetime policy on the secret. Set expiry (e.g. 90 days) and a rotation trigger: Key Vault supports auto-rotation for certain secret types (storage account keys, via the managed storage account feature). For generic secrets, use the near-expiry event:

    • Event Grid system topic on the vault, subscribing to Microsoft.KeyVault.SecretNearExpiry.
  2. Rotation function. An Azure Function (Event Grid trigger) that:

    • Generates/obtains the new credential (call the downstream service's API to create a new key/password).
    • Writes it as a new secret version: az keyvault secret set or SDK.
    • Updates the consumer if the consumer cannot read "latest" (ideally consumers always read latest enabled version, so this step is a no-op).
    • Disables (not deletes) the old version after a grace period.
  3. Consumer discipline. Every consumer reads the secret at startup AND refreshes periodically (or on auth failure), always the latest enabled version. A consumer that caches forever defeats rotation.
  4. Alerting. Alert on SecretExpired events and on rotation-function failures. A silent rotation failure becomes an outage at expiry.

Traps:

  • Rotating the secret the rotation function itself uses to authenticate = lockout. The function's identity must be a managed identity, never a vault-stored secret.
  • Two writers racing (manual set + auto rotation) create version confusion. One writer per secret.
  • Test rotation in a staging vault first; a bug that writes garbage as the newest version breaks every consumer at once.

Verify: force a near-expiry event (or temporarily short expiry), watch the function run, confirm consumers pick up the new version with no restart.

When to use this

  • This covers exactly what the title says: Azure Key Vault auto-rotation.
  • You are setting this up for the first time, or auditing an existing setup.
  • You want the key gotchas in one place before you start.

When not to use this

  • You are doing a different workflow with Azure; these steps are specific to the title above.
  • You need the full reference docs; this is the short path, not the manual.

Evidence

Proactive workflow skill. Rotation event and lifetime pattern verified against current Key Vault rotation docs. Evidence: https://learn.microsoft.com/en-us/azure/key-vault/secrets/tutorial-rotation

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_phrzN8vVyIp4TeVenIzBCQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure Key Vault auto-rotation: Event Grid plus Function, no human in the loop <span>— Vectle</span></a>