How to Configure Cosmos DB Rotate Password

Published
Length
3 min read

Luis Felipe Dias

All posts

To run a cosmos db rotate password workflow, teams swap between primary and secondary account keys. You update apps to use the secondary key, then regenerate the primary key in Azure. Most teams run this rotation on a set schedule to limit key exposure. Yet shared account keys still grant broad read and write power to every user. One leaked key gives an attacker full control over your database containers and items. How the native cosmos db rotate password workflow operates Azure Cosmos DB use

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To run a cosmos db rotate password workflow, teams swap between primary and secondary account keys. You update apps to use the secondary key, then regenerate the primary key in Azure. Most teams run this rotation on a set schedule to limit key exposure. Yet shared account keys still grant broad read and write power to every user. One leaked key gives an attacker full control over your database containers and items.

How the native cosmos db rotate password workflow operates

Azure Cosmos DB uses master keys instead of standard user passwords for account logins. Each database account comes with two active keys at all times. You get one primary key and one secondary key for full access. You also get a separate pair of keys for read-only tasks. This dual-key design lets you rotate secrets without causing app downtime.

The rotation process follows four plain steps across your cloud setup. First, you find every app and script that uses the primary key. Second, you change those apps to read the secondary key from your secret store. Third, you ask Azure to make a new primary key for the account. Fourth, you update your secret store with the fresh primary key for next time.

Many teams store these keys in Azure Key Vault to speed up the swap. A scheduled job can trigger the key change and save the new value. Your apps still must reload the secret from the vault to keep working. If an app caches the old key in memory, its database calls will fail. Engineers who save keys in local files also get locked out during a swap.

What key rotation solves and what it leaves open

Rotating keys on a schedule shrinks the time window for a stolen secret. If an old key leaks in a code repo, it stops working soon. Audits also require regular secret changes to pass basic security checks. Dual keys help your apps stay online while you replace old secrets.

Still, key rotation only controls how long a secret stays valid. It does not control what a person or app does after logging in. A fresh master key still holds full admin rights over every data container. Anyone with the current key can delete items or drop whole containers.

Shared keys also ruin your audit logs during an incident review. When five engineers use the same primary key, every query looks the same. You cannot tell which team member ran a bad write command. Moving to role-based rules helps, yet roles still allow broad query patterns.

Application-to-Application Password Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native key rotation also fails to inspect the data inside query results. A valid user can run a broad read query and pull sensitive rows. The database returns raw emails, phone numbers, card numbers, and national IDs in plain text. Data masking is needed to rewrite matched fields in results before they leave.

Managing human and tool sessions during rotation

App servers handle key swaps well when they poll a secret store often. Human users and local scripts cause the most pain during a rotation cycle. Developers often copy account keys into database tools on their laptops. When the team rotates the key, all those local setups break at once.

To avoid this friction, teams often delay rotation or share new keys in chat. Sharing fresh keys in chat defeats the whole point of rotating them. A better plan removes raw account keys from developer laptops and scripts. Teams need a way to check every command and mask sensitive fields in flight.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does Azure Cosmos DB use standard passwords or account keys?

Azure Cosmos DB uses primary and secondary account keys instead of standard text passwords. You can also set up role-based access with Microsoft Entra ID for identity logins.

How do you rotate Cosmos DB keys without app downtime?

Switch all running apps to use the secondary account key first. Once traffic leaves the primary key, regenerate the primary key in your cloud portal.

Why is key rotation not enough for database security?

Key rotation only invalidates old secrets after a set time period. An active key still allows broad queries and exposes raw emails or card numbers.

The query runs. The emails stay hidden.