README
ΒΆ
FaultWall
The Agentic Data Firewall for PostgreSQL
Identity-aware SQL enforcement for AI agents. Block rogue queries before they hit your database.
Your AI agent has your database password. FaultWall makes sure that's safe.
Deterministic. No LLM in the loop. FaultWall uses the real PostgreSQL C parser (
pg_query_go) for static SQL analysis β no AI, no API keys, no probabilistic guessing. Every decision is auditable, reproducible, and adds under 1ms of latency.
Check what your agent's database user can do (30 seconds)
Run this against the database your agent uses. It prints what that login can actually do, using Postgres' own privilege checks (inherited role grants included).
curl -fsSL https://raw.githubusercontent.com/shreyasXV/faultwall/main/try.sh | FAULTWALL_NO_RUN=1 bash # installs to ~/.faultwall/bin, no sudo
~/.faultwall/bin/faultwall audit "$DATABASE_URL"
It checks:
- superuser, BYPASSRLS, CREATEROLE, CREATEDB, REPLICATION, and membership in
pg_read_server_files,pg_write_server_files,pg_execute_server_program,pg_read_all_data,pg_write_all_data - per table: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, ownership (owner can ALTER/DROP), and whether RLS is on and applies to this role
- secret-looking columns it can SELECT (
password_hash,token,ssn,api_key...), including column-level grants - views it can read that pull from those columns
- functions it can EXECUTE that reach files, other servers or other sessions (
pg_read_file,lo_export,dblink*, andpg_terminate_backendwhen it haspg_signal_backend), COPY ... PROGRAM, and extensions likedblink,postgres_fdw,plpython3u - schemas it can CREATE objects in
Sample output, for a shared app_user:
Summary
app_user can DELETE on 42 of 43 tables, UPDATE 42, INSERT 42, TRUNCATE 42, and read 4 secret columns (users.password_hash, api_tokens.token, customers.ssn, +1 more).
Owns 40 (can ALTER/DROP). 1 view reads secret columns. 1 dangerous function executable (dblink*). RLS applies on 0 of 1 RLS tables.
Superuser: no. Bypasses RLS: no. Create role: no. Create DB: no. Replication: no.
Fixable with Postgres grants (enforced by Postgres)
- DELETE on 42 of 43 tables.
- Can SELECT 4 secret-looking columns: public.users.password_hash, public.api_tokens.token, ...
- Can read 1 view that reads secret-looking columns: public.user_logins (reads public.users.password_hash).
...
Not enforced by audit or Postgres grants (what the FaultWall proxy does today, and what is planned)
- Writes without a WHERE clause: app_user can UPDATE or DELETE every row of 42 tables in one statement. A grant can't require a WHERE. FaultWall proxy today, in enforce mode: the standard and strict profiles block UPDATE and DELETE without a WHERE.
- Row-count caps: FaultWall proxy today: max_rows limits the rows one statement returns. A cap on rows changed is planned, not in this release.
- Approval before a write: Planned in the FaultWall app, not in this release.
faultwall audit --fix prints SQL for a new per-agent role (fw_agent_<name>) that keeps the reads, leaves out secret columns with column-level grants, and has no writes unless you pass --writes orders,tickets. It only prints the SQL. It never runs it, and it never REVOKEs or ALTERs your existing users, so your app keeps working. It also lists what the new role still gets through PUBLIC (for example dblink or CREATE on schema public) so you can review those with your DBA. --role NAME checks another role, --json gives machine-readable output.
Read-only, nothing leaves your machine. The session is set to read-only and runs only catalog queries. There is no telemetry or update check, and no network call besides the one Postgres connection.
Works with every managed Postgres
| Deployment | Status |
|---|---|
| Self-hosted Postgres 12+ | π’ Green |
| AWS RDS Postgres 16 | π’ Green |
| AWS Aurora Postgres 16 | π’ Green |
| Neon (serverless Postgres 17) | π’ Green |
| PgBouncer (tx + session) | π’ Green |
| Supabase pooler | π‘ Yellow (workaround) |
| Cloud SQL Β· CrunchyBridge Β· DO MPG | π’ Expected ΒΉ |
ΒΉ Same Postgres wire protocol as validated providers; tested path exists, instance not provisioned.
Overhead: +0.14ms per query / β15% TPS on cloud-latency paths (RDS benchmark). Zero code changes required in your agent. Stock Postgres driver, standard connection string.
β Full compatibility matrix + SCRAM config per provider Β· Attack suite results Β· Reproducible test harness
A prompt injection hides a DROP TABLE in a customer feedback comment. Your agent blindly executes it. The WAF sees nothing β it's a legitimate connection with valid credentials. The database sees a normal query from an authorized user.
FaultWall intercepts the query before it reaches PostgreSQL, parses the SQL, checks it against your policy, and blocks it:
π New connection: agent=cursor-ai/summarize-feedback
π’ [ALLOWED] agent=cursor-ai/summarize-feedback query=SELECT * FROM feedback LIMIT 100;
π΄ [BLOCKED] agent=cursor-ai/summarize-feedback reason=blocked_operation query=DROP TABLE users;
π΄ [BLOCKED] agent=rogue-bot/steal reason=agent_not_in_policy query=SELECT * FROM users;
π΄ [BLOCKED] agent=cursor-ai/summarize-feedback reason=blocked_function:pg_read_file query=SELECT pg_read_file('/etc/passwd');
Two Modes
π‘οΈ Proxy Mode (Enforce) β Recommended
FaultWall sits between your agent and PostgreSQL as an inline L7 proxy. Every SQL query is parsed and checked before it reaches the database. Blocked queries never execute.
- Intercepts 100% of queries (Simple + Extended Query Protocol)
- Parses SQL using the real PostgreSQL C parser (
pg_query_go) β deterministic, no LLM - Sub-1ms latency overhead per query
- Works with any Postgres client: psql, psycopg2, pgx, SQLAlchemy, JDBC
- Fail-closed on internal errors: if a policy check fails, that query is refused and the session stays usable
./faultwall --proxy --listen :5433 --upstream localhost:5432 --policies ./policies.yaml
Agents connect to port 5433 instead of 5432. That's the only change.
Watch-only first? Add --mode monitor (or set POLICY_ENFORCEMENT=monitor): same parsing and logging, violations are recorded as monitored, nothing is blocked.
The SQL proxy runs without a management token. To use the local dashboard,
policy API, or local approvals, set FAULTWALL_API_TOKEN in the operator's
environment before starting it; see operator access.
π Monitor Mode (Sidecar)
FaultWall connects to your database as a read-only sidecar, polls pg_stat_activity, and logs violations. Good for visibility without being in the data path.
- Dashboard with agent activity, violations, cost attribution
- Anomaly detection and alerting
- Slack notifications
- No query blocking (observe only)
DATABASE_URL="postgres://user:pass@localhost:5432/mydb" \
POLICY_FILE=./policies.yaml \
./faultwall
Try it in 60 seconds (no YAML)
First choose a long random management token in your password manager. In an operator-only Bash shell, paste it at the prompt below; input is hidden. Keep this shell and token separate from your agent's environment.
read -r -s -p "Operator management token: " FAULTWALL_API_TOKEN
printf '\n'
export FAULTWALL_API_TOKEN
# Demo: bundled Postgres + two scripted agents, live view at http://localhost:8080
curl -fsSL https://app.faultwall.com/try.sh | bash
# Your database (monitor mode: observes and flags, never blocks)
curl -fsSL https://app.faultwall.com/try.sh | bash -s -- "postgres://user:pass@host:5432/db"
The browser asks for username faultwall and your management token as the
password. This is separate from the control-plane enrollment --token.
Without FAULTWALL_API_TOKEN, the SQL proxy still runs, but the local UI and
management API return 503; only GET/HEAD /api/health stay public.
No anonymous read-only UI is provided because its queries, policies, and
connection details are sensitive.
It prints a connection string to give your agent (postgres://β¦@localhost:5433/db?application_name=agent:my-agent:mission:default)
and opens a live view of every query, per agent, with what FaultWall would have flagged:
- DDL / DCL (
CREATE,ALTER,DROP,TRUNCATE,GRANTβ¦) UPDATE/DELETEwith noWHEREclause- writes that touch more than 100 rows
- reads of secret-looking columns (
password,token,secret,ssn,api_keyβ¦) - dangerous server functions (
pg_read_file,dblink,lo_exportβ¦)
Already installed? With the same operator environment, run
faultwall try [postgres://β¦]. With Docker:
docker run --rm -it \
-e FAULTWALL_API_TOKEN -e BIND_ADDR=0.0.0.0 \
-p 127.0.0.1:5433:5433 -p 127.0.0.1:8080:8080 \
ghcr.io/shreyasxv/faultwall try "postgres://user:pass@host.docker.internal:5432/db"
Management defaults to 127.0.0.1, including inside containers, independently
of the SQL --listen address. Docker port publication alone cannot reach a
container's loopback listener. The example explicitly binds management to the
container interfaces and publishes it only on the host's loopback address;
the token remains required. Use a tunnel to open a remote
host's dashboard.
Name your agent. Keep application_name=agent:<name>:mission:<task> on whatever connection string your agent uses, or its queries show up as unknown. Most drivers take it as a URL param or a keyword:
psycopg.connect(url, application_name="agent:support-bot:mission:triage") # psycopg 3 / psycopg2
create_engine(url, connect_args={"application_name": "agent:support-bot:mission:triage"}) # SQLAlchemy
await asyncpg.connect(url, server_settings={"application_name": "agent:support-bot:mission:triage"})
Tested through faultwall try with psql, pgx, psycopg 3 (simple, prepared, pipeline, async, COPY), psycopg2, SQLAlchemy, asyncpg and node-pg.
When you're ready to block, write a policy (below) and run in proxy mode.
Quick Start (5 minutes)
Step 1: Install
git clone https://github.com/shreyasXV/faultwall && cd faultwall
go build -o faultwall .
Or use Docker:
docker pull ghcr.io/shreyasxv/faultwall:latest
Step 2: Write your policy
Create policies.yaml:
default_policy: deny
# Dangerous PostgreSQL functions blocked for ALL agents
blocked_functions:
- pg_read_file
- pg_read_binary_file
- pg_ls_dir
- pg_execute_server_program
- lo_export
- lo_import
- dblink
- dblink_exec
- pg_terminate_backend
- pg_cancel_backend
- pg_reload_conf
- pg_sleep
- set_config
agents:
cursor-ai:
description: "Cursor IDE agent"
profile: standard # use a security profile
blocked_tables: [public.users, public.payments]
missions:
summarize-feedback:
tables: [public.feedback, public.products]
langchain-agent:
description: "LangChain research agent"
blocked_operations: [DROP, TRUNCATE, ALTER, GRANT] # legacy mode still works
missions:
analyze-trends:
tables: [public.orders, public.products]
unidentified:
policy: deny # deny | monitor | allow
Step 3: Run FaultWall (Proxy Mode)
POLICY_ENFORCEMENT=enforce \
./faultwall --proxy --listen :5433 --upstream localhost:5432 --policies ./policies.yaml
Step 4: Point your agents at FaultWall
Change the connection port from 5432 to 5433:
Python (psycopg2):
conn = psycopg2.connect(
host="localhost", port=5433, dbname="mydb", user="myuser",
application_name="agent:cursor-ai:mission:summarize-feedback"
)
Node.js (pg):
const client = new Client({
host: "localhost", port: 5433, database: "mydb", user: "myuser",
application_name: "agent:cursor-ai:mission:summarize-feedback"
});
Go (pgx):
conn, err := pgx.Connect(ctx, "postgres://myuser@localhost:5433/mydb?application_name=agent:cursor-ai:mission:summarize-feedback")
psql:
psql "host=localhost port=5433 user=myuser dbname=mydb application_name=agent:cursor-ai:mission:summarize-feedback"
Step 5: Verify
# This should work (agent has access to feedback table):
psql "host=localhost port=5433 ... application_name=agent:cursor-ai:mission:summarize-feedback" \
-c "SELECT * FROM feedback LIMIT 5;"
# This should be BLOCKED:
psql "host=localhost port=5433 ... application_name=agent:cursor-ai:mission:summarize-feedback" \
-c "DROP TABLE users;"
# ERROR: [BLOCKED by FaultWall] blocked_operation (op: DROP)
How It Works
Proxy Mode Architecture
βββββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β AI Agent ββββββΆβ FaultWall ββββββΆβ PostgreSQL β
β (port 5433) β β L7 Proxy β β (port 5432) β
βββββββββββββββββββ ββββββββ¬ββββββββ ββββββββββββββββ
β
ββββββββββββ΄βββββββββββ
β For each query: β
β 1. Parse SQL (AST) β
β 2. Check policy β
β 3. Allow or Block β
βββββββββββββββββββββββ
- Agent connects to FaultWall on port 5433
- FaultWall reads the startup message, extracts
application_namefor agent identity - Auth handshake is relayed to upstream PostgreSQL
- Every query (Simple or Extended protocol) is intercepted:
- SQL is parsed into an AST using
pg_query_go/v6(the real PostgreSQL C parser) - AST is checked against the agent's policy: operation type, tables, functions
- Allowed β query is forwarded to PostgreSQL, response relayed back
- Blocked β PostgreSQL never sees it. Client gets
ERROR: [BLOCKED by FaultWall] reason
- SQL is parsed into an AST using
- All other wire protocol messages are forwarded transparently
Agent Identity
Agents identify themselves via PostgreSQL's application_name parameter:
agent:<agent_id>:mission:<mission_id>
This is set in the connection string β no code changes beyond the connection config. FaultWall reads it from the startup packet at connect time.
Per-agent keys (managed from the control plane)
Agents created on the control plane's Agents page get their own key. The agent connects with postgresql://<agent-name>:<key>@<proxy>/<db>, and the proxy logs in to Postgres with its own credentials (FW_UPSTREAM_USER / FW_UPSTREAM_PASSWORD), so the agent never holds the real database password.
The agent authenticates to the proxy with SCRAM-SHA-256, the same challenge-response Postgres uses: the key is never sent over the wire, and neither the control plane nor the proxy stores it (only a salted SCRAM verifier). Any driver that supports password_encryption=scram-sha-256 works unchanged (psql, psycopg 2/3, pgx, asyncpg, node-pg, JDBC). A wrong or revoked key is refused with 28P01 before any upstream connection is opened. Keys created before SCRAM support are refused until re-created, unless you set FW_ALLOW_CLEARTEXT_KEY=1 on the proxy.
Revoking a key on the Agents page also ends that agent's open sessions on the proxy's next sync (FATAL agent key revoked), not just new connections.
Per-agent database role (db_role). On the Agents page you can give an agent a Postgres role. Right after the proxy logs in upstream, and before the agent can send anything, the proxy runs SET SESSION ROLE "<db_role>". From then on Postgres enforces that role's grants itself: with a SELECT-only role, an UPDATE fails with Postgres' own 42501 permission denied, even if a FaultWall rule were wrong. The agent can't switch back. SET ROLE, RESET ROLE, SET SESSION AUTHORIZATION, RESET ALL, DISCARD ALL and set_config('role', ...) are refused with 42501 [BLOCKED by FaultWall] agent role is fixed, over both the simple and extended protocol, and the connection stays open. If the role doesn't exist or isn't granted to the proxy's login, the connection gets a FATAL that says so. Changing or clearing an agent's role ends its open sessions, so reconnects pick up the new role. Leave db_role empty for "ask first" agents: an approved write still needs write grants. See Make the proxy the only path to the database for the SQL.
What Gets Checked
| Check | Example |
|---|---|
| Blocked operations | DROP, TRUNCATE, DELETE |
| Blocked tables | public.users, public.payments |
| Mission scope | Agent can only access feedback and products tables during this mission |
| Blocked functions | pg_read_file, dblink, lo_export (17 dangerous functions blocked by default) |
| Unknown agents | Agents not in the policy file are denied (when default_policy: deny) |
| Unidentified connections | Connections without agent: prefix are denied/monitored per config |
Query Protocols Supported
| Protocol | Coverage | Used By |
|---|---|---|
Simple Query (Q message) |
β Full inspection | psql, basic clients |
Extended Query (Parse/Bind/Execute) |
β Full inspection | psycopg2, pgx, SQLAlchemy, JDBC, all ORMs |
Monitor Mode (Sidecar)
For teams that want visibility without putting a proxy in the data path:
DATABASE_URL="postgres://user:pass@localhost:5432/mydb" \
POLICY_FILE=./policies.yaml \
POLICY_ENFORCEMENT=monitor \
./faultwall
Features:
- π Real-time dashboard on port 8080
- π Anomaly detection (genetic algorithm-tuned baselines)
- β‘ Auto-throttling (kill runaway queries)
- π° Cost attribution per tenant/agent
- π€ MCP server for AI agent self-monitoring
- π¨ Slack alerting
Limitation: Monitor mode polls pg_stat_activity every 10 seconds. Queries that complete faster than 10 seconds may not be detected. Use Proxy Mode for guaranteed enforcement.
Dashboard
Available in both modes at http://localhost:8080 when FAULTWALL_API_TOKEN
is configured:
| Panel | What you see |
|---|---|
| Agent Connections | Active agents, missions, connection status |
| Violations | Blocked queries with agent, table, reason |
| Tenant Leaderboard | Ranked by queries, latency, cost |
| Cost Attribution | Per-agent/tenant cost breakdowns |
| Anomalies | Statistical deviations from baseline |
| Predictions | Trend forecasts and breach warnings |
| APA Proposals | Policy changes the Autonomous Policy Agent proposes for review |
Operator access
All local management routes require the same operator token in proxy, monitor,
and try mode: query/history reads, policy downloads and changes, holds,
exports, and the dashboard itself. Set a long random FAULTWALL_API_TOKEN
in the proxy process's environment before startup. For an interactive Bash
session, paste a token from your password manager without echoing it:
read -r -s -p "Operator management token: " FAULTWALL_API_TOKEN
printf '\n'
export FAULTWALL_API_TOKEN
./faultwall --proxy --listen :5433 --upstream localhost:5432 --policies ./policies.yaml
Use username faultwall and that token as the password in the browser's login
prompt. API clients use Authorization: Bearer <token>:
curl -fsS -H "Authorization: Bearer $FAULTWALL_API_TOKEN" \
http://127.0.0.1:8080/api/holds
curl -fsS -X POST -H "Authorization: Bearer $FAULTWALL_API_TOKEN" \
http://127.0.0.1:8080/api/holds/HOLD_ID/approve
An absent/blank server token disables local management with 503. A missing or
incorrect client credential returns 401. The SQL data path and enrolled
control-plane approval path can still run without a local management token.
The public health endpoint returns only {"status":"ok"}. Restart the process
to change its management token.
Management binds to 127.0.0.1 by default; BIND_ADDR explicitly overrides it
in every mode, including try. Loopback access still requires authentication,
so an agent sharing the host cannot approve work without the token. Keep the
management credential, operator process environment, and Docker administration
access out of the agent's reach. Give agents only their intended agent
credentials.
For a remote browser, keep management on loopback and forward it over SSH:
ssh -N -L 127.0.0.1:18080:127.0.0.1:8080 operator@faultwall-host
# Open http://127.0.0.1:18080 on your workstation and use the same browser login.
Explicit remote API access needs a trusted tunnel or a TLS reverse proxy; do not expose the HTTP management listener directly to an untrusted network. Browser mutations require an exact matching Origin (scheme, host, and port) as well as the token. TLS termination in front of an HTTP backend does not satisfy that browser check: use the SSH tunnel for the browser, or Bearer authentication for API clients through TLS. Forwarded headers do not bypass the check. Browser credentials are cached by the browser; close its authenticated session when finished.
APA review: PR mode vs file-drop mode
The Autonomous Policy Agent (APA) watches observations and proposes policy
changes. It never edits your live policy in place. You choose how proposals are
reviewed, in the apa: section of policies.yaml:
apa:
enabled: true
provider: openai # openai | anthropic | litellm | fake
# PR mode: open a GitHub PR against a repo (needs the gh CLI).
policy_repo: myorg/faultwall-policies
# File-drop mode: no git required. APA writes a downloadable, apply-ready
# policies.yaml plus a diff, surfaced in the dashboard "APA Proposals" panel.
proposal_dir: ~/.faultwall
Set either or both. With no policy_repo, APA runs in file-drop mode by default
(proposals land in ~/.faultwall/proposals, or APA_PROPOSAL_DIR). Review them
in the dashboard: Download the proposed YAML, apply it yourself, then
POST /api/policies/reload (or restart). Endpoints:
GET /api/apa/proposals/filesβ list proposals (diff + metadata)GET /api/apa/proposals/files/{id}/downloadβ download the proposed policies.yamlPOST /api/apa/proposals/files/{id}/apply|/dismissβ mark status
Docker Compose
version: "3.8"
services:
postgres:
image: postgres:16
environment:
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
faultwall:
image: ghcr.io/shreyasxv/faultwall:latest
command: ["--proxy", "--listen", ":5433", "--upstream", "postgres:5432", "--policies", "/etc/faultwall/policies.yaml"]
environment:
POLICY_ENFORCEMENT: enforce
BIND_ADDR: "0.0.0.0" # container listener; host publication stays on loopback
FAULTWALL_API_TOKEN: "${FAULTWALL_API_TOKEN:?Set FAULTWALL_API_TOKEN in your operator shell}"
volumes:
- ./policies.yaml:/etc/faultwall/policies.yaml:ro
ports:
- "127.0.0.1:5433:5433"
- "127.0.0.1:8080:8080"
depends_on:
- postgres
# First export FAULTWALL_API_TOKEN in the operator shell as shown above.
docker compose up -d
# Agents connect to localhost:5433
# Operator opens localhost:8080 (username faultwall, password the management token).
This UI-enabled example requires the token explicitly and publishes management only on host loopback. For a headless proxy, omit the management token, bind override, and port 8080 publication; the SQL listener still runs. For a remote operator, use the SSH tunnel above.
Security Profiles
Security profiles let you pick a security posture instead of manually listing operations. Three built-in profiles are available:
| Profile | Posture | Blocked | Use Case |
|---|---|---|---|
permissive |
Log everything, block nothing | β | Visibility into agent behavior |
standard |
Block dangerous ops | DCL, ADMIN, EXTENSION, FUNCTION categories + COPY | Agents read/write data safely |
strict |
Allowlist only | Everything except SELECT, INSERT, UPDATE, DELETE, EXPLAIN, TRANSACTION | Basic CRUD only |
standard and strict also enforce "DELETE must include WHERE" and "UPDATE must include WHERE" conditions.
Using Profiles
agents:
my-agent:
profile: standard # pick a built-in profile
profile_overrides: # optional per-agent tweaks
allow: [COPY] # allow COPY even though standard blocks it
block: [DELETE] # block DELETE even though standard allows it
blocked_tables: [public.secrets] # table rules still apply on top
Custom Profiles
Define custom profiles in the profiles section:
profiles:
readonly:
extends: strict
allowed_operations: [SELECT, EXPLAIN]
Backward Compatibility
The existing blocked_operations field still works. If an agent has no profile, behavior is identical to before. If both profile and blocked_operations are set, the profile takes precedence.
Privacy: what leaves your box (control-plane telemetry)
Query values never leave your box. Table and column names do, so we can show you what each agent touched.
Telemetry is off unless the proxy is enrolled to a control plane (install.sh --token ... writes ~/.faultwall/config.toml, or set FAULTWALL_CONTROL_PLANE_URL + FAULTWALL_CONTROL_PLANE_TOKEN). Turn it all off with FAULTWALL_TELEMETRY=false or telemetry_enabled = false.
faultwall try follows the same rule. Enroll it with faultwall try --token <TOKEN> --control-plane https://api.faultwall.com [postgres://...] (try.sh passes both flags through), or use the same env / config file as --proxy. The startup banner's Events go to: line says where events are going. Without enrollment, try sends nothing.
When enrolled, each statement sends one event:
| Field | Example | Notes |
|---|---|---|
agent_id, mission |
support-agent, refunds |
from application_name=agent:<id>:mission:<m>. The :token: part is never sent. Connections without a name are sent as their raw application_name (or unknown) with agent_unnamed: true. |
op_type, table_name, tables |
UPDATE, orders |
names only |
rows_affected |
12 |
count from the CommandComplete tag. No row data. |
decision, flags, reasons |
allow, ["mass_write"] |
zero-config rules: DDL, UPDATE/DELETE without WHERE, writes over 100 rows, secret-column reads, dangerous server functions, policy violations |
fingerprint |
a1b2c3... |
pg_query structural hash. Literals don't change it. |
latency_ms, risk_score |
0.4, 0.12 |
decision latency, QWM score |
query_shape |
UPDATE orders SET status = ? WHERE id = ? |
gated, see below |
Never sent: raw query text, bound parameter values, literals, comments, row data, policy bodies, connection credentials.
Query shapes (FW_TELEMETRY_QUERY_SHAPE)
query_shape is the statement with every literal replaced by ? (strings, dollar-quoted bodies, numbers, booleans, $n params, E''/U&''/bit/hex constants) and every comment removed. It is built from the Postgres scanner's token stream (pg_query), not regexes. If a statement can't be tokenized, or anything quote-like survives, the shape is dropped and only the metadata above is sent. It is what makes the hosted feed say "support-agent ran UPDATE orders SET status = ? WHERE id = ? (12 rows)" instead of "UPDATE on orders".
| Setting | Effect |
|---|---|
| (unset) | on when enrolled (telemetryQueryShapeDefault in telemetry_client.go) |
FW_TELEMETRY_QUERY_SHAPE=off (or false/0) |
never send shapes |
FW_TELEMETRY_QUERY_SHAPE=on |
send shapes |
query_shape = false in [control_plane] |
same as off; the env var wins |
Identifiers stay in the shape: table, column and function names. If your schema names are themselves sensitive, set FW_TELEMETRY_QUERY_SHAPE=off.
Delivery: events are batched (200 per batch, every 2s) on a background goroutine. If the control plane is unreachable they are retried with exponential backoff (1s up to 60s, jittered), and up to 10,000 events are held in memory. Emitting never blocks a query; if the buffer is full the event is dropped.
Configuration
Proxy Mode
| Flag | Default | Description |
|---|---|---|
--proxy |
β | Enable proxy mode |
--mode enforce|monitor |
enforce |
monitor (or --monitor, or POLICY_ENFORCEMENT=monitor) observes and flags, never blocks. Flag beats env. |
--listen |
:5433 |
Proxy listen address |
--upstream |
localhost:5432 |
Upstream PostgreSQL address |
--policies |
./policies.yaml |
Policy file path |
| Env Var | Default | Description |
|---|---|---|
POLICY_ENFORCEMENT |
enforce |
enforce (block) or monitor (log only). Unknown values fall back to enforce. |
UPSTREAM_TLS |
false |
true = TLS to Postgres (SSLRequest), verified against system roots |
UPSTREAM_TLS_CA |
β | PEM CA bundle to verify Postgres with (e.g. the AWS RDS global bundle). Implies UPSTREAM_TLS=true |
UPSTREAM_TLS_SKIP_VERIFY |
false |
Encrypt without verifying the server. Testing only |
TLS_CERT_FILE / TLS_KEY_FILE |
β | Serve TLS to agents (also --tls-cert / --tls-key) |
FW_UPSTREAM_DATABASE |
database in DATABASE_URL |
The one database key-authenticated agents may open. * allows any |
Monitor Mode (Sidecar)
| Env Var | Default | Description |
|---|---|---|
DATABASE_URL |
(required) | PostgreSQL connection string |
PORT |
8080 |
Dashboard port |
POLICY_FILE |
./policies.yaml |
Policy file path |
POLICY_ENFORCEMENT |
monitor |
enforce or monitor |
SLACK_WEBHOOK_URL |
β | Slack webhook for alerts |
THROTTLE_ENABLED |
false |
Enable auto-throttling |
RDS_HOURLY_COST |
0.50 |
Hourly DB cost for attribution |
MCP Server (AI-Native)
FaultWall exposes an MCP server so AI agents can self-monitor:
{
"mcpServers": {
"faultwall": {
"command": "./faultwall",
"args": ["--mcp"],
"env": { "DATABASE_URL": "postgres://..." }
}
}
}
10 tools: list_tenants, get_tenant, get_noisy_tenants, get_costs, throttle_tenant, get_health, get_anomalies, get_predictions, and more.
Make the proxy the only path to the database
FaultWall can only enforce what goes through it. If an agent has any other route to the database, it bypasses FaultWall. After installing, close the other routes:
1. Rotate the database password so only the proxy knows it. Whatever password your agents (or their config, CI secrets, .env files) used before is now a way around the proxy. Set a new one and give it to the proxy only:
-- as an admin, on the real database
ALTER ROLE faultwall_proxy WITH PASSWORD 'a-new-long-random-password';
# on the FaultWall host only
FW_UPSTREAM_USER=faultwall_proxy FW_UPSTREAM_PASSWORD='a-new-long-random-password' faultwall --proxy ...
Agents connect with their FaultWall agent key (postgresql://<agent>:<fw_ak_...>@<proxy>/<db>), which Postgres rejects if it's tried directly. If agents used to share an application login, rotate that one too, or ALTER ROLE ... NOLOGIN it.
2. Allow network access to the database from the proxy host only.
-
Cloud (RDS, Cloud SQL, Azure, Supabase, Neon): restrict the database's security group / authorized networks / firewall to the FaultWall host's address (or its security group). Remove
0.0.0.0/0and any agent subnets. -
Self-managed: in
pg_hba.conf, accept the proxy's address and reject the rest, then reload:# TYPE DATABASE USER ADDRESS METHOD host all faultwall_proxy 10.0.1.20/32 scram-sha-256 # FaultWall host host all all 0.0.0.0/0 reject host all all ::/0 rejectKeep any admin or migration access on separate, named rules that agents can't use.
The proxy logs a startup hint about DB-port reachability (F9), and REAL-F9 flags sessions that reach the DB without going through it. These are hints, not proof. Verify the network rules yourself.
3. Give read-only agents a read-only database role. With a role set, Postgres rejects the agent's writes on its own, independent of FaultWall's rules. Create one NOLOGIN role per agent (or per access level), grant it only what the agent needs, and grant the role to the proxy's login so the proxy can switch to it:
-- read-only role for one agent
CREATE ROLE fw_ro_support_agent NOLOGIN;
GRANT USAGE ON SCHEMA public TO fw_ro_support_agent;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO fw_ro_support_agent;
-- tables created later (run as the role that creates them)
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO fw_ro_support_agent;
-- let the proxy's login switch to it
GRANT fw_ro_support_agent TO faultwall_proxy;
Then set the agent's Database role to fw_ro_support_agent on the Agents page. The page suggests fw_ro_<agent> when writes are blocked. Narrow the grants further (specific tables or columns instead of ALL TABLES) if the agent needs less. Don't do this for "ask first" agents, since approved writes need write grants. Two caveats. Keep the proxy's login (faultwall_proxy) a plain role, not a superuser, so the agent's role is the only source of its rights. And SECURITY DEFINER functions the role can execute still run with their owner's rights, so review those, or revoke EXECUTE from the role.
Known Limitations & Hard Requirements
- DB-port isolation is REQUIRED. FaultWall is a proxy. If agents can reach the upstream Postgres port directly (bypassing the proxy), every SQL-level rule in this repo is void and PII is exposed. Network policy / security groups / firewall rules MUST allow only the FaultWall proxy to reach the upstream DB port. At startup the proxy runs a best-effort TCP-dial probe (F9) and logs a warning describing what it observed; this is a topology hint, not proof of isolation. Disable with
FW_DB_ISOLATION_CHECK=falseif you've already verified isolation externally. - Identity spoofing:
application_nameis fully spoofable. Setauth_token: <secret>per agent inpolicies.yamland have the agent sendagent:<id>:mission:<m>:token:<secret>. To make tokenless agents fail-closed at the proxy, setFW_REQUIRE_AUTH_TOKEN=true. JWT-based identity attestation is on the roadmap. - SSL/TLS: To Postgres, set
UPSTREAM_TLS_CA=/path/to/global-bundle.pem(RDS/Aurora/Cloud SQL) for verified TLS. To agents, setTLS_CERT_FILE/TLS_KEY_FILE; without them, agent connections are plaintext, so keep agents and the proxy on a private network. - Approvals hold locks taken earlier in the txn: with
action: hold(see docs/APPROVALS.md), a held statement has not reached Postgres, but locks that earlier statements in the same transaction took stay held until the decision. Keep hold timeouts short; the approver seesin_txnand the txn age. - Fail-closed: If a policy check fails (e.g. a parser panic), the query is refused. If the control plane is unreachable: a held write keeps waiting and is denied at its timeout (default 120s); the proxy keeps enforcing the last policy it synced, with no staleness limit, so a key revoked during the outage stays usable on that proxy until the next successful sync; on a first start with no cached policy, key-authenticated agents are refused.
Roadmap
- Inline L7 proxy mode
- Simple Query Protocol interception
- Extended Query Protocol interception (Parse/Bind/Execute)
- Per-agent, per-mission YAML policies
- 17 blocked PostgreSQL functions by default
- Real-time dashboard
- Monitor mode (sidecar)
- Security profiles (permissive, standard, strict) with custom profile support
- Full SQL parser coverage (115 pg_query_go statement types)
- TLS/SSL passthrough
- JWT-based agent identity
- Connection pooling
- Health check endpoint for proxy
- eBPF kernel-level identity attestation (enterprise)
- MySQL support
- Kubernetes operator
Contributing
git clone https://github.com/shreyasXV/faultwall
cd faultwall
go build -o faultwall .
go test ./...
License
MIT β see LICENSE.
Built by Shreyas Shubham
faultwall.com Β· @FaultWall
Source Files
ΒΆ
- agent_api.go
- agent_auth.go
- agent_keys.go
- agent_sessions.go
- alerting.go
- anomaly.go
- apa.go
- apa_client.go
- audit.go
- audit_fix.go
- audit_report.go
- auth.go
- bypass_detect.go
- collector.go
- cost.go
- dashboard.go
- detector.go
- firewall_api.go
- guards.go
- help.go
- history.go
- hold.go
- hold_cp.go
- hold_gate.go
- hold_rules.go
- identity.go
- init.go
- main.go
- management.go
- mcp.go
- mdns.go
- observation.go
- parser.go
- policy.go
- pqdsn.go
- predictor.go
- proxy.go
- proxy_mode.go
- proxy_stmts.go
- qwm_shadow.go
- qwm_state.go
- qwm_worldmodel.go
- role_pin.go
- scram_server.go
- searchpath.go
- slack.go
- telemetry_client.go
- telemetry_conn.go
- telemetry_shape.go
- throttle.go
- try.go
- try_activity.go
- try_unix.go
- tuner.go
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
internal
|
|
|
auth
Package auth implements FaultWall agent JWT authentication primitives.
|
Package auth implements FaultWall agent JWT authentication primitives. |
|
logging
Package logging provides a redacting logger wrapper for FaultWall.
|
Package logging provides a redacting logger wrapper for FaultWall. |
|
store
Package store implements a SQLite-backed persistence layer for FaultWall agent records and JWT ID (JTI) denylist entries.
|
Package store implements a SQLite-backed persistence layer for FaultWall agent records and JWT ID (JTI) denylist entries. |
|
policygen
|
|
|
agent
Package agent implements RFC-002 Autonomous Policy Agent (APA).
|
Package agent implements RFC-002 Autonomous Policy Agent (APA). |