Database access management for engineers and AI agents

Engineers, BI tools and AI agents reach Postgres, MySQL, Snowflake and MongoDB through the Formal Connector as themselves. A Native User holds the database password, and database access control runs on every query and every result.

psql · prod-postgresexample
HUMAN   maya@acme.com via Okta, native user: readonly
BLOCK   DELETE FROM users WHERE plan='free'
MASKED  SELECT name, ssn FROM patients
AGENT   devin for maya@acme.com: SELECT * FROM orders, LIMIT 1000 added
# the database password stays with the Native User on the Connector

Why now

Why shared database logins stop working

Most teams start with one read-write login per database and its password in a vault folder. With hundreds of people, several engines and now agents on a handful of logins, database access management has to carry the person, or the agent and its owner, all the way to the query.

  1. Privileged accounts shared by a whole team

    An incident review finds app_admin on every line of the database log, and nobody can say who ran the query. The accounts also outlive the people who used them.

  2. Passwords copied into scripts, laptops and agent configs

    “Without Formal, we couldn't have agents with access to sensitive data.”
    Travis McPeak, Head of Security, Cursor
  3. Read-write roles for read-only questions

    Every engine has its own permission model, so the quick answer to a read-only question is a role that can also write.

today · no policy on the pathexample
01
app_admin · psqlDELETE FROM users WHERE plan='free'ALLOWED
02
agent · DATABASE_URLSELECT * FROM ordersALLOWED
03
analyst · DataGripUPDATE accounts SET plan='pro'ALLOWED

# One shared login, three requests, and the database log says app_admin for all of them.

What you get

What database access management covers

database access managementnoun

Database access management is how you decide who can reach which production database, as which database user, and what they can run once connected. With Formal, database access control happens on each query and each result instead of only at login.
  • Every connection as a person or agent

    Engineers sign in with SSO. Agents and BI tools connect as machine users, and Formal records the human they act for.

  • The password stays at the Connector

    A Native User holds the database login, or fetches it from your secret manager at connection time. People and agents never see it.

  • Risky queries blocked before they run

    Stop a production DELETE and tell the engineer why, right in psql, or cap unbounded reads with a row limit.

  • Columns masked by data label

    Mask or filter results by the labels discovery assigned to each column, per user, group or agent.

  • Time-bound exceptions in Slack

    Lift a block for one person or one agent session after an approval in Slack. The exception expires on its own.

  • Every query logged with who ran it

    Query text, rows affected, bind parameters and the policy actions taken, forwarded to your SIEM.

Rollout

How do you manage database access?

Tie every connection to a person or agent from your identity provider, keep database passwords off laptops and out of scripts, grant least privilege database access per task, check each query against a policy and log who ran what. Shared logins and per-database GRANTs work for ten engineers. They stop working at a few hundred engineers across several engines. This is the order we’d roll it out in.

  1. Inventory the data

    Formal’s data discovery lists databases, schemas, tables and columns on a schedule (every 6 to 24 hours, or your own cron) and labels sensitive columns with regex rules, or with AI prompts on Amazon Bedrock in your own AWS account. A column added since the last scan has no label until the next one.

  2. Remove shared logins

    Engineers sign in through SSO and connect as idp:formal:human:<email>; agents and BI tools connect as machine users. This step matters most: while a team shares app_admin, every log line says app_admin, and no policy can tell the on-call engineer from the analytics job.

  3. Give each upstream login the least privilege it needs

    For read-only access on Postgres, the docs recommend a Native User with only SELECT on the application schemas (GRANT in the Postgres manual).

  4. Put a policy on the queries that matter

    Writes in production, reads of labeled columns, unbounded agent reads.

  5. Turn standing access into time-bound exceptions

    Someone approves each exception, and it ends on its own. See time-limited access with approval.

  6. Send every session to your SIEM

    The database log then sits next to the rest of your security logs, with a person or agent on every line.

Setup

How it works

  1. Step 1 of 4

    Add each database as a Resource

    Point a Resource at the database hostname and attach it to a Connector listener. Many Postgres or MySQL databases can share one port.

    RESOURCESexample
    • prod-postgres on port 5432✓
    • billing-postgres on port 5432✓
    • orders-mysql on port 3306✓
  2. Step 2 of 4

    Create Native Users

    Add the upstream logins the Connector uses, such as a read-only one, and choose which one each group gets by default.

    NATIVE USERSexample
    • readonly · everyone by defaultDEFAULT
    • admin · group adminsADMINS
    • password from AWS Secrets ManagerNEVER SHOWN
  3. Step 3 of 4

    Write policies

    Start in dry-run, check the results, then activate. Policies run at the session, request and response stages.

    POLICY STAGESexample
    • request · DELETE FROM usersBLOCKED
    • response · SELECT ssn FROM patientsMASKED
    • new policy · row limit for agentsDRY RUN
  4. Step 4 of 4

    Connect and review sessions

    Engineers connect with their usual client and Formal username. Each session lists its queries and the policy actions taken.

    SESSION · MAYA@ACME.COMexample
    • SELECT id, plan FROM accountsALLOWED
    • SELECT * FROM ordersLIMIT ADDED
    • DELETE FROM usersBLOCKED

Policy

Database access control on every query

Database permissions answer one question when a role touches a table: is it allowed at all? The Connector reads each query before it reaches the database and each result before it reaches the client, so a Rego policy can decide with more context: the environment, the user’s groups, the statement type and the data labels in the result. This policy from the enforcement docs blocks DELETE statements on production resources, and the engineer reads the message in psql.

  • At the request stage, rewrite adds a LIMIT to a query or lowers a higher one, and never raises a lower limit
  • When two policies disagree, Formal picks the stricter one: block wins over allow, the smallest row limit wins, and a nullify beats a partial redaction on the same column
  • Test a new policy in dry-run first. Mask names aren’t checked on save, and a misspelled sub_type leaves the value unmasked without an error
Policy enforcement docs ›
block-production-deletes.regorego
package formal.v2

import future.keywords.if

request := {
  "action": "block",
  "type": "block_with_custom_message",
  "message": "DELETE operations are not allowed in production",
  "reason": "Production data protection policy"
} if {
  input.resource.environment == "production"
  input.sql_query.statement_type == "DELETE"
}

Capabilities

Least privilege database access, per task

Masking

Mask and filter results by data label

At the response stage, mask changes the values in columns that carry a data label before the result reaches the client. The data masking page covers the masking side in depth.

  • Nullify, hash, fake values or partial redaction, per user, group or agent
  • filter drops rows instead: the docs example keeps a customer’s rows only while the user has an open Zendesk ticket for that customer, with the ticket data loaded into the policy
  • Masking covers the SQL engines and MongoDB fields, not ClickHouse or Redis
Data masking ›
psql · prod-postgresexample
maya@acme.com> SELECT name, ssn FROM patients LIMIT 3
namessn
J. Okafor***-**-1186
R. Lindqvist***-**-5530
P. Mehta***-**-2079
3 rows · policy mask-ssn-by-labelMASKED
AI agents

Database access control for AI agents

An agent with a database password in its environment can query production in every session it runs, and the database log shows the password’s user. In the Devin guide, Devin signs in to Formal with its own short-lived OIDC token, maps to a devin machine user and to the person who started the session, and the Connector evaluates and logs each query with that person as the end user.

  • A policy blocks the machine user by default. When Devin needs data, it calls a workflow with a reason and a duration, the person who started the session approves in Slack, and the policy suspension covers only that person and that Devin session
  • The workflow runs as a separate machine user, so Devin can never create its own suspension: separation of duties between the agent and the approval
  • The suspension’s condition is built from verified token claims only. The approver reads Devin’s reason and duration, and neither goes into the condition, where Devin could inject CEL
  • The token Devin uses for psql never outlives the OIDC token it came from, and masking and read-only rules still apply after approval
  • Formal ships 15 built-in OIDC issuers, including Cursor and GitHub Actions, and accepts any OIDC provider (agent identity). A policy on input.user.type == "machine" can cap every agent read with a row limit
  • Cursor puts PostgreSQL, Redis and ClickHouse behind Formal and keeps their policies and audit logs in one place with SSH and Kubernetes
Devin integration ›
slack · #db-accessexample
FormalAPP
devin for maya requests read access to prod-postgres for this session
Resource
prod-postgres
Reason
debug a failed checkout
Duration
1 hour
Scope
maya + this Devin session
maya approved. The suspension covers maya and this Devin session only.
APPROVED
Just-in-time

Time-limited access with approval

Just-in-time database access in Formal is a policy suspension: a one-off or time-bound exception to a blocking policy, for one identity, that Formal removes when it expires.

  • The request comes from a Slack form or from Access Requests; the yes comes from an approver in Slack or the Control Plane
  • Exceptions from Access Requests run from 30 minutes to 7 days, and the approver sees the reason first
  • Deleting the suspension in the Policy Suspensions tab revokes it before it expires
  • JIT access explains the concept
Just-in-time access in Workflows ›
access requests · prod-postgresexample
09:02leo@acme.comUPDATE on prod-postgres for 2 hoursREQUESTED
09:05sam@acme.comapprove leo, block-prod-writes suspendedAPPROVED
11:05formalsuspension removedEXPIRED
Audit

What a database session log records

Formal doesn’t record database sessions as video. It logs each query in Sessions, which you can search and alert on. SSH and Kubernetes sessions, which Formal does record, are on session recording, and database activity monitoring covers how a query log fits next to DAM tools.

  • The full query text, SQL or NoSQL, with execution time and rows affected
  • Policy actions (masking, denials, warnings) and the bind variables and arguments
  • The Formal identity, the end user an agent acted for, and the Native User it ran as
  • Log integrations forward the same records to Datadog, Splunk, Panther, or a bucket in S3, Google Cloud Storage or Azure Blob Storage. Logs also reach Formal’s Control Plane, so use log schemas to drop, truncate or encrypt fields such as bind parameters before they leave the Connector
  • Modern Health found default Postgres logging too thin to track user queries, and now gets audit logs beyond it across 20+ Postgres databases
Privileged session recording ›
session · psql · prod-postgresexample
10:14:03maya@acme.com as readonlySELECT id, total FROM orders WHERE id = $1 · 1 rowALLOWED
10:14:41devin for maya@acme.comSELECT * FROM ordersLIMIT ADDED
10:15:09devin for maya@acme.comSELECT email FROM usersMASKED

Credentials

No shared database passwords

A Native User is the login the Connector uses upstream. Formal identities never know it or send it. Which Native User a person gets is one CEL expression on the Resource: here, everyone outside admins lands on readonly.

  • The credential can be a value stored encrypted in Formal, an environment variable on the Connector, a secret the Connector reads from AWS Secrets Manager, GCP Secret Manager or Azure Key Vault with its own cloud identity, or the output of a hook that runs at connection time, for example to fetch short-lived credentials from Vault
  • Where the database accepts IAM authentication, such as RDS, Redshift or ElastiCache, the Native User can use the Connector’s AWS identity instead of a password
  • A user can ask for another label by appending @<label> to their Formal username, and a session policy can block any request that differs from the assigned default
  • Rotating a static password is one Update Credentials on the Native User, in one place instead of in every script that had a copy. Formal doesn’t rotate database passwords on its own; if you want short-lived ones, generate them in a hook
  • No engineer or agent holds a password that works against the database directly, which is the database half of zero standing privileges
Native Users docs ›
native user selection (CEL)text
"admins" in user.groups
  ? native_users["admin"]
  : native_users["readonly"]

Supported databases

Which databases and warehouses does Formal support?

Formal’s Connector supports PostgreSQL, MySQL, MariaDB, Amazon Redshift, Snowflake, Google BigQuery, ClickHouse, MongoDB, Redis and Amazon DynamoDB. Policies run on all of them except DynamoDB, which the Connector authenticates and logs only. Masking needs a response stage and column support, so it covers the SQL engines and MongoDB fields, and not ClickHouse or Redis.

  • PostgreSQL, including RDS, Aurora, Supabase, AlloyDB

    Session, request and response policies. No extra Postgres privileges needed to proxy queries. Postgres access control

    Column masking
  • MySQL, including RDS and Aurora

    Session, request and response policies. No extra MySQL privileges needed to proxy queries.

    Column masking
  • MariaDB

    Session, request and response policies. Native Users can use AWS IAM or GCP IAM.

    Column masking
  • Amazon Redshift

    Session, request and response policies. Policies, masking and logs work as for Postgres.

    Column masking
  • Snowflake

    Session, request and response policies. The Connector is reached through DNS records and a load balancer. Snowflake access control

    Column masking
  • Google BigQuery

    Session, request and response policies. No Native Users: the Connector uses Google application default credentials.

    Column masking
  • ClickHouse

    Session, request and response policies. Masking isn’t supported, and a mask fails closed. No administrative ClickHouse user needed.

    No masking
  • MongoDB, self-hosted and Atlas

    Session, request and response policies, with masking by field path. Discovery reads the first 500 documents per collection; with a default-deny session policy, mongosh can’t connect.

    Field masking
  • Redis

    Session and request policies, no masking. AWS IAM authentication for ElastiCache.

    No masking
  • Amazon DynamoDB

    No policy stages: authenticated and logged only. Put an AWS resource in front for policies.

    Logged only

Sources: the resource pages under supported resources. A database that isn’t in this table isn’t a supported resource type today.

Deployment

How the Connector sits in front of your databases

The Connector is a database proxy you run in your own network: on ECS Fargate, with Helm on EKS, GKE, AKS or on-premises Kubernetes, or in Docker, as a cluster for redundancy (deployment docs). It reaches self-managed databases, RDS and Aurora over plain TCP, and dials Google Cloud SQL for Postgres, MySQL and MariaDB natively, without a cloud-sql-proxy sidecar.

  • Queries and results pass only through the Connector; the Control Plane holds configuration and can’t reach your data
  • Clients point at the Connector instead of the database. With smart routing, many Postgres databases share port 5432 and the client picks one with DATABASE_NAME@RESOURCE_NAME, the same way for MySQL
  • Engineers who would rather keep the original hostname run the Formal Endpoint in Transparent Mode on macOS or Linux
  • BI tools are where shared service accounts last longest, because one connection serves every viewer of a dashboard. This Retool connection from the Snowflake docs signs in as a Formal machine user and passes the viewer’s email on each connection, so queries are logged with the person behind the app. Formal takes that end user from Retool’s assertion, so trust it as far as you trust Retool’s own sign-in
  • At ManoMano, putting Metabase, Snowflake and Postgres behind Formal turned up former employees with active Metabase jobs
Smart routing docs ›
Retool to Snowflake through the Connector (JDBC)text
jdbc:snowflake://account.test-snowflake-proxy.prod.com:443/?user=idp:formal:machine:prd-retool&password=[pwd]&db=analytics&options=formal_enduser={{ current_user.email }}

Works with

Works with your clients and databases

Engineers keep their clients. The Connector speaks each database’s protocol and proxies SQL databases, warehouses, MongoDB and Redis; the supported resources page lists each one with its setup.

  • PSpsql
  • MYmysql
  • MOmongosh
  • PGpgAdmin
  • DADataGrip
  • Metabase
  • RERetool
  • Postgres
  • MySQL
  • MariaDB
  • MongoDB
  • Redis
  • Snowflake
  • BigQuery
  • Redshift
  • ClickHouse
  • Devin
  • ANAny OIDC workload

Deployment and enterprise

Deployed one network hop from the database

The Connector runs in your VPC or data center, and it uses the identity provider, SIEM and Terraform you already run.

Formal Connector in your VPC

Linux on AMD64 or ARM64: AWS ECS Fargate behind a Network Load Balancer, or Helm on EKS, GKE, AKS or on-premises Kubernetes. In production, run 2 or more nodes behind a load balancer.

Deployment docs ›

AWS PrivateLink to the Control Plane

On AWS, the Connector can reach the Formal Control Plane over AWS VPC PrivateLink.

PrivateLink docs ›

Your identity provider

People sign in with SSO, and SCIM keeps users and groups in sync. At Notion, hundreds of developers reach more than 100 RDS instances through group-based rules and short-lived credentials issued through Okta.

Logs in your SIEM

Log integrations forward Formal logs to AWS S3, Google Cloud Storage, Azure Blob Storage, Datadog, Splunk or Panther.

Policy and configuration as code

Policies are written in Rego. Manage Formal with Terraform, Pulumi or the Kubernetes Operator.

Audited controls

Formal holds SOC 2 Type II and ISO/IEC 27001. The reports are on security.formal.ai.

For database privileged access management, Formal uses the Connector and the Rego policies that also govern SSH hosts and Kubernetes clusters in its privileged access management software, and Workflows run the approvals for all of them.

In production

RDS instances
100+
Deployment
<1 week
Dev friction
0
“What's nice is that the developers who are using it don't even notice that they're using it. So it's working very seamlessly into our system. It's working in the background and it's not impacting developer velocity.”
Michelle Parent
Security Engineer, Notion
Read the Notion story ›

FAQ

Questions about database access management

Buying and fit

How do you manage database access for hundreds of developers?

Through groups from your identity provider instead of one GRANT per person. SCIM keeps users and groups in sync with Okta, Entra ID or Google Workspace, database access control policies name the groups, and a person who changes team or leaves changes access everywhere at once. That is the setup Notion runs for hundreds of developers.

What is database access control?

Database access control is the set of rules that decide which identities can connect to a database and what they can read or change once connected. Each engine ships its own version, usually role-based access control with roles and GRANTs. Formal adds policies in front of every engine, written once in Rego and checked on each query and result. Least privilege still starts in the database, as NIST defines it: the Native User should hold only what the job needs.

Is database access management the same as database activity monitoring?

No. Database activity monitoring watches queries and alerts on them, usually after they ran. Database access management decides who may connect and what they may run before the query reaches the database. Formal does both from the proxy: it enforces the policy and logs the query. DAM vs database access management goes through the difference.

Is Formal database security software?

It covers the access part of database security software: identity, per-query policy, masking and audit logs for people and agents. It doesn’t encrypt data at rest, patch database servers or scan them for vulnerabilities. The database security guide covers those layers.

Product

How do I give engineers time-limited database access with an approval workflow?

Have the approval create a time-bound exception to a blocking policy instead of granting a new database role. Exceptions from Access Requests run from 30 minutes to 7 days, the approver sees the reason first, and deleting the suspension in the Policy Suspensions tab revokes it before it expires. Time-limited access with approval links the Slack workflow setup.

How do you give engineers database access without static passwords?

Sign them in with SSO and let the proxy hold the database credential. Engineers connect as idp:formal:human:<email>, and the Connector logs in upstream as a Native User whose password it reads from your secret manager or a hook, so nothing on the laptop works against the database on its own. Zero standing privileges covers the wider pattern.

Do engineers have to change psql or their BI tool?

No new client is needed. psql, mysql and mongosh point at the Connector hostname with a Formal username. pgAdmin and DataGrip can mangle the DATABASE_NAME@RESOURCE_NAME routing format, so they work best with a local listener from formal connect or with the Endpoint’s Transparent Mode. Retool needs custom connection options to reach Snowflake through the Connector.

Put a person behind every database query

See how Notion runs database access for hundreds of developers through Formal, with no shared logins.