Every Cosmos DB account ships with a pair of standing read-write credentials: a primary and a secondary key. Each is a bearer secret that grants data-plane access to every database and container in the account. Until this week, if you regenerated one, you were guessing about who was still holding it. The honest rotation runbook at most shops was: regenerate the secondary key at 2am, watch the error dashboards, and keep a finger on the rollback.
Microsoft has now made Safe Key Rotation generally available, and the headline feature is modest and genuinely useful: a last-used timestamp surfaced per key. You can look at an account and see which keys have seen recent traffic before you touch anything. The blindfold comes off.
Good. But a last-used timestamp on a shared account key is a better flashlight in a room you shouldn’t be standing in. So let’s run the real comparison the feature invites, account keys with usage visibility versus disabling local auth and going keyless with Entra ID RBAC, and score it on the things that actually hurt when they go wrong.
One housekeeping note before the commands: everything in the code blocks below is representative. Azure CLI flag names and Bicep API versions drift between releases, and the GA announcement doesn’t publish the exact command surface for the new timestamp. Check az cosmosdb --help and the current CLI and resource-provider reference before you run any of it. I’m showing the shape of the operation, not guaranteeing the syntax against the version you have installed.
Round 1, Knowing what you’re about to break
This is the round the new feature exists to win, and against the old behaviour it wins cleanly. Before, you had no reliable signal that a given key was live. A key baked into a forgotten Logic App, a CI/CD variable group, or a contractor’s laptop looked identical to one nobody had touched in two years. Now the timestamp gives you a defensible answer to “is this safe to retire?”
One caveat the announcement does not resolve, and you should not pretend it does: Microsoft hasn’t spelled out precisely what counts as “usage.” Data-plane reads? Writes? Control-plane calls that list the keys? If a key was last used eleven months ago, that’s a strong retire signal. If it was used four minutes ago, you’ve learned something important. The grey zone in the middle, low-frequency batch jobs that run quarterly, is exactly where a timestamp will lull you into regenerating something that fires again next week.
Keyless sidesteps the question entirely. There is no key to time-stamp because there is no standing secret. Identities authenticate with short-lived Entra tokens, and you see the principal in the logs, not a last-used date on an anonymous blob.
Round to keyless, but only just, and only because it makes the question disappear rather than answers it better. If you’re staying on keys, this timestamp is the best thing that’s happened to the rotation runbook in years.
Round 2, Blast radius when the credential leaks
No contest. A Cosmos DB account key is account-wide and unscoped. One leaked primary key is full read/write to every container in the account, from any network path that can reach it, by anyone. There is no “scope this key to one database” option, a key is the whole account or nothing. The timestamp tells you a key is active; it tells you nothing about who copied it into a Postman collection that got committed to a public repo in 2024.
Entra RBAC on the data plane is scoped and assigned to a principal. You hand a managed identity a built-in data-plane role at a database or container scope, and that’s all it can do. Revocation is a role-assignment delete, not a global key regeneration that breaks everyone sharing the key.
Round to keyless. This is the one that gets you paged by your incident team, and keys lose it badly.
Round 3, Rollback safety during the change
Here’s where keys fight back, and it’s why the feature matters for teams that can’t move yet. The classic two-key dance is a genuinely safe pattern: clients run on the primary, you regenerate the secondary, confirm nothing broke, migrate clients to the now-fresh secondary, then regenerate the primary. The timestamp makes each step auditable, you can confirm the old key has gone quiet before you kill it instead of waiting out an arbitrary soak window.
Regeneration itself has no dry-run, there is no --what-if on a key regenerate, which is precisely why the timestamp is the closest thing you get to a pre-flight check. Treat the regenerate as state-changing and irreversible for the old secret:
Keyless rollback is different in character. There’s no swap; tokens refresh on their own. But a botched role-assignment change or a managed identity that loses its assignment fails closed and fast, and recovery is re-applying the assignment from your IaC. No coordinated two-phase migration across every consumer.
Round to keys, narrowly. The two-key pattern plus a real usage signal is a mature, well-understood rollback story, and the timestamp is what finally makes it evidence-based instead of superstition.
Round 4, Auditability six months later
A last-used timestamp is a single coarse number per key. It cannot tell you who used the key, from where, or for what. Four principals sharing one key produce one timestamp. When an auditor asks “which workloads authenticate with the secondary key,” the honest answer with keys is still “we think we know.”
Entra authentication writes per-principal activity you can actually query, and the identity in the log is the workload’s own managed identity, not a shared secret. That’s the difference between “a key was used” and “this function app read the orders container at 02:14.”
Round to keyless.
Round 5, Compatibility and operational cost
Keys win this one, and it’s the whole reason the loser is still on the board. Account keys work everywhere, with every SDK version, every third-party tool, and every API, NoSQL, MongoDB, Cassandra, Gremlin, Table. Entra ID data-plane RBAC does not have uniform coverage across all of those APIs and tooling, and some legacy SDKs and connectors simply expect a connection string. Going keyless can mean an SDK upgrade, code changes to use DefaultAzureCredential, and a provisioning story for identities that your platform team actually owns.
For a lot of estates, flipping local auth off is a multi-quarter migration, not a Tuesday. Until then, keys with a timestamp are what you’ve got, and they’re now less dangerous than they were.
Round to keys.
The verdict
Keyless takes it 3–2. For any new Cosmos DB account on the NoSQL API, there is no good reason to build on account keys. Provision with local auth disabled from day one, and enforce it so nobody re-enables it under deadline pressure. The property that controls this has historically been disableLocalAuth on the database account resource, confirm the current property name and pin a current stable API version rather than copying the one below verbatim:
Back it with policy. There is a built-in Azure Policy aimed squarely at Cosmos DB local authentication, if it’s present in your tenant, assign it at the management-group scope so new subscriptions inherit it. Run it in audit mode first to size the blast radius across your existing estate before you deny anything.
The one case where you pick the loser: an existing account on an API or SDK path where Entra data-plane RBAC isn’t a clean fit, or a third-party tool that only speaks connection strings. There, keys are the pragmatic answer, and this is where Safe Key Rotation earns its GA badge. Use the timestamp to retire stale keys you were previously afraid to touch, drive every consumer onto managed identities where you can, and shrink the number of live keys down toward zero.
Just don’t mistake a usage timestamp for a security control. It tells you whether a secret is live. It says nothing about whether it should exist. The fix for a credential you can’t fully account for isn’t better visibility into it, it’s not having it.
