An offboarded contractor leaves behind a CI job that runs an AI coding agent, creating a prompt-injection risk. The agent keeps generating SQL snippets based on vague prompts and pushes them straight to the production Postgres cluster. Because the job uses a long‑lived service account credential, the queries execute with full read‑write rights, and no human ever sees the generated statements.
That pattern is becoming common: teams hand a language model access to a database so it can autocomplete queries, refactor schemas, or even write migration scripts. The appeal is obvious, speed, fewer manual errors, and a perception that the model will only produce safe code. In practice the model can be coaxed into emitting statements that leak data, drop tables, or exfiltrate credentials, all under the guise of a legitimate request.
Current practice with AI coding agents and Postgres
Most organizations treat the AI agent like any other application. They create a dedicated database user, store the password in a secret manager, and let the agent connect with a standard client library. The connection is direct, meaning the traffic travels from the agent process straight to the Postgres port. Auditing is limited to the database’s own log, which records the final statement but not the prompt that produced it. Masking, approval workflows, or real‑time command blocking are rarely in place because they require additional infrastructure that teams consider optional.
Because the credential is static, any compromise of the CI runner or the secret store instantly grants the attacker the same level of access. The model itself can be tricked, prompt injection, by feeding it a crafted instruction that makes it reveal internal data or execute destructive commands. The database sees only the resulting SQL, so the root cause is hidden.
Why prompt‑injection risk remains unchecked
The core of the problem is that the enforcement point sits on the wrong side of the connection. Identity and token validation happen before the request reaches Postgres, but no policy engine examines the payload. The system therefore fixes credential distribution (the agent no longer needs a human‑centered password) yet leaves the request path wide open. Without a gateway that can inspect, approve, or redact the query, the following gaps persist:
- There is no real‑time audit of which prompt produced which statement.
- Sensitive result fields cannot be masked before they reach the agent.
- Dangerous commands cannot be blocked or routed for manual approval.
- Session replay is impossible because the raw traffic is never recorded.
All of these gaps disappear the moment a layer‑7 proxy sits between the AI agent and Postgres and enforces policy on each request.
