# PostgreSQL temporary access

[Temporary access overview](/docs/concepts/temporary-access) covers target setup, connection methods, and credential handling.

## How it works

PostgreSQL stores passwords as **SCRAM-SHA-256 verifiers**, and `CREATE ROLE …
PASSWORD '…'` stores the string verbatim when it is already in verifier form —
it does not re-hash it. So the flow inverts:

1. The machine that will connect generates a random password **locally**.
2. It computes the SCRAM verifier locally (PBKDF2 → HMAC → SHA-256).
3. It sends seekrit **only the verifier**, plus a role name and a TTL.
4. seekrit runs `CREATE ROLE … PASSWORD '<verifier>' VALID UNTIL …`.
5. The machine connects to Postgres directly with the password it never shared.

The verifier is **not sufficient to authenticate** — SCRAM login requires
`ClientKey`, and the verifier only stores `SHA256(ClientKey)` (preimage-
resistant) plus `ServerKey`. So a dump of `pg_authid`, the query log, or a
backup cannot log in. The plaintext password lives only on the consumer.

> **Note:** This is zero-knowledge at **both** layers: the control plane relays only the
>   verifier, and Postgres-at-rest holds only a verifier that can't log in. The
>   password is high-entropy and machine-generated, so the SCRAM iteration count
>   (which exists to slow dictionary attacks on human passwords) is irrelevant.

## Access levels & permissions

A freshly created role has **no privileges** — it can connect but read nothing,
by design (least privilege). You grant access by picking an **access level** when
you register a target:

- **Read-only** — leased credentials can only `SELECT`.
- **Read-write** — `SELECT / INSERT / UPDATE / DELETE` (plus sequence usage so
  inserts into serial/identity columns work).
- **Custom** — supply your own create/revoke SQL templates.

For the two presets, seekrit shows you a **one-time setup query** to run as an
admin. It creates a shared **group role** (`seekrit_readonly` /
`seekrit_readwrite`) with the right grants, including `ALTER DEFAULT PRIVILEGES`
so future tables are covered. It's idempotent — safe to re-run:

```sql
DO $$ BEGIN
  IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'seekrit_readonly') THEN
    CREATE ROLE seekrit_readonly NOLOGIN;
  END IF;
END $$;
GRANT USAGE ON SCHEMA "public" TO seekrit_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO seekrit_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT SELECT ON TABLES TO seekrit_readonly;
```

Every leased credential is then created **`IN ROLE seekrit_readonly`** and
inherits those grants — so you configure permissions once, and the temp roles
stay disposable (they own nothing, so `DROP ROLE` at expiry is clean). The
dashboard badges each target and lease with its access level, so "this
credential can write" is always visible.

## Provider compatibility

A pre-hashed `SCRAM-SHA-256$…` password is stored as-is on
**Render, AWS RDS, Cloud SQL, Azure, Crunchy Bridge, self-hosted**, and most
managed Postgres. The in-DO executor authenticates its own admin connection via
**SCRAM, MD5, or cleartext** (over TLS), so it works whether a provider uses the
modern SCRAM default or still challenges MD5 for login.

See the [verifier compatibility limits](/docs/concepts/temporary-access#provider-compatibility) for control-plane-proxied databases.

See the [CLI reference](/docs/reference/cli) and [API reference](/docs/reference/api) for commands and endpoints.
