All posts

Audit logging for autonomous agents on Postgres

Autonomous agents that can run SQL against production databases without audit logging are a ticking time bomb. In many organizations the first step to automate data‑driven workflows is to hand a service account or a static password to a bot and let it connect directly to PostgreSQL. The bot talks straight to the database over the usual client libraries, and the only record of its activity is whatever the database writes to its own log files – often at a coarse level, without context about who o

Free White Paper

K8s Audit Logging + Single Sign-On (SSO): The Complete Guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free. No spam. Unsubscribe anytime.

Autonomous agents that can run SQL against production databases without audit logging are a ticking time bomb.

In many organizations the first step to automate data‑driven workflows is to hand a service account or a static password to a bot and let it connect directly to PostgreSQL. The bot talks straight to the database over the usual client libraries, and the only record of its activity is whatever the database writes to its own log files – often at a coarse level, without context about who or what triggered the query. When a breach occurs, teams scramble to piece together which statements were issued, whether sensitive rows were exposed, and who authorized the access. The lack of granular, immutable evidence makes forensic analysis slow and incomplete.

Even when teams adopt better identity practices – provisioning a dedicated service account, using OIDC‑based tokens, and limiting the role’s privileges – the request still travels unmediated to the PostgreSQL server. The gateway that sits between the agent and the database remains invisible, so there is no place to enforce inline data masking, block dangerous statements, or require a human approval before a high‑risk query runs. The connection is still a black box: it carries the right identity, but it offers no audit logging, no real‑time visibility, and no way to intervene if the agent behaves unexpectedly.

To close that gap, the control point must move from the database itself to the data path, the network hop that all traffic must traverse before reaching PostgreSQL. By inserting a Layer 7 proxy that can inspect the wire‑protocol, organizations gain a single enforcement surface where every statement can be captured, examined, and acted upon. That proxy becomes the authoritative source of truth for who did what, when, and with which data.

hoop.dev fulfills exactly that role. It runs a gateway next to the PostgreSQL instance and presents itself as the target host to any client. When an autonomous agent initiates a connection, hoop.dev validates the agent’s OIDC or SAML token, extracts group membership, and maps that to a just‑in‑time, least‑privilege scope. The gateway then forwards the traffic to the real database using credentials that are stored only inside the gateway – the agent never sees the password or IAM token. While the session is active, hoop.dev records every SQL statement at the command level, timestamps each query, and stores the full request‑response pair for later replay. Because the proxy sits in the data path, it can also mask columns that contain personally identifiable information, block statements that attempt to drop tables, or pause execution pending a manual approval.

Continue reading? Get the full guide.

K8s Audit Logging + Single Sign-On (SSO): Architecture Patterns & Best Practices

Free. No spam. Unsubscribe anytime.

This architecture delivers several concrete benefits. First, audit logging becomes exhaustive: every SELECT, INSERT, UPDATE, or DELETE issued by an autonomous agent is captured with full context, satisfying compliance frameworks that require query‑level evidence. Second, the logs are retained centrally, making them available for investigations. Third, inline masking ensures that even if a bot is compromised, any downstream consumer only sees redacted data, reducing the blast radius of a breach. Finally, because the gateway can enforce guardrails in real time, risky commands never reach the database unchecked, preventing accidental data loss or privilege escalation.

Deploying this capability starts with provisioning the hoop.dev gateway, which can be run via Docker Compose for a quick trial or installed in Kubernetes for production workloads. The gateway’s agent runs on the same network segment as the PostgreSQL server, guaranteeing low latency and reliable connectivity. After connecting the gateway to an identity provider – such as Okta, Azure AD, or Google Workspace – you define a PostgreSQL connection in the hoop.dev console, supplying the host, port, and the database credentials that the gateway will use. From that point forward, any client (including autonomous agents) points its standard PostgreSQL client at the hoop.dev host instead of the database directly. The rest of the workflow – defining which groups can query which schemas, configuring masking rules, and setting up approval policies – is covered in the official getting‑started guide and the detailed feature documentation.

Once the gateway is live, you can verify that audit logging is active by reviewing the session logs in the hoop.dev UI or exporting them to your SIEM of choice. The logs include the full SQL text, the identity of the caller, timestamps, and any masking actions applied. This evidence can be fed directly into audit reports for standards such as SOC 2, providing the concrete proof auditors look for.

Explore the open‑source repository to get the code and contribute

Why audit logging matters for autonomous agents

Autonomous agents operate without human supervision, which makes it essential to have a reliable record of every database interaction. Without query‑level logs, a compromised agent could exfiltrate data, modify records, or delete tables without leaving a clear trail. Detailed audit logging enables rapid detection of anomalous patterns, supports forensic investigations, and satisfies regulatory requirements that demand visibility into who accessed what data and when.

How hoop.dev provides audit logging for Postgres

hoop.dev acts as a native wire‑protocol proxy for PostgreSQL. It authenticates callers via OIDC/SAML, maps their identity to a scoped role, and then forwards the request using credentials stored only inside the gateway. While the traffic passes through, hoop.dev records each statement, captures the full response, and applies any configured masking or guardrails before the data reaches the client. Because the proxy sits in the data path, every query is logged regardless of the client or the agent that issued it.

Getting started with audit logging on Postgres

Begin by reviewing the getting‑started guide to spin up the gateway in a test environment. Follow the steps to connect the gateway to your identity provider, register a PostgreSQL connection, and define the groups that are allowed to query the database. The learn section contains deeper explanations of masking rules, approval workflows, and session replay. After deployment, monitor the session logs in the UI to confirm that every statement is captured.

FAQ

  • Do I need to modify my existing PostgreSQL client code? No. The client continues to use the standard PostgreSQL protocol; you only change the host and port to point at the hoop.dev gateway.
  • Can I export the audit logs to an external SIEM? Yes. hoop.dev provides export capabilities that can stream logs to popular SIEM platforms or object storage for long‑term retention.
  • Will masking affect query performance? Masking is performed inline as the response passes through the gateway. In practice the overhead is minimal, and the security benefit outweighs the slight latency.
Open source

Save the open-source gateway for agent data access

Hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.

Star and save the repo →More posts