pushleft
Deploy your first app
Manual contents
Handbook
HandbookPushleftArchitecture
Operate
Install the control planeYour own serversFleetOperations and alertsAuthenticationAccess gateDomains and DNSUsage and budgetsScheduled jobsAbuse controlsAI provider proxyCustomer mailErrors and performanceLogs and metricsRetentionObject storageContainer registryGit server
Develop
The .pl.yaml manifestOnboard with an AI agentThe pl up demoBuild executorSource ingestionAgent gatewayManaged databasesSecurity findingsTunnels and shellsDev workspacesPrivate hostnamesMesh coordinatorsDesign baseline
Runbooks
Control-plane host failoverControl-plane PostgreSQL failoverControl-plane PostgreSQL restoreCustom domains and certificatesGateway key compromiseIngress host failureNode busyNode disk fullNode drain and replacementNode lostRegistry outageHetzner Robot hostsSecret rotationSecurity incidentStaging fleet on ProxmoxStaging build cacheStuck deploymentVault/OpenBao backup and recovery
More
CI pipelines
Manual · docs/authentication.md

Authentication

Sign in to Pushleft from the CLI and the console, invite members and protect your organization. Pushleft has no passwords. You sign in with a single-use code, an invitation, a passkey or your organization’s single sign-on.

Console Members, roles and pending invitations.
Console Second factors, passkeys and SSH keys of the signed-in user.

Quick start

  1. Open the console sign-in page, enter your email and select Email me a link. The mail holds one link for your account. Select it, then select Continue. It works once, for 5 minutes. Use the console’s organization switcher to reach your other organizations. If your control plane sends no mail, ask an admin for a code.

  2. Sign in the CLI with the code in that mail. The CLI stores a personal token for one organization. Add --org <name> to choose it:

    pl login --email [email protected] --code plc_...
    pl whoami
  3. Turn on two-factor authentication within 10 minutes of that sign-in. Add the printed otpauth:// URI to your authenticator app, then confirm with its first code. Store the ten recovery codes in a safe place:

    pl totp enroll
    pl totp confirm --code 123456
  4. To sign in to the console from the CLI, print a one-time code and enter it on the sign-in page:

    pl console-code
  5. Admins: open the console’s Team page, enter the email and role under Invite someone, and select Invite. The person accepts with the link from the invitation mail.

You can also add a passkey on the console’s Security page. To use an API token that you already have, run pl login and paste the token on standard input.

Overview

This section is for operators and for anyone who wants the details behind the quick start.

There are no passwords, so there is no password reset. Pushleft signs people in with:

  • Single-use login codes: mailed, self-issued or from an admin.
  • Invitations.
  • Passkeys.
  • Organization SSO.

A recovery code (below) or an operator resets a lost second factor.

Modes

The mode decides which credentials the API accepts. PUSHLEFT_AUTH_MODE selects one of two modes. The API refuses to start on any other value.

development (default)production
CredentialPUSHLEFT_DEV_TOKEN (≥ 32 characters), fixed PUSHLEFT_DEV_ORG_IDAPI tokens and console sessions in PostgreSQL
Bind addressloopback only (unchanged refusal)any
Transportplain HTTP on loopbackmust arrive from PUSHLEFT_TRUSTED_PROXIES with X-Forwarded-Proto: https
Refuses to start whenthe token is missing/short or the bind address is not loopbackPUSHLEFT_DEV_TOKEN/PUSHLEFT_DEV_ORG_ID are set, PUSHLEFT_TRUST_PROXY_TLS is not 1, the proxy list is empty, invalid or /0, PUSHLEFT_TLS_CERT/PUSHLEFT_TLS_KEY is set, or the database role bypasses RLS (superuser, BYPASSRLS, or owner of an application table) while PUSHLEFT_MIGRATE_ON_START is not 1 (the default is 0 in this mode; see deploy/README.md)

Development mode keeps the old behaviour: every request acts as the owner of the dev organization. Identity endpoints return 409 there.

Production mode accepts TLS evidence only from a terminating proxy. The API checks every authenticated request and the login request:

  • The TCP peer must be in a trusted CIDR.
  • The proxy must have set X-Forwarded-Proto: https.

If either check fails, the API returns 403 https_required. The proxy must overwrite any X-Forwarded-Proto header from the client, and must not append to it. The API records the right-most X-Forwarded-For entry as the session IP. There is no direct TLS listener (gaps).

Credentials

A credential is what proves who you are on each request. Pushleft has API tokens, console sessions, login codes and invitations.

API tokens look like pl_<prefix8>_<base64url of 32 random bytes>. The API stores only SHA-256(secret) and the prefix. The prefix is a non-secret display hint, and the API also checks it after the lookup.

Why a fast hash is enough:

  • A slow password hash such as Argon2 protects low-entropy human passwords from offline guessing.
  • A 256-bit random secret cannot be guessed, so a fast hash gives the same protection.
  • A fast hash allows an indexed equality lookup on the hash. No secret comparison happens in application code, so there is no timing side channel.

Tokens expire after 90 days by default (1–366 days allowed). A token belongs to exactly one organization.

  • A personal token has a user_id. Its role is a ceiling: the effective role is the lower of the ceiling and the user’s current membership role. Demoting or removing a member changes or ends their tokens at once.
  • A service token has no user. Its role is its role. Only admins can create one.
  • Scope ro caps the effective role at viewer.

Console sessions use the cookie __Host-pl_session (HttpOnly, Secure, SameSite=Lax, Path=/, 12 hours). The session value is 32 random bytes, and the database stores only its SHA-256.

A session belongs to one user and one organization: the organization of the login code or invitation that created it (console_sessions.org_id). The session can act for no other organization.

  • X-Pushleft-Org is optional. The API refuses any value other than the session’s own organization (credential rejected: wrong_org).
  • The API checks membership in that organization on every request.
  • Migration 0042 revoked every session created before sessions were bound. A check constraint refuses an unrevoked session without an organization.

Login codes (plc_…) are single-use. A mailed code expires after 5 minutes, any other code after 60. A code signs in to one organization, so the token it becomes acts only there.

Redeem a code with POST /v1/auth/session {email, code}. The console receives a cookie. pl login --email --code receives a new personal token for that organization.

Three kinds of caller can issue a code:

  • Anyone, by email, when platform mail is configured. POST /v1/auth/login-codes/email {email} is public, needs the CSRF header and is rate limited per address and per email. It mails the address one sign-in link for the account, and the code for the CLI. The session starts in the organization the user last had open in the console, if it can admit them.
    • The answer is always 202 and the mail goes out in the background. The endpoint does not reveal whether the address has an account.
    • A mailed code counts as self-issued (created_by is the user), because only the mailbox owner receives it. POST /v1/auth/session {email, code, org} with a mailed code signs in to any organization of the account, by name or id. If two organizations have that name, use the id.
    • Without mail, the endpoint answers 409.
  • You, for yourself: pl console-code, or POST /v1/auth/login-codes without email. This needs a read-write credential. Such a code signs you in but is not a fresh login. If it were, whoever holds the token that issued it could turn a leaked token into a fresh login.
  • An admin, for a member of the admin’s organization: POST /v1/auth/login-codes {"email": …}. Only owners can issue codes for owners.
    • The API refuses this (403) when the member also belongs to any other organization. Whoever issues a code for someone else can sign in as them. Pushleft accepts this risk inside one organization only.
    • A trigger on login_codes enforces this, and redemption checks it again (failed_auth login_code_foreign). A code issued before the user joined a second organization stops working when they join.

A user in several organizations needs one mailed link. The organization switcher reaches the others. A CLI token belongs to one organization, so run pl login --org <name> with a mailed code once for each one. The CLI keeps each login and does not change your default login. Then:

  • pl org list shows your stored logins and marks the current one.
  • pl --org <name> <command> or PUSHLEFT_ORG=<name> uses one login for one command. Parallel sessions do not affect each other.
  • pl org switch <name> changes the default for every session on the machine, and needs no new code.
  • A token in PUSHLEFT_TOKEN (or --token) already names its organization, so pl refuses --org next to it. In CI, set the token of the organization you deploy to and leave out --org.

A code you issue yourself from a credential you already hold (a CLI token or a console session) signs in to that credential’s organization.

  • The console holds one session cookie at a time. To switch organizations in the browser, pick another organization in the console’s organization switcher (POST /v1/auth/session/switch, below). This works only for a session signed in by a factor you own: a mailed code, a second factor or a passkey. After any other sign-in (SSO, a code from pl console-code or an admin, an invitation), sign in again.
  • A multi-org user who has lost every credential for an organization asks its admin to remove and re-invite them. They accept while signed in to any of their other organizations.

Invitations (pli_…) are how anyone joins an organization. POST /v1/orgs/{id}/members {email, role} for someone who is not a member creates a pending invitation. It returns 202 with the invitation and delivery.

  • With platform mail (delivery: "email"), the token goes only to the invited address, as a https://<console>/#invite=<token> link. The response does not contain it. The mail is sent before the invitation commits, so a failed send (502 mail_failed) leaves no invitation.
  • Without mail (delivery: "none"), the response carries the token, shown once. It also carries invite_url when PUSHLEFT_CONSOLE_URL is set. Only the SHA-256 is stored.

Invitations are scoped to the organization by RLS, expire after 7 days and are single-use. Inviting the same address again revokes the previous invitation.

  • Admins list invitations with GET /v1/orgs/{id}/invitations.
  • Admins revoke one with DELETE /v1/orgs/{id}/invitations/{invitation_id}.
  • Only owners invite or revoke owners.

To accept, the invited person opens https://<console>/#invite=<token> or calls POST /v1/auth/invitations/accept {token, client?}. That creates the membership and signs them in to that organization only. They get a cookie, or a token with "client": "cli". TOTP users get the usual challenge.

Without mail, the inviting admin holds the token and hands it over out of band. Because the admin may hold it too, the token alone is enough only for an address with no account or no remaining membership. An address whose account already belongs to an organization must also present that account’s own credential: a session cookie or bearer token for any of its organizations. Otherwise the answer is 403 sign_in_required.

Role changes for existing members stay direct (200).

Token creation. POST /v1/auth/tokens {name, role?, scope?, expires_in_days?, service?} (pl token create <name> [--role R] [--read-only] [--days N] [--service]) prints the new token once. Its role is never above the creator’s, and a read-only credential cannot create one. A token lasts 90 days by default, 1 to 366. A pl login token also lasts 90 days. --service makes a token of the organization rather than of a person, and needs an admin. Use one for CI. An admin service token reaches every project of the organization, so keep it on the one runner that needs it, not in a CI variable that every job can read.

Token rotation. POST /v1/auth/tokens/{id}/rotate {overlap_minutes?} (pl token rotate [id] [--overlap-minutes N]) issues a new secret. The new token has the same name, scope, role, owner and lifetime, and rotated_from links the two.

  • The old token ends after the overlap: 10 minutes by default, at most 1440. An overlap of 0 revokes it at once.
  • A token is rotated at most once (409 after).
  • Only the owner rotates a personal token, because the new secret goes to the caller. An admin who could rotate a member’s token would receive that member’s credential. Admins can still revoke it.
  • Admins rotate service tokens up to their own role.
  • Without an id, pl token rotate rotates the token it runs with. When that is the stored token, it replaces it in the credentials file.

The audit trail records token_created plus token_rotated {token_id, new_token_id, overlap_minutes, old_valid_until}. There is still no forced rotation or expiry warning.

Fresh login

Some changes affect a user in every organization. These need proof of a recent sign-in with a factor the user owns. The user-wide changes are:

  • TOTP enroll, rotate, confirm and disable.
  • Passkey registration and removal.
  • SSH key add and remove (/v1/users/me/ssh-keys, Git server).

The proof is a console session, or a token that pl login --email --code (or a challenge) issued. It must be created in the last 10 minutes by one of these methods:

Login method (console_sessions.login_method, api_tokens.login_method)Fresh login
email: a link or code mailed to the address (POST /v1/auth/login-codes/email)yes
totp, recovery_code: the login’s second factoryes
passkey: passwordless, or as the second factoryes
sso: the organization’s IdPno
code: a code issued through the API (pl console-code, POST /v1/auth/login-codes, for yourself from a token or session, or by an admin)no
invitation: an invitation tokenno
legacy: created before migration 0071no

Anything else gets 403 fresh_login_required.

The rule is about who holds the factor. User-wide credentials reach every organization of the user. An SSH key opens every repository the user can push to, and TOTP gates every sign-in.

An organization controls its own IdP. Its admins issue codes and hold invitation tokens (without mail), and any API token can issue a self code. None of these may plant a user-wide credential. Otherwise a member shared with another organization would hand that organization’s access to the first.

  • A second factor counts because it is the user’s own. An SSO or admin-code login that completes the user’s TOTP or passkey challenge is fresh.
  • To step up from a session that is not fresh, use “email me a code” (or pl login --email <address> --code <mailed code>).
  • Without platform mail, no login is email, so user-wide changes need an existing TOTP or passkey.
  • A read-only token is never enough.
  • pl login with a pasted token is not a fresh login.

Request identity

Every route extracts one AuthContext { org_id, user_id, role, scope, credential }. In production, the extractor runs pushleft_authenticate_token or pushleft_authenticate_session in a short transaction of its own.

  • These functions are SECURITY DEFINER because they run before the tenant is known. They take only a credential hash and return only that credential’s row.
  • The extractor rejects a credential that is unknown, revoked, expired, belongs to a disabled user, or has no membership.
  • It writes last_used_at at most once a minute.

Each handler then calls scope_transaction to set app.org_id from the context, so the existing RLS policies apply unchanged.

The API looks up the credential on every request. Revocation, expiry, disabling and membership removal take effect on the next request. The SSE stream checks the credential again before each poll (about every 750 ms). When the check fails, it sends event: unauthorized and closes. The stream cursor stays scoped to the context’s organization.

Roles

A role decides what a member can do in one organization: guest < viewer < member < admin < owner. Each handler calls principal.require(Role::…) first.

A guest sees only the projects it was given, as viewer or member (PUT /v1/orgs/{id}/guest-grants, admins). Every route refuses a guest unless it checks that list: the project and deployment lists, one deployment with its events, instances and source upload, the findings, and the runtime logs. A guest does not deploy production, like a member.

Route familyviewermemberadminowner
Deployments: list, get, SSE stream✓✓✓✓
Deployments: create, teardown, source upload✓✓✓
DNS zones/records, domain orders, database instances/catalogs/principals: read, preset preview✓✓✓✓
Custom domains: list, show✓✓✓✓
Custom domains: add, remove✓✓✓
DNS record sets: create/update/delete (create and update need a verified zone); database catalogs/principals: create; domain quotes✓✓✓
DNS zone creation; domain checkout and price acceptance (spends money)✓✓
Cloudflare connections: list✓✓✓✓
Cloudflare connections: add, remove✓✓
Push or delete the production branch (other branches: member)✓✓
In a production environment: deploy, teardown, source upload, secrets, database logins, catalogs and backups, custom domain add, removal and certificate upload, AI and mail tokens, storage bucket create, key rotation and file access, volume resize and migration, schedule run, cancel and cache clear, role restart (other environments: member)✓✓
Developer sessions (pl db connect, pl tunnel, pl exec); personal credentials only, not service tokens✓✓
Personal tokens (own role or lower); list/revoke own tokens✓✓✓
Service tokens; list/revoke any token in the org; invite, change or remove non-owner members; list/revoke invitations; login codes for single-org members✓✓
Grant, change or remove ownership✓

A preview environment cannot have the name production. That name is kept for the production environment, so a member cannot block the first production deploy (2026-11-29).

An organization always keeps at least one owner. An advisory lock serializes concurrent demotions. Viewers can revoke their own tokens. Viewers cannot create tokens. They get a CLI token through pl login --email --code.

Endpoints

Method and pathPurpose
GET /v1/auth/meContext, user, and memberships: only the credential’s own organization
POST /v1/auth/sessionPublic. {email, code, client?} → cookie, or {token} when client is "cli". 202 {totp_required, challenge, expires_at} when the user has TOTP. Requires X-Pushleft-CSRF: 1. Rate limited
POST /v1/auth/session/totpPublic. {challenge, code} or {challenge, recovery_code} → the cookie or token the login asked for. Requires X-Pushleft-CSRF: 1. Rate limited
GET /v1/auth/totpYour TOTP state: none, pending or active, recovery codes left
POST /v1/auth/totp/enrollA new pending secret: {credential_id, secret, otpauth_uri}, shown once. While active: {code} or {recovery_code} (rotation, reset). Fresh login
POST /v1/auth/totp/confirm{code}: activates (replacing an active secret); returns ten recovery codes, shown once. Fresh login
POST /v1/auth/totp/disable{code} or {recovery_code}. Fresh login
GET/PUT /v1/organizations/{id}/security{require_totp_for_admins}. Read: any member. Change: owners only
DELETE /v1/auth/sessionSign out: revoke the current session and clear the cookie
GET /v1/auth/orgsConsole sessions only. The organizations you can switch to, [{id, name, role, current}] by name. A session signed in by a method you do not own (sso, code, invitation, legacy) lists only its own organization
POST /v1/auth/session/switchConsole sessions only. {org_id} → 201 and a new cookie for that organization; the old session is revoked. The new session keeps the old one’s login method, second-factor proof, creation time and expiry, so a switch never extends a session or counts as a fresh login. Needs an owned login method (403 otherwise: one organization’s SSO or an admin’s code never opens another), membership (404), another organization (400). When the organization requires TOTP from its owners and admins and this session has not passed it: 202 {totp_required, challenge, methods} with the session ended, or 403 totp_enrollment_required with the session kept. Audited as logout and login with via: switch
POST /v1/auth/login-codes{email?}: a one-time code for yourself, or (admin) for a member who belongs to no other organization. Rate limited per address and target user
POST /v1/auth/login-codes/emailPublic. {email} → always 202; mails one sign-in link for the account (409 without platform mail). Requires X-Pushleft-CSRF: 1. Rate limited
POST /v1/auth/signupPublic. {email, org_name} → always 202; mails one link (403 signup_disabled when sign-up is off). Requires X-Pushleft-CSRF: 1. Rate limited
POST /v1/auth/signup/confirmPublic. {token} → 201 {user_id, org_id} and the session cookie. 401 for an unknown or used link. Requires X-Pushleft-CSRF: 1
GET/PUT /v1/orgs/{id}/onboardingThe setup state: hosting, cloud_access, trial_ends_at, trial_ended, payment_method, payments, nodes, deployments. Change {hosting}: owners and admins
POST /v1/auth/tokens/{id}/rotate{overlap_minutes?} → the new token, shown once; the old one ends after the overlap
GET /v1/auth/passkeys, DELETE /v1/auth/passkeys/{id}Your passkeys in this organization; remove one (fresh login)
POST /v1/auth/passkeys/register/options, POST /v1/auth/passkeys/registerRegister a passkey (fresh login)
POST /v1/auth/passkeys/login/options, POST /v1/auth/passkeys/loginPublic. Passwordless sign-in, or the second factor with challenge. Requires X-Pushleft-CSRF: 1. Rate limited
GET /v1/auth/sso/start, GET /v1/auth/sso/callbackPublic. OIDC sign-in for ?org=<id>; redirects
GET/PUT /v1/organizations/{id}/ssoSSO settings. Read: admins. Change: owners
POST /v1/auth/invitations/acceptPublic. {token, client?} → membership plus cookie, or {token} when client is "cli"; 202 TOTP challenge as for login. Requires X-Pushleft-CSRF: 1. An existing account also sends its own credential. Rate limited
POST /v1/auth/tokens{name, scope?, role?, expires_in_days?, service?}. The response shows the token once
GET /v1/auth/tokensAdmins see all tokens in the org; others see their own
DELETE /v1/auth/tokens/{id}Revoke. The row stays as history
GET/POST /v1/orgs/{id}/membersList, or {email, role}: change a member’s role (200) or invite a non-member (202 {token, id, email, role, expires_at, …})
GET /v1/orgs/{id}/invitationsPending invitations (admin)
DELETE /v1/orgs/{id}/invitations/{invitation_id}Revoke a pending invitation (admin; owner invitations: owner)
DELETE /v1/orgs/{id}/members/{user_id}Remove a member

{id} must be the credential’s organization. Any other id returns 404, so a token cannot probe other organizations.

Rate limiting

Rate limits slow down guessing and floods on the sign-in endpoints. They apply in production mode only.

  • Counters live in PostgreSQL (auth_rate_limits, fixed windows keyed by scope:kind:subject), so every API replica shares them.
  • pushleft_rate_limit_hit (SECURITY DEFINER) counts one attempt atomically. It prunes windows older than two days on about 1 % of writes. The counters are not history, and they are the only rows Pushleft deletes.
  • The client address is the TLS proxy’s right-most X-Forwarded-For entry. The API trusts it only from PUSHLEFT_TRUSTED_PROXIES with PUSHLEFT_TRUST_PROXY_TLS=1 (the same rule as the session IP). Otherwise it uses the TCP peer.
WhatBucketsCountedDefault per window
Login-code exchange POST /v1/auth/sessionlogin:ip:<address>, login:subject:<email>|<address>every attempt, before the code is looked at, so guesses beyond the limit are never evaluated30 per address, 10 per email from one address
TOTP challenge POST /v1/auth/session/totptotp_challenge:ip:<address>, then totp:user:<user>every attempt30 per address, 10 per user
TOTP confirm / disabletotp:user:<user>every attempt10 per user
Login-code issuance POST /v1/auth/login-codeslogin_code_issue:ip, login_code_issue:subject:<target user>every attempt30 / 10
Invitation acceptance POST /v1/auth/invitations/acceptinvitation:ip, invitation:subject:<first 8 bytes of the token hash, hex>every attempt30 / 10
Emailed login codes POST /v1/auth/login-codes/emaillogin_email:ip, login_email:subject:<email>every attempt30 / 10
Passkey sign-in (options and assertion)passkey:ipevery attempt30 per address
SSO start and callbacksso:ipevery attempt30 per address
Invalid token or session on any routecredential:ip:<address>failures only (401 unauthorized; a missing credential is not counted)100 per address

These settings set the limits. The API refuses to start on other values:

  • PUSHLEFT_AUTH_RATE_WINDOW_SECONDS (300, 1–86400).
  • PUSHLEFT_AUTH_RATE_IP_LIMIT (30), PUSHLEFT_AUTH_RATE_EMAIL_LIMIT (10) and PUSHLEFT_AUTH_RATE_TOKEN_IP_LIMIT (100), all 1–100000.

Over a limit, the answer is 429 rate_limited with Retry-After (seconds until the window ends). The first refused attempt per bucket and window writes one auth_events row rate_limited. It has no organization and holds {scope, bucket, subject, limit, window_seconds}. The subject is the address or email. The row holds no code or token. A flood adds at most one row per bucket per window.

For invalid tokens, a valid token from a limited address still works. An attacker cannot lock real users out by spraying garbage from a shared NAT. The spray only turns the attacker’s own 401s into 429s.

The per-email bucket for login is keyed on the email and the client address. If it were keyed on the email alone, anyone could lock any user out by sending bad codes for their address. Bad codes from one address now lock out only that address, and the victim signs in from their own.

  • Login codes are 32 random bytes, so the email bucket does not guard against guessing. The per-address bucket stops spraying many emails from one address.
  • Lockout ends when the window ends. An operator can lift it early (owner role): DELETE FROM auth_rate_limits WHERE bucket = 'login:subject:[email protected]|203.0.113.7'.
  • bootstrap-owner is not limited. It runs on the host with the owner’s DATABASE_URL and is not reachable over the network.
  • Alert: auth_rate_limited_spike (SLOs).

Two-factor authentication (TOTP)

TOTP is the six-digit code from an authenticator app. Pushleft uses it as a second factor after the login code.

Pushleft uses RFC 6238 TOTP: HMAC-SHA1, 6 digits, 30 s steps, a 160-bit secret and ±1 step of clock tolerance.

  • Each credential stores the last accepted step. The API refuses a code for that step or an earlier one (totp_replayed), so nobody can reuse an observed code.
  • Secrets are sealed with AES-256-GCM (ring) under the key in PUSHLEFT_AUTH_TOTP_KEY_FILE (base64 of 32 bytes). The API refuses a file with group or other permission bits.
  • The additional data binds each ciphertext to its credential and user row.
  • The secret leaves the API only in the enroll response. It is never logged or put in auth_events.

State machine (totp_credentials.status). Rows are never deleted, and a trigger refuses DELETE. The states are pending → active (first valid code) → disabled (a valid code or recovery code). Enrolling again while pending marks the old secret superseded. Every change needs a fresh login.

Rotation and self-service reset. While TOTP is active, POST /v1/auth/totp/enroll {code} or {recovery_code} starts a replacement. The CLI is pl totp enroll --code <code> or --recovery, which reads from standard input.

  1. A pending secret now exists next to the active one. The active secret stays in force.
  2. confirm with a code from the new secret marks the old secret superseded. Its recovery codes stop working with it.
  3. Confirm returns ten new recovery codes (rotated: true).

A recovery code used here is consumed. A user who lost the authenticator can reset it without an operator. Enroll without a code while active is 409. GET /v1/auth/totp shows the active credential and rotation_pending.

Recovery codes. Activation returns ten recovery codes (XXXX-XXXX-XXXX-XXXX, 80 random bits, stored as SHA-256, case and dashes ignored). Each works once, and recovery_code_used records how many are left. They belong to that credential and stop working with it.

Login. The user may have active TOTP or a passkey in that organization. Then POST /v1/auth/session still consumes the login code, but returns 202 {totp_required: true, challenge: "plt_…", expires_at, methods} in place of a credential. methods lists totp and/or passkey (passkeys completes it with a passkey).

  • The challenge is stored as a hash in totp_challenges. It is bound to the user, organization and client (console or cli).
  • It lives 5 minutes and allows 5 wrong codes.
  • POST /v1/auth/session/totp with a valid code or recovery code issues exactly what the login asked for, once.
  • Console sessions created this way carry totp_verified.
  • API tokens (pl_…) are not affected. Once issued, they work without a second factor. This includes tokens issued before TOTP was enabled.

Organization requirement. Owners can require a second factor from owners and admins with PUT /v1/organizations/{id}/security {"require_totp_for_admins": true}. The owner’s own TOTP must already be active, so the setting cannot lock out its author. A passkey satisfies it as well as TOTP, because the setting means “a second factor”. When it is on:

  • An owner or admin without active TOTP who exchanges a login code for that organization gets 403 totp_enrollment_required (audited as failed_auth).
  • The API refuses a console session of an owner or admin that did not pass a TOTP challenge (credential rejected: totp_required).
  • Owners and admins cannot disable their TOTP there (409).
  • Members and viewers are unaffected. Existing API tokens keep working.

An admin who has no second factor yet cannot sign in there, and an existing personal token is not a fresh login. To fix this:

  1. An owner demotes the admin.
  2. The admin signs in with a mailed code.
  3. The admin enrolls TOTP or a passkey.
  4. The owner promotes the admin back.

The API refuses to remove your last passkey (409) while it is your only second factor in such an organization.

CLI. Sign in first with pl login --email --code and a mailed code (a fresh login). Then:

  • pl totp enroll prints the otpauth:// URI, and the secret on stderr.
  • pl totp confirm --code <code> prints the ten recovery codes.
  • pl totp status shows the state.
  • pl totp disable --code <code> or pl totp disable --recovery turns TOTP off. The recovery code is read from standard input, never from arguments.

pl login --email --code prompts for the TOTP code (or a recovery code) when the API asks for one. --totp <code> passes the short-lived authenticator code non-interactively. --recovery reads a recovery code from standard input.

Console. The sign-in screen completes a challenge with an authenticator code, a recovery code or a passkey. Settings has:

  • Enrollment: the otpauth:// URI and secret as text, with no QR code.
  • Confirmation, with the recovery codes shown once.
  • Rotation and reset, with the current code or a recovery code.
  • Disabling.

A fresh_login_required answer asks you to sign in again. Playwright tests with a mocked API cover these screens. They do not run against the real API. The organization requirement has no console screen. Use the API.

Without PUSHLEFT_AUTH_TOTP_KEY_FILE, the TOTP and SSO endpoints return 409. A user who already has active TOTP and no passkey then cannot log in (503, fail closed).

Key rotation. To rotate the TOTP key:

  1. Move the current key file to PUSHLEFT_AUTH_TOTP_PREVIOUS_KEY_FILE.
  2. Put a new key in PUSHLEFT_AUTH_TOTP_KEY_FILE.
  3. Restart the API.

New secrets are sealed with the new key. A TOTP secret sealed with the previous key still opens. The API reseals it under the new key the next time it accepts a code.

Keep the previous key until every active secret was used once. Check with SELECT count(*) FROM totp_credentials WHERE status = 'active' AND last_used_step < extract(epoch FROM <rotation time>)::bigint / 30. A user who never signs in during that time needs an operator reset after the previous key is dropped: UPDATE totp_credentials SET status = 'disabled', ended_at = now() WHERE user_id = ….

SSO client secrets are not resealed automatically. Save the organization’s SSO settings with the client secret again before you drop the previous key. See also secret rotation.

Passkeys (WebAuthn)

A passkey signs you in with your device’s PIN or biometric. A passkey belongs to one user in one organization (passkeys.user_id, org_id, with RLS on both). Like a login code, it signs in to that organization only. A passkey registered from one organization’s session can never open another organization of the same user. The WebAuthn user handle comes from (user, organization), so one authenticator can hold a passkey per organization.

  • Register (fresh login): POST /v1/auth/passkeys/register/options returns navigator.credentials.create options. Resident key and user verification are required, attestation is none, and the algorithms are ES256/EdDSA/RS256. Then send POST /v1/auth/passkeys/register {name, id, client_data_json, attestation_object} (base64url).
  • List: GET /v1/auth/passkeys. Remove (fresh login): DELETE /v1/auth/passkeys/{id}.
  • Passwordless sign-in: POST /v1/auth/passkeys/login/options {}, then POST /v1/auth/passkeys/login {id, client_data_json, authenticator_data, signature, client?}. The credential determines the user and organization. User verification (PIN or biometric) is required, so a passkey is two factors on its own. It skips the TOTP challenge, and the session counts as second-factor verified.
  • Second factor: after a 202 challenge with passkey in methods, POST /v1/auth/passkeys/login/options {challenge: "plt_…"} returns the user’s passkeys for that organization. POST /v1/auth/passkeys/login {…, challenge} completes that login (console cookie or CLI token, as requested).

Both public endpoints need X-Pushleft-CSRF: 1 and are rate limited per address. Challenges are 32 random bytes, stored as SHA-256, single use, and live 5 minutes (webauthn_challenges, touched only by SECURITY DEFINER functions).

The server checks:

  • The client data type, challenge and origin (exactly PUSHLEFT_CONSOLE_URL, no cross-origin).
  • The RP id hash (PUSHLEFT_WEBAUTHN_RP_ID, by default the console host).
  • User presence and verification, and the signature.
  • A signature counter that must grow. A counter that stays at 0 is accepted. A counter that goes back is refused as a cloned authenticator (passkey_counter).

Attestation is not verified: the server trusts whatever authenticator the user picked. The verifier is about 300 lines on ring with a minimal CBOR decoder, because webauthn-rs links OpenSSL.

The CLI cannot use passkeys. A user whose only second factor is a passkey signs in to the console. Unit tests and a software authenticator in test:auth-hardening prove the flow. Real browsers and hardware keys are not tested.

Single sign-on (OIDC)

Single sign-on lets members sign in through the organization’s own identity provider (IdP). Pushleft supports generic OpenID Connect per organization: the authorization code flow with PKCE (S256), a nonce, and a state bound to the browser.

  • Settings: in the console under Settings → Single sign-on, or GET /v1/organizations/{id}/sso (admins) and PUT (owners) {enabled, issuer, client_id, client_secret?, allowed_domains, default_role}. The screen shows the redirect URI to register at the provider and the sign-in link to share. Admins see it; only owners save it.

    • The issuer must be https on a public host and pass discovery before you can enable it. The discovered endpoints must be https on a public host too.
    • Discovery, token and JWKS requests go through the shared SSRF filter (pushleft_core::ssrf). It refuses private, loopback, link-local, shared, reserved, documentation, NAT64, 6to4-of-private and Teredo addresses. The check runs in the resolver, so the checked address is the one dialled. Redirects are not followed.
    • A failed discovery answers with a generic 400. The detail goes to the API log.
    • PUSHLEFT_SSO_ALLOW_PRIVATE=1 (tests only) allows plain http on loopback and private addresses.
    • The client secret is sealed with AES-256-GCM under PUSHLEFT_AUTH_TOTP_KEY_FILE, bound to the organization, and never returned. Omit it to keep the stored one.
    • default_role is viewer or member.
    • The response includes redirect_uri (<console>/v1/auth/sso/callback, to register at the IdP) and login_url (<console>/#sso=<org id>, to share with members).
  • Sign-in: the console link calls GET /v1/auth/sso/start?org=<id>[&login_hint=]. This sets a 10-minute __Host-pl_sso cookie and redirects to the IdP.

    • The state is sealed (organization, nonce, PKCE verifier, expiry, hash of the cookie). The callback must come back to the same browser, which blocks login CSRF.
    • GET /v1/auth/sso/callback exchanges the code with client_secret_post, or client_secret_basic when that is all the IdP lists.
    • It fetches the JWKS and checks the ID token: RS256 or ES256 signature, iss, aud (and azp with several audiences), exp and iat with 60 s skew, nonce, and email_verified: true.
  • Who gets in (pushleft_sso_sign_in):

    • A returning user is found by the (issuer, subject) link. The email does not decide.
    • An address with no account yet gets a new one, linked at once.
    • A non-member joins only through a pending invitation for that address (with its role), or an email domain in allowed_domains (with default_role).
    • Anyone else gets sso_not_invited.
  • Linking an existing account (migration 0072). The organization controls its IdP and its email claims. The first time its identity is linked to an account that already exists, the same browser must also hold that account’s own credential. This applies to members of the organization too. Valid credentials are:

    • A console session (or pl login token) signed in with a factor the user owns.
    • A mailed code, their TOTP or recovery code, or their passkey.

    A session from SSO, an invitation or an API-issued code does not count. Without one, the answer is #sso_error=sign_in_required and nothing is linked. Sign in with “email me a code” (or a passkey), then use the SSO link again. Once linked, later SSO sign-ins need no step-up (sso_identity_linked is audited).

  • After sign-in, the usual second-factor gate applies. The session is bound to that organization, with login method sso. It never counts as a fresh login for user-wide changes, unless the user’s own TOTP or passkey completed it. The callback returns the browser to one of:

    • <console>/.
    • <console>/#challenge=plt_…&methods=… for the second factor.
    • <console>/#sso_error=<reason>.

Discovery and JWKS are fetched on every sign-in, with no cache. The code uses reqwest and ring. The openidconnect crate is not used, because its dependencies include the rsa crate (RUSTSEC-2023-0071) and about forty other crates.

Gaps: there is no console screen for the SSO settings, no SAML, no SCIM and no single logout. Pushleft does not verify that an organization owns the domains it allows. A fake provider (scripts/fixtures/fake-oidc.py) proves the flow. Tests have not run against a real IdP.

Platform mail

Platform mail sends invitations and login codes. The same settings also send budget alerts, image-scan security alerts and operator alerts. Tenants send customer mail through the mail service.

The Robot control plane sends platform mail through Amazon SES over SMTP (decided 2026-11-01; it replaced Cloudflare Email Sending, which needs Workers Paid). deploy/install-control-plane.sh builds PUSHLEFT_SMTP_URL as smtps://<key id>:<SES SMTP password>@email-smtp.<region>.amazonaws.com:465 from PUSHLEFT_SES_SMTP_USER, PUSHLEFT_SES_SMTP_PASSWORD and PUSHLEFT_SES_REGION (default eu-west-1) in install.env. PUSHLEFT_MAIL_FROM must be on a domain verified in SES. Set the user, the password and PUSHLEFT_MAIL_FROM together, or none; with none, the API sends no mail. The SES sender can send only for its own tagged domain (deploy/aws/).

  • Set PUSHLEFT_SMTP_URL and PUSHLEFT_MAIL_FROM together, or neither. They need PUSHLEFT_CONSOLE_URL for links.
  • smtps://user:pass@host:465 is implicit TLS. smtp://user:pass@host:587?tls=required is STARTTLS.
  • The API refuses plain or opportunistic SMTP at startup, except to a loopback relay.
  • Mail is sent with lettre (rustls, webpki roots) and a 10 s timeout.
  • Unset, the API logs that mail is disabled and returns tokens to the admin.

A local SMTP sink proves the sending. A real relay and deliverability are not tested. SPF, DKIM and DMARC are the relay’s job.

CSRF model

CSRF is a cross-site request that uses your console cookie without your consent. Bearer requests cannot be forged cross-site.

  • For cookie-authenticated requests, every method except GET, HEAD and OPTIONS requires the custom header X-Pushleft-CSRF: 1.
  • The login request requires it too, which also blocks login CSRF.
  • A cross-site form or simple request cannot set custom headers, and the API has no CORS policy.
  • SameSite=Lax adds a second layer.

If CORS is ever enabled for foreign origins, replace this defence with a per-session double-submit token.

Onboarding and revocation

This procedure sets up the first owner and the first members of a new control plane.

  1. Start in production mode behind the TLS proxy.

  2. Run pushleft-api bootstrap-owner --email [email protected] [--org-name "Acme"] with the migration-owner DATABASE_URL, because it bypasses tenant RLS.

    • The command creates the organization, the owner and one 90-day owner token. It prints the token once on stdout.
    • If you run it again with the same email, it issues a new token and creates no new organization (operator recovery).
    • It refuses any other email once an owner exists.

    The platform operator creates further organizations with pushleft-api create-organization --email <owner> --org-name <name> (same DATABASE_URL). It prints a new organization, its owner and one owner token on stdout. It refuses an email that already belongs to any organization, so an existing account is never pulled into a second tenant. Invite such people through the API. People can also make their own organization when sign-up is on.

  3. Run pl login (paste the token), pl whoami and pl up.

    • Credentials are stored as JSON {api_url: token} in $XDG_CONFIG_HOME/pushleft/credentials (directory 0700, file 0600).
    • PUSHLEFT_TOKEN or --token still overrides the stored token.
    • pl logout forgets the stored token only. To invalidate it, revoke it with DELETE /v1/auth/tokens/{id}.
  4. Invite teammates on the console’s Team page or with POST /v1/orgs/{id}/members. With platform mail, they receive the https://<console>/#invite=<token> link. Without it, hand them the link out of band. Later sign-ins use login codes (“email me a code”), passkeys or SSO.

Production database roles need EXECUTE on the pre-tenant pushleft_* auth functions listed in database roles. The migrations revoke PUBLIC execute from them. Since 0042, the API no longer needs pushleft_ensure_user or pushleft_user_memberships.

Sign-up

Sign-up lets a person make an organization with a free trial. It is off by default, so a self-hosted control plane never opens it by accident.

Set these in the API environment:

VariableMeaning
PUSHLEFT_SIGNUP=onOpens sign-up. It needs platform mail (PUSHLEFT_SMTP_URL)
PUSHLEFT_SIGNUP=inviteOpens sign-up only to invited addresses. Other addresses go on the waitlist. It needs platform mail
PUSHLEFT_TRIAL_DAYSThe trial length in days, 1 to 90. The default is 14
PUSHLEFT_SIGNUP_MAIL_TOThe operator address that gets a mail for each sign-up, each request for Pushleft servers and each trial that ends without a payment method

The flow:

  1. The person opens https://<console>/#signup and types an email address and an organization name.
  2. The API answers 202 for every valid request and mails one link, https://<console>/#signup=<token>. The link works once, for 60 minutes. The mail contains nothing that the person typed.
  3. The person selects Confirm on the page that the link opens. Only then does the API make the organization, its owner and a console session. A mail scanner that opens the link makes nothing.
  4. The console opens the setup steps: servers, the CLI and the first deployment.

Rules:

  • An address that already has an account gets a sign-in link instead. The answer is the same 202, so the endpoint does not reveal which addresses have an account.
  • Limits: 5 requests per client address and 3 per email address in an hour.
  • The API stores only a hash of the link token. Unconfirmed requests are deleted 7 days after they expire.
  • A sign-up organization starts in the new trust tier, on the trial plan.
  • Its work runs on its own servers until an operator approves Pushleft servers.
  • Audit events: signup, hosting_changed, cloud_access_approved, payment_method_added and payment_method_removed.
  • With PUSHLEFT_SIGNUP=invite, an address that is not invited gets no link. It goes on the waitlist, and the operator gets a mail with the command that invites it. The answer is the same 202, with invite_only: true.

Invite list

Use the invite list when server capacity is low.

pushleft-api signup waitlist           # addresses that wait, oldest first
pushleft-api signup invite <email>     # invite an address; it does not have to be on the waitlist

The API sends the invite mail within a minute. The mail links to the sign-up page. The person signs up with the invited address and gets the usual confirmation link.

Audit

The auth_events table records every sign-in and credential change. The table is append-only: a trigger rejects UPDATE and DELETE. It stores ids only.

It records these events:

  • bootstrap, logout, token_created, token_revoked, token_rotated, membership_changed.
  • login, with method (the login method) and second_factor: null, totp, recovery_code or passkey.
  • login_code_created (with delivery: "email" for mailed codes).
  • invitation_created, invitation_revoked, invitation_accepted.
  • totp_enrolled, totp_activated, totp_disabled, recovery_code_used.
  • security_settings_changed, passkey_registered, passkey_removed, sso_settings_changed, sso_identity_linked.
  • rate_limited (no organization).
  • failed_auth with a reason (below).

invitation_accepted and membership_changed have via for SSO joins.

The failed_auth reasons are:

  • General: revoked, expired, user_disabled, not_a_member, wrong_org, login_code_reused, login_code_expired, login_code_foreign, invitation_used, invitation_revoked, invitation_expired, sign_in_required, totp_invalid, totp_replayed, totp_not_active, recovery_code_invalid, recovery_code_reused, challenge_used, challenge_expired, challenge_exhausted, totp_required, totp_enrollment_required.
  • Passkeys: revoked, passkey_client_data, passkey_origin, passkey_rp_id, passkey_user_verification, passkey_signature, passkey_counter, challenge_invalid, challenge_expired.
  • SSO, with via: "sso": sso_disabled, sso_not_invited, sso_email_unverified, sso_token_invalid, sso_token_signature, sso_token_algorithm, sso_failed.

pushleft-api audit --org <uuid> lists an organization’s rows. --org none lists the organization-less ones (rate_limited). RLS lets only owners and admins of the organization read it. Unknown tokens and unknown login codes go to the log and not to the table, so unauthenticated guessing cannot grow it. The operations audit trail covers the other audit tables.

Threat model

The threat model lists what this design defends against, and what it does not cover yet.

In scope:

  • Stolen database rows: they contain hashes only.
  • Cross-organization access: the context comes from the credential, and the API, RLS and 404 responses on foreign ids all block it. Every credential (token, session, login code, invitation, passkey, SSO link) is bound to one organization.
  • An organization’s own IdP:
    • Its email claims never reach an account that another organization trusts without that account’s own credential.
    • SSO sessions are bound to that organization.
    • An SSO session cannot change user-wide credentials (SSH keys, TOTP, passkeys) without the user’s own factor.
  • Account takeover across organizations:
    • An admin cannot make an existing user of another organization a member without that user’s own credential.
    • An admin cannot issue a login code for a user who belongs to another organization.
    • A session can never select an organization other than its own.
  • Privilege escalation: tokens cannot exceed their creator’s role, and admins cannot touch owners. ro tokens are capped at viewer and cannot issue login codes or rotate or revoke tokens.
  • CSRF on the console.
  • Bypassing the proxy: TLS evidence is required on every request.
  • Lingering access after revocation, expiry, disabling or removal: the API checks credentials on every request, and the SSE stream checks them during streaming.

Out of scope or missing:

  • SSO: generic OIDC only (above). Tests have not run against a real IdP. Missing:
    • SAML, SCIM, single logout, IdP-initiated login and a console settings screen.
    • Proof that an organization owns the domains it allows. An organization can allow any domain. A new account squatted that way can only be a denial of service for the real person, as with invitations.
  • 2FA: TOTP, recovery codes and passkeys are implemented (above). A user who loses the authenticator and every recovery code (and has no passkey) still needs an operator. Passkey attestation is not verified.
  • Password login and reset: none by design (no passwords). Without platform mail, login codes and invitation tokens are handed over out of band. Whoever relays a code can sign in as that user, within that one organization.
  • Email delivery: with platform mail, invitations and login codes go to the address only. Without it, the API returns invitation tokens to the inviting admin. A new address that the admin accepts themselves becomes an account the admin controls. The real person then cannot use that address. The admin gains no existing account. Mail is platform-own only, with no bounce handling.
  • User-wide settings from an org-bound credential: TOTP and SSH keys are per user. Changes need a fresh login with a factor the user owns (10 minutes) and, while TOTP is active, a current code or recovery code. An organization’s SSO, its admins’ login codes, its invitation tokens and API tokens cannot produce one. What remains:
    • An organization that controls the user’s mailbox (a company domain) controls the account through mailed codes, as with any email-based sign-in.
    • A passkey registered from an SSO or admin-issued session before migration 0071 still counts as the user’s own. If that matters, revoke such passkeys: look for passkey_registered audit rows before the migration.
  • Token rotation policy: rotation with an overlap is implemented (above). There is no forced rotation, no expiry warnings and no refresh tokens. Service tokens are bearer secrets with no IP or audience binding.
  • Rate limiting and lockout: implemented per address and per email/user (above). Every counted attempt is one PostgreSQL upsert, so a large distributed flood still reaches the database; keep a coarse limit at the proxy as well. There is no permanent lockout or CAPTCHA, only fixed windows.
  • Session management UI: you can only sign out the current session. Listing other sessions and revoking all of them is missing. Disabling a user (users.disabled_at, set by an operator) ends every credential.
  • Org creation, org settings and org deletion endpoints: missing. Only bootstrap creates an organization.
  • Direct TLS listener: missing. Production requires a trusted terminating proxy.
  • Viewers and source upload: a viewer’s source upload is refused only after the body has been read. A viewer can therefore briefly hold an upload slot.
  • Agent, scheduler and controller tenant isolation: not covered by this work. Those services use mTLS node identity (agent gateway).

Source and tests

  • Code: crates/pushleft-api/src/auth.rs, auth_hardening.rs (rate limits, TOTP), auth_mail.rs (platform mail), auth_passkeys.rs (WebAuthn) and auth_sso.rs (OIDC).
  • Migrations: 0027_production_auth.sql, 0038_control_plane_ha_and_auth_hardening.sql, 0042_org_bound_sessions_and_invitations.sql, 0048_token_rotation_totp_rotation_and_mail.sql, 0049_passkeys.sql, 0050_organization_sso.sql, 0071_login_method.sql and 0072_sso_link_needs_own_credential.sql.
  • Tests: src/auth_tests.rs, src/auth_hardening_tests.rs, the unit tests in the passkey, SSO and mail modules, the production phase of scripts/e2e.sh, and scripts/auth-hardening-e2e.sh (npm run test:auth-hardening, with a local SMTP sink, a software authenticator and a fake OIDC provider in scripts/fixtures/).
  • CLI: pl login, pl logout, pl whoami, pl console-code, pl totp, pl token create, pl token rotate.
  • Console (src/main.jsx): sign-in (login code, “email me a code”, passkey, SSO link /#sso=<org id>), invitation acceptance (/#invite=…), the second-factor step (TOTP or passkey), Team (members and invitations), Settings (TOTP and passkeys) and sign-out.
Rendered from the repository at build time. Edit docs/authentication.md to change it.