How to Configure n8n CockroachDB Audit Log
You set up an n8n cockroachdb audit log by turning on database logging for your workflow user. Then your database records every query that n8n runs during a task. Teams often attach a shared database role to their n8n nodes. This role lets workflows and AI agents read and write tables. When that role has broad permissions, one bad prompt can read sensitive rows or drop data. How an n8n cockroachdb audit log works in practice In n8n, workflows run queries through database nodes or AI agent too
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 an n8n cockroachdb audit log by turning on database logging for your workflow user. Then your database records every query that n8n runs during a task. Teams often attach a shared database role to their n8n nodes. This role lets workflows and AI agents read and write tables. When that role has broad permissions, one bad prompt can read sensitive rows or drop data.
How an n8n cockroachdb audit log works in practice
In n8n, workflows run queries through database nodes or AI agent tool sub-nodes. The n8n AI Agent node pairs a chat model with one or more tools. The agent decides which tools to call to finish a task. You must attach at least one tool sub-node to an AI Agent node. For SQL tasks, n8n docs say to use a Postgres or MySQL tool sub-node. Since CockroachDB speaks the Postgres wire protocol, teams use the Postgres tool sub-node here. You can also attach a Custom Code Tool, an HTTP Request Tool, or a Call n8n Workflow Tool.
On the database side, CockroachDB logs SQL events based on the database role or table rules. When n8n logs in with its assigned role, the database starts a session. Each time an n8n workflow or AI agent sends a query, the database checks the role. It runs the SQL statement and writes an entry to its log files. That entry shows the database user, the timestamp, and the query text. Security teams then ship these log files to a central log store for review.
What native database logging solves and what it leaves open
Native database logging gives you a record of every SQL query that hit the cluster. If a table changes, you can check the log to see the exact statement. You can also see when the query ran and which database role ran it. This helps teams investigate incidents and pass basic security checks.
Still, native setup rules only check who logs in at the start of a session. They do not inspect what individual statements do while they run in flight. All n8n workflows and AI agents often share one static database user. Because of this, the database log only shows that single service account name. You cannot tell which specific n8n user or workflow triggered the query. Also, an audit log only records damage after the query finishes. It does not block a risky drop statement or wait for a human to approve it. Finally, logs do not mask sensitive data like emails, phone numbers, card numbers, or national IDs. If an AI agent pulls customer rows, those raw values flow straight into the chat model.
Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing AI agent queries and shared credentials
This gap grows wider when you build AI agents in n8n. From n8n 1.82.0, the old agent type setting is deprecated. Every AI Agent node now runs as a Tools Agent. Node version 1 is removed in n8n 3.0. In this setup, the chat model writes and runs SQL queries on its own. It converts natural language questions into SQL and runs them through the Postgres tool sub-node.
If you store a high-privilege database key inside n8n, every tool call uses that power. A prompt injection or a model mistake can ask for full tables of customer card numbers. The native database log will record the select query after the fact. By that time, the raw data is already inside the n8n execution history and model context. Teams need a way to check queries before they run and rewrite sensitive fields in results.
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 runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
How does n8n connect to CockroachDB for AI agent workflows?
You attach a Postgres tool sub-node to the n8n AI Agent node. Because CockroachDB uses the Postgres protocol, the agent sends SQL queries through this standard sub-node.
Why do native CockroachDB logs miss the real n8n user identity?
Workflows usually log in to the database with one shared service account. The database only sees that shared role name, not the person or webhook that started the workflow.
Can native database audit logs stop an AI agent from reading sensitive fields?
No, an audit log only records queries that already ran. To protect emails, phone numbers, card numbers, or national IDs, you need data masking that rewrites results in flight.
Related guides
In this post