How to Configure Cosmos DB Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a cosmos db audit log by routing cloud events to a storage workspace. You pick control plane and data plane events to track who runs database tasks. Many teams start by turning on broad logging for every database account. Still, broad roles and shared master keys hide the real person behind each action. When two engineers use one account key, the log shows the same shared identity. How the native cosmos db audit log works Cloud platforms split database activity into two main tracks

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.

You set up a cosmos db audit log by routing cloud events to a storage workspace. You pick control plane and data plane events to track who runs database tasks. Many teams start by turning on broad logging for every database account. Still, broad roles and shared master keys hide the real person behind each action. When two engineers use one account key, the log shows the same shared identity.

How the native cosmos db audit log works

Cloud platforms split database activity into two main tracks for logging. The control plane tracks changes to the database account itself. This includes creating containers, changing scale settings, or rotating account keys. The data plane tracks work inside the database containers. This includes reading items, writing documents, running queries, and deleting records.

To capture these events, admins link the database to a central log sink. You can send records to a log workspace, cold storage, or an event stream. Once you turn this on, the platform writes a record for every request. Each log entry shows the time, the request type, and the network source. If your team uses identity roles, the log also records the principal ID. If your team uses shared keys, the log only shows that key auth occurred. Admins then run queries over the workspace to review past actions and spot trends.

Choosing which database events to capture

Logging every single data plane read and write creates huge log volume. High traffic apps can make millions of document reads every single hour. Storing all those log records in an analytics workspace raises cloud bills fast. Teams must balance security needs against their monthly storage budget.

Many teams log all control plane changes because those events are rare and important. For the data plane, they often filter logs to track only human user queries. Another common approach is sending raw data logs to cheap archive buckets. Teams then route only high-risk events to their fast search workspace. You should also set clear retention rules so old logs expire on schedule. Good log filtering keeps your search tools fast and keeps your storage costs low.

Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native logging solves and what it misses

Native platform logs are great for looking at past events after an incident. They help security teams prove that logging is active for audit checks. You can see when a container changed or when a spike in reads happened. If each engineer uses an individual cloud role, you can trace their past calls.

Still, native logs only record events after the database has already run them. A log cannot stop a bad delete command while it is in flight. Also, native logging takes some time to ingest and index new records. By the time an alert fires, the data is already gone or changed. Native logs also do not mask sensitive fields inside query results. If a record holds emails, phone numbers, card numbers, or national IDs, raw data returns. Masking tools are needed to rewrite matched fields in results before users see them. Finally, if apps or users share a master key, logs lose user attribution.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Does turning on database logging slow down live queries?

No, the cloud platform handles log shipping in the background outside your query path. Your app reads and writes run at normal speed while logs move to storage.

How can we see exact query text in our logs?

You must turn on full text query logging in your diagnostic settings. Keep in mind that raw query text may contain sensitive inputs from users.

Why do our audit logs show a blank user identity?

Logs show a blank identity when a client connects with a shared master key. Switch human users to individual identity roles so logs capture their real user ID.

The query runs. The emails stay hidden.