Files
tessera/docs/DATABASE-CAPTURE.md
Adnan Zahir 618681fa7f feat: persistent sessions and OIDC sign-in (auth M2 + M3)
Sessions and users (M2)
- users and sessions tables in SQLite; only a digest of the session ID is stored
- idle 30 min / absolute 8 h deadlines, UPDATE-only touch, per-user revoke by generation
- emergency operator is a users row (issuer local:emergency); its sessions are
  bound to the operator hash fingerprint, so unsetting or rotating it ends them
- CSRF derived from the session ID; GET /api/v1/me

OIDC login (M3)
- openidconnect 4.1: authorization code + PKCE S256, static redirect URI, no redirects
- one-time login transactions bound to the browser by a Lax correlation cookie
- identity is (issuer, subject); admin only from configured subjects/groups;
  a signed-in user without a grant gets 403 on management APIs
- OIDC sessions are bound to the OIDC configuration fingerprint
- SSO button, no-access page and fixed error codes in the web UI
- tests against a mock IdP with signed and malformed tokens; rehearsed against
  Keycloak 26.1 in a real browser
- rsa 0.9 advisory (RUSTSEC-2023-0071) excepted with a written reason: runtime
  code only verifies signatures with public keys

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 13:43:09 +07:00

17 KiB

Managed database backups

A capture profile maps one application and Wormhole orbit to a paired outpost. The hub stores the assignment, format, schedule, and retention policy. The agent reads connection settings and password references from its local profile file. Each application has one active capture lease. An agent can serve several applications in parallel.

Pair an agent

Build the hub, CLI and agent with cargo build --workspace. Put Restic on the hub and the database client for the source server version on the agent. SSH profiles also use OpenSSH on the agent. MySQL remote capture runs the server-compatible mysqldump on the SSH host.

Generate a pairing code in Outposts or call POST /api/v1/wormhole/pairing with operator credentials. On the agent, create the credential file once.

tessera-agent --hub-url https://backup.example.org --credentials /etc/tessera/wormhole.json pair CODE --name database-outpost
tessera-agent --credentials /etc/tessera/wormhole.json --capture-profiles /etc/tessera/capture.json run

The credentials file is owner-only and contains the hub URL, outpost UUID and upload token. Keep it outside the repository. TLS uses the system trust store. Set TESSERA_WORMHOLE_CA for a private CA and configure both TESSERA_WORMHOLE_CLIENT_CERT and TESSERA_WORMHOLE_CLIENT_KEY for a hub that requires mTLS. Plain HTTP capture is available on loopback for local testing.

Register an application

In Orbits, choose Database or Filesystem / Folder, then Via Outpost. Save the orbit and register its Outpost backup profile. Pick the paired Outpost, application UUID, and optional daily UTC schedule. Database profiles also need an engine.

For Via Hub, give the hub a readable folder path or a reachable PostgreSQL/MySQL endpoint and an absolute password-file path. Mount these files into the container when applicable. TLS verifies the server identity by default. Provide a CA file for a private CA. The hub needs a matching database client on its PATH. The bundled hub image includes pg_dump and mysqldump. Use a compatible client for the source server version.

For CLI setup, create an orbit using tessera orbit billing --provider wormhole and save its returned UUID. Use the UUID of the paired outpost shown in Outposts. Choose a stable application UUID and submit the following object to POST /api/v1/capture-profiles using the hub's admin API token or authenticated operator session.

{
  "application_id": "e1656c14-0d87-4572-a548-b66cc283e61f",
  "orbit_id": "393e5c00-65b8-4084-a521-099732948a6c",
  "outpost_id": "c7072265-89ab-493a-8dbe-948c1e9aa24c",
  "format": "postgres_custom",
  "schedule": { "hour": 2, "timezone": "Asia/Jakarta" }
}

A schedule is optional. Scheduled jobs catch up from the time the profile was registered and stay queued while the outpost is offline. Retention defaults to 14 days and keeps the newest archive. Use "retention": {"mode": "count"} for five archives or set its keep value explicitly. An orbit's custom GFS policy applies when the profile has no explicit retention override. The offline CLI decay command only processes legacy snapshots.

Set the same application UUID in the agent's local JSON file. Each entry has a source and an optional timeout_seconds (default 3600). The password file contains one line and should be readable only by the service account.

{
  "e1656c14-0d87-4572-a548-b66cc283e61f": {
    "source": {
      "engine": "postgres",
      "host": "billing.internal",
      "database": "billing",
      "user": "backup",
      "password_file": "/etc/tessera/billing.password",
      "tls": { "mode": "verify_full_with_ca", "ca_file": "/etc/tessera/database-ca.pem" }
    }
  }
}
Case Format Agent source
Direct PostgreSQL postgres_custom or postgres_sql Example above. Port defaults to 5432. TLS defaults to verify_full.
PostgreSQL through SSH postgres_custom or postgres_sql Add a bastion object. Keep the PostgreSQL hostname that the server certificate covers.
Direct MySQL mysql_sql Use "engine": "mysql", "transport": "direct", host, database, user, password file and MySQL TLS policy. Port defaults to 3306. TLS modes include verify_identity_with_ca with a CA file and required.
MySQL through SSH mysql_sql Use "engine": "mysql", "transport": "ssh", bastion, database and defaults_file. The latter is an absolute path to a private MySQL client options file on the SSH host.

The bastion object has host, user, identity_file, known_hosts_file and an optional port (default 22). Use an absolute path for each file. Record the authorized SSH server host key in the pinned known-hosts file. The SSH login needs forwarding permission for PostgreSQL or permission to run the MySQL client and read its options file for remote MySQL.

Run and inspect a backup

Open Orbits → Outpost backup jobs, select an application, and queue a backup. In the API, use POST /api/v1/capture-profiles/{application-id}/jobs. Poll GET /api/v1/capture-jobs/{job-id} for status and its /events endpoint for phase history. The list endpoint supports application_id, status, and limit filters. Successful captures expose their engine, format, and job ID in the snapshot catalog.

New Outpost orbits require the current agent and an incremental Restic repository. Follow the Rest Server and repository setup in the README for each orbit. Use the same repository password in the hub's orbit key and the agent's password file. Add these fields to the application's agent profile:

{
  "restic_repository": "rest:https://backup.example.org/<orbit-id>/",
  "restic_password_file": "/etc/tessera/keys/repository-password",
  "rest_server_password_file": "/etc/tessera/keys/rest-server-password"
}

The Rest Server login is the orbit ID when rest_server_password_file is set. For a private Rest Server CA, configure RESTIC_CACERT on the agent. A filesystem profile uses "paths": ["/path/to/folder"] in place of source and "format": "filesystem" on the hub.

The agent sends new Restic chunks and snapshot metadata. The hub registers the snapshot after checking the lease and repository. One capture job produces one catalog ID across retries. A logical database backup needs room on the executor for one private temporary dump per concurrent capture. A database can run with its normal logging settings. The dump is read in full at the source, and Restic performs deduplication before transfer to the repository.

Existing database orbits keep the legacy full-upload path until their Restic repository is configured. That path validates length and SHA-256 at ingest, stages on both sides, and has a 100 GiB upload limit.

Use the snapshot detail to download or remove an archive. Database snapshots can also be exported to a file on the hub. Use Database recovery options to apply a verified database archive to a registered target.

Operator sign-in

Authentication is required by default, including requests from loopback and a local reverse proxy. Before upgrading, configure the emergency operator hash/name and/or the separate API admin token. Startup refuses a hub without credentials. An existing install with neither configured must bootstrap credentials locally before restarting; there is no first-user auto-admin or public registration. Use a named individual emergency operator, not a shared daily SSO account.

For synthetic local development only, TESSERA_LOCAL_DEVELOPMENT=true explicitly enables anonymous loopback access when no operator/token is configured. Both listeners must bind loopback; wildcard and non-loopback binds are rejected. Forwarded requests are rejected in this mode, but that is not a proxy trust boundary: never reverse-proxy a development listener. Compose keeps the mode off and needs operator/API credentials even with a localhost published port.

Generate an Argon2id hash and set TESSERA_OPERATOR_PASSWORD_HASH to the result. The hub reads the password from stdin in hash mode. For example, from an interactive Bash shell:

read -rs -p 'Operator password: ' tessera_operator_password; printf '\n'
export TESSERA_OPERATOR_PASSWORD_HASH="$(printf '%s\n' "$tessera_operator_password" | tessera-hub --hash-operator-password)"
unset tessera_operator_password

Set TESSERA_OPERATOR_NAME for the audited identity, or use the default operator. Serve the browser over HTTPS outside loopback. Sessions expire after eight hours or a hub restart. Browser mutations require the session's CSRF token. API and CLI callers use the separate TESSERA_ADMIN_TOKEN. Use the bundled HTTP CLI on the hub's loopback listener when sending the token.

Legacy full-upload agents now need an explicit orbit assignment. With operator CSRF or an admin API token, call PUT /api/v1/orbits/{orbit-id}/outpost with {"outpost_id":"<paired-outpost-uuid>"}. Only active paired Outposts and legacy Wormhole orbits are accepted; managed capture assignment remains on its profile. Existing unassigned orbits and upload sessions without an owner fail closed. Review the mapping, bind the orbit, then restart the upload to obtain a new owned session. No owner is inferred from a name or an old token. This does not delete old snapshots or partial uploads; operators can remove abandoned partial files after stopping the old agent. Rebinding invalidates in-flight uploads from the previous Outpost.

Optional S3 copy

Configure TESSERA_OFFSITE_REPOSITORY=s3:https://s3.example.org/tessera-backups/managed with a dedicated prefix and point TESSERA_OFFSITE_PASSWORD_FILE to the independent Restic password. Supply AWS credentials via the hub service environment or the provider's credential chain. In Docker, mount the password file at the container path using a read-only mount.

The hub retries failed copies and reports their state on the capture job. Local retention and deletion protect pending copies. Off-site archives remain available independently after local catalog removal. To recover without the hub or its primary repository, use the off-site Restic password and S3 credentials with these commands:

restic -r "$TESSERA_OFFSITE_REPOSITORY" --password-file "$TESSERA_OFFSITE_PASSWORD_FILE" snapshots --tag "tessera-<snapshot-uuid>"
restic -r "$TESSERA_OFFSITE_REPOSITORY" --password-file "$TESSERA_OFFSITE_PASSWORD_FILE" dump <restic-id-from-first-command> /payload > recovered.dump

Register a restore target

Configure target credentials on the assigned agent. A target can use a different outpost from its source. PostgreSQL identifies a logical database by cluster system identifier and database name. MySQL uses the server UUID and database name. PostgreSQL source and target roles need read access to pg_catalog.pg_control_system() to verify identity. A capture with an unavailable source identity remains available for export.

From a restorable snapshot, open Database recovery options and select Register restore target. For API setup, call POST /api/v1/restore-targets with id, application_id, outpost_id, name, engine and identity. The identity has instance and database. Query the values on the target.

  • PostgreSQL uses SELECT system_identifier, current_database() FROM pg_catalog.pg_control_system().
  • MySQL uses SELECT LOWER(@@server_uuid), DATABASE().

On the target agent, add a targets map under the application UUID, keyed by the registered target UUID. A target-only outpost can omit the application's source. An example PostgreSQL entry follows.

{
  "engine": "postgres",
  "connection": {
    "host": "staging-db.internal",
    "database": "billing_staging",
    "user": "restore",
    "password_file": "/etc/tessera/staging.password",
    "tls": { "mode": "verify_full_with_ca", "ca_file": "/etc/tessera/database-ca.pem" }
  },
  "mode": { "reset": "schema", "schema": "public" }
}

Use {"reset":"recreate_database"} to recreate the registered PostgreSQL database. It requires access to the postgres maintenance database and permission to drop and create the target database. Schema mode resets the named schema and applies the dump in a transaction. Supply a local post_restore_sql file for target-specific SQL. PostgreSQL can read custom archives and plain or gzip-compressed SQL. The agent requires a psql client with restricted mode for restore. omit_transaction_timeout and omit_pg_stat_statements enable specific compatibility rules.

A MySQL target uses "engine":"mysql" and the same connection fields as a direct or SSH MySQL source. recreate_database drops and recreates the registered database before applying SQL. use_target_definer rewrites supported dump DEFINER clauses to the connected MySQL user.

Open the snapshot and choose its recovery options, then pick the target in Restore. Activity lists recent restore jobs across all snapshots (GET /api/v1/restore-jobs?limit=, newest first, at most 200) and flags any that need reconciliation. The required confirmation includes both UUIDs. The hub verifies the safety archive before issuing the single-use apply permit. If the job reports recovery_required, stop any old apply process and verify its database session has ended. Recover the target with the linked safety archive, verify data and permissions, then confirm reconciliation to release the lock. Session-authenticated file exports use a filename in the hub's private exports directory.

Import legacy archives

Run the CLI against the staging vault. Use an AWS CLI profile with s3:ListBucket scoped to the legacy prefix and s3:GetObject on the objects in that prefix.

tessera legacy-import --bucket legacy-bucket --prefix billing/ --orbit-id ORBIT_UUID --application billing --engine postgres --inventory-only

Repeat without --inventory-only to import. The JSON report includes the source key, ETag, size, last-modified timestamp, and Tessera snapshot ID. Conditional reads reject changed objects between listing and download. A persistent receipt prevents reimport after local retention and GC. AWS S3 CLI inventory, AWS S3 conditional download.

Add --history /path/to/consistent-history.sqlite to archive a consistent SQLite export of the old job history. Save the reported history ID and retrieve it with tessera legacy-history HISTORY_UUID history.sqlite on the vault host. Inspect the retrieved copy read-only. Legacy SQL archives retain their original bytes and can be applied to a temporary database with the matching engine client.

OIDC sign-in (single issuer)

Set TESSERA_OIDC_ISSUER to enable browser SSO (authorization code + PKCE S256, Tessera is a confidential client). When it is set, these are also required:

Variable Meaning
TESSERA_OIDC_CLIENT_ID, TESSERA_OIDC_CLIENT_SECRET Client registered at the IdP. The secret is only read from the environment and never logged.
TESSERA_OIDC_REDIRECT_URL Public, static callback, exactly https://<hub>/api/v1/auth/oidc/callback. It is never derived from Host or X-Forwarded-*.
TESSERA_OIDC_ADMIN_SUBJECTS Comma-separated sub values that may administer the hub.
TESSERA_OIDC_ADMIN_GROUPS Comma-separated group names that may administer the hub.
TESSERA_OIDC_GROUPS_CLAIM ID-token claim that carries groups (default groups; string or array of strings).
TESSERA_OIDC_CA_FILE Optional PEM bundle for an IdP behind a private CA.

At least one admin subject or group is mandatory, otherwise startup fails: with no mapping nobody could administer the hub. Issuer and redirect URL must be https://; plain http is accepted only for a loopback host together with TESSERA_LOCAL_DEVELOPMENT=true.

Behaviour to know about:

  • Users are identified by (issuer, subject), never by email or display name. There is no auto-link by email and no first-user-becomes-admin.
  • A user who signs in but matches no admin mapping gets a "No access yet" page and 403 on every management API. They can still call GET /api/v1/me and sign out.
  • Group membership is read at sign-in. A change at the IdP applies at the next sign-in, at most 8 hours later (absolute session limit); there is no back-channel logout or SCIM yet.
  • Changing the issuer, client ID, admin subjects/groups or groups claim ends every existing OIDC session. Rotating the client secret does not.
  • Sign-out ends the Tessera session only. The IdP session stays, so the next "Sign in with SSO" may not ask for a password. RP-initiated logout is not implemented.
  • ID tokens must be signed with RS256 (the library default). An IdP that signs with another algorithm is rejected until that is made configurable.
  • The emergency operator password keeps working beside SSO and is shown under "Emergency operator sign-in" when SSO is on.
  • No IdP token is stored or sent to the browser; the browser only receives the Tessera session cookie.