**TL;DR:** An expired secret does not always error loudly: get_secret returns the newest ENABLED version, so expiry can mean silently getting an old value. Check expiry and enabled flags, not just existence. TL;DR: An expired secret does not always error loudly: get_secret returns the newest ENABLED version, so expiry can mean silently getting an old value. Rotate: az keyvault secret set creates a new version; the old one stays for history.

## The error

```text
.

## The fix

Symptoms: auth failures downstream after
```

## The fix

**TL;DR:** An expired secret does not always error loudly: get_secret returns the newest ENABLED version, so expiry can mean silently getting an old value. Check expiry and enabled flags, not just existence. Rotate: az keyvault secret set creates a new version; the old one stays for history. Then update the consumer, or better, have the consumer always read "latest".

## The fix

Symptoms: auth failures downstream after "nothing changed", or `SecretExpired` / 403 on get.

Diagnosis:

```
az keyvault secret show --vault-name [vault] --name [secret]   --query "{expires: attributes.expires, enabled: attributes.enabled, created: attributes.created}"
```

1. **Expired.** `attributes.expires` in the past. Rotate: `az keyvault secret set` creates a new version; the old one stays for history. Then update the consumer, or better, have the consumer always read "latest".
2. **Disabled, not expired.** A rotation gone wrong sometimes disables the newest version instead of the old one. `get_secret` without a version then returns the previous enabled version with no error. If downstream auth fails but the vault "has" the secret, check the enabled flag on the latest version.
3. **Near-expiry automation.** Key Vault emits `Microsoft.KeyVault.SecretNearExpiry` Event Grid events 30 days before expiry (configurable via lifetime actions). Wire it to a rotation function instead of discovering expiry from an outage.
4. **Access policy expiry.** In the access-policy model, the policy itself does not expire, but the service principal's secret used to authenticate TO the vault does (AADSTS7000215). If the vault calls worked yesterday, suspect the caller's credential, not the stored secret.
5. **Purge protection vs rotation.** With purge protection on, old versions linger; that is fine. Do not purge to "clean up" unless the secret value itself is compromised.

Verify: after rotation, read the secret with the consumer's identity and confirm the version id matches the newest enabled version.

## When to use this

- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: Azure Key Vault.
- You want the fastest verified fix before digging through logs.

## When not to use this

- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.

## Edge cases

- Do not purge to "clean up" unless the secret value itself is compromised.