Hi @Yu-Jeong Seo , please check below and let me know if any further question on this.
- How to discover / inventory resources that generate auto-keys
- Run an initial Resource Graph scan for resource types that typically have data-plane keys (storageAccounts, Microsoft.DocumentDB/databaseAccounts, Cognitive Services, Search, etc.). Save the list to a table (resourceId, type, subscription, resourceGroup, tags).
- Create/maintain a small resource-type → key API & semantics mapping (e.g., storageAccounts → Access Keys REST/portal; Cosmos DB → listKeys/regenerateKey). This is the authoritative mapping your automation will use.
- Use Azure Policy AuditIfNotExists (or DeployIfNotExists with a managed identity for remediation) to flag resources that are not yet “onboarded” (for example, missing tag KeyVaultOnboarded=true). Policy will give you a near-real time compliance inventory.
- Periodically (daily/weekly) re-run Resource Graph + Policy compliance to find new or missed resources; export to a queue/CSV for remediation. (Resource Graph is fast and suitable for large inventories.)
- How to automatically ingest / onboard keys when a resource is created
- Subscribe to Event Grid for
Microsoft.Resources.ResourceWriteSuccessevents at subscription or resource-group scope. Filter to only resource types in your mapping. This captures new resources (and updates). - Event Grid forwards the event to an Azure Function / Logic App (managed identity). The function should:
- Parse the event → resourceId & type.
- Check Azure Policy / tags to skip if already onboarded.
- Use your mapping to call the service’s List Keys API (or CLI) to fetch the current key(s). For example, Cosmos DB:
listKeysREST; Storage:listKeysor portal/CLI. - Store each key as a Key Vault secret (
/<resourceName>/key1,/<resourceName>/key2) and tag the resourceKeyVaultOnboarded=true.(Use Key Vault secret versioning for audit/history.)
- If some services don’t expose
listKeyson creation or require extra steps (private preview or role), have the function enqueue the resource for a remediation run (ARM deployment script or human review). Document these exceptions in your mapping. - Add a smoke-test: after writing secret to Key Vault, the function attempts a minimal auth call to the service using the stored secret to confirm it works (optional but recommended). If the test fails, raise an alert and mark resource for manual remediation.
- Subscribe to Event Grid for
- How to understand and implement grace period / rotation behaviour safely
- Assume service-specific behaviour — test it. Do not assume a universal grace period. For each service in your mapping, create a short test plan: regenerate key A and immediately attempt to use the old key; record whether it still works and for how long. Document results. (Storage, Cosmos DB, etc. have documented regenerate APIs; behaviour differs.)
- Prefer the two-key (primary/secondary) swap pattern where available:
- Step A: Ensure apps can read both keys from Key Vault (or switch to secondary).
- Step B: Regenerate secondary (key2) via API → update Key Vault secret for key2.
- Step C: Switch applications to key2 (update config to use new secret version).
- Step D: Regenerate key1. This provides zero-downtime if the service supports two keys.
- For services with one credential or immediate invalidation: coordinate rotation with application owners and plan a short maintenance window — or use a sidecar/feature-flag to quickly swap credentials. Treat these as higher-risk and test thoroughly.
- Automate verification after rotation: after your rotation run (Logic App/Function):
- Confirm
regenerateKeyreturned success, - update Key Vault secret,
- trigger Key Vault secret event and have dependent apps re-read the secret,
- perform a health check using the new secret. If health check fails, rollback by switching app to previous secret version (if service supports it) or alert operator.
- Confirm
- Record timelines & audit: log old/new secret versions, timestamps, who/what performed rotation; surface in Azure Monitor / Workbook for compliance (rotation older than X days). Use Policy to enforce rotation cadence where possible. I hope the provided answer is helpful,
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.
Thanks