The Simplest Way to Make Cosmosdb and GCP Secret Manager Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use cosmosdb and gcp secret manager to run apps on Google Cloud with Azure data. The secret store holds the database key so workloads can read and write records. Many teams split their stack across two cloud providers. Compute nodes run in Google Cloud while Azure hosts the globally distributed database. This setup needs a clean way to store and read database keys. Hardcoding keys in source code creates huge security risks for any team. Storing those keys in a central vault fixes that ini

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.

Teams use cosmosdb and gcp secret manager to run apps on Google Cloud with Azure data. The secret store holds the database key so workloads can read and write records.

Many teams split their stack across two cloud providers. Compute nodes run in Google Cloud while Azure hosts the globally distributed database. This setup needs a clean way to store and read database keys. Hardcoding keys in source code creates huge security risks for any team. Storing those keys in a central vault fixes that initial problem.

How cosmosdb and gcp secret manager share keys and data

The workflow starts when you create a database account in Azure. Azure generates primary and secondary keys along with full database strings. An admin copies the secondary key and saves it into the Google secret store. Each secret version gets a unique number and stays encrypted at rest.

Next, you set up an identity role for your Google Cloud workload. That role needs permission to read the specific secret version you just saved. When the app starts up, it asks the Google API for the secret payload. The app then uses that string to log in to the Azure database.

From there, data flows over the network between the two cloud regions. The app sends queries and writes new items to the database containers. You should turn on audit logs in both clouds right away. Google logs every secret read event, while Azure logs control plane changes.

Common failure modes and how to scope roles

Several problems show up when teams scale this setup across many developers. First, shared master keys give every app full admin power over the database. One bad query can wipe out whole containers or leak private records. Second, human engineers often pull the same secret to run local debug queries. Once a key sits on a laptop, you lose track of who runs what.

Key rotation also breaks apps when teams do not plan ahead. If you change the key in Azure first, running apps fail right away. You must update the secondary key in Azure and add a new secret version. Then you let apps pick up the new version before resetting the primary key.

GCP Secret Manager + CosmosDB RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix broad permissions, stop using master keys for every single task. Set up data plane roles in Azure that only allow reading specific containers. In Google Cloud, give each service account access to one secret only. Never grant project-wide secret read roles to your compute nodes or users.

Network rules also need tight limits between the two cloud providers. Do not leave the Azure database open to all public internet traffic. Lock down the database firewall so it only accepts traffic from known Google egress IPs. You should also mask sensitive fields like emails, phone numbers, and card numbers in query results.

How to audit human database sessions

Apps are easy to lock down, but human access remains a tough gap. Engineers need to check production records during outages or fix broken data entries. Giving them the raw secret from Google Cloud creates a huge blind spot. Azure logs will show the master key logged in, not the specific person.

Teams should separate human database sessions from automated app workloads. Map every engineer to their own corporate login before they run any query. Log every read and write command with a clear timestamp and user name. Rewrite matched fields like national IDs in results to keep private data safe.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

How do we rotate keys without app downtime?

Azure gives you two keys for each database account. Put the secondary key into a new secret version while apps use the primary key. Once all apps read the new version, regenerate the old key in Azure.

Can we avoid static keys between Google Cloud and Azure?

Yes, you can set up workload identity federation between the two cloud providers. Your Google service account gets a token that Azure trusts for database roles. Many teams still store fallback keys in the secret store for legacy tools.

What is the safest way for developers to query CosmosDB?

Do not let developers read raw database keys from the Google secret store. Route human queries through a system that checks their identity and logs every action. This keeps static keys off laptops and applies data masking to sensitive fields.

The query runs. The emails stay hidden.