Backup and restore
A complete backup of an Open Enterprise deployment has three parts:
- The runtime PostgreSQL database.
- The master keys that encrypt secrets inside that database.
- The runtime configuration file and the other environment secrets.
A database backup alone is not enough. Without the master keys, the runtime cannot read the secrets stored in the database.
State in PostgreSQL
The runtime database holds all durable runtime state:
- Users, external identities, organizations, memberships, roles, and invitations.
- Sessions, login flows, exchange grants, and session revocations.
- Audit events.
- SCIM directories, directory users, groups, group members, and directory credentials.
- Shared Signals streams and the received-event inbox.
- Permission state, revisions, policy versions, and the synchronization log.
- Organization configuration versions, domains, and portal entries and sessions.
- Encrypted administration secrets, such as customer OIDC client secrets.
- The lifecycle event log, the outbox, resource versions, and snapshots.
- Webhook subscriptions, encrypted signing keys, deliveries, and attempts.
- Local accounts and their password hashes, sealed TOTP seeds, recovery code hashes, challenges, account-page sessions, login policies, identity migrations, and the account email outbox.
- OAuth issuer state: clients, resources, approvals, subject mappings, browser sessions, grants, hashed codes and refresh tokens, and sealed signing keys.
- Service accounts, hashed API keys, machine client bindings, live token gates, and credential epochs.
- SCIM schemas, SAML correlation and replay records, sealed POST handoffs, and short-lived operator browser sessions.
- The
_sqlx_migrationstable, which records the applied migrations.
API keys, invitation tokens, runtime session tokens, login handles, exchange codes, OAuth client secrets, authorization codes, and refresh tokens are stored as SHA-256 hashes.
The PDP receives permission snapshots from the runtime. The runtime database is the source of those snapshots.
These systems keep their own state, so back them up separately:
- The optional vendor backend bridge database (
PORTAL_DATABASE_URL), when deployed. - Each application database, including the example's outbox and event consumer tables.
- The identity provider, such as Keycloak.
Master keys
Four configuration sections name master keys:
administration.secret_key_envencrypts customer OIDC client secrets.events.secret_key_envencrypts webhook signing keys and protects feed cursors.local_authentication.secret_key_envseals TOTP seeds and queued account messages.issuer.secret_key_envseals the OAuth issuer's private signing keys.
Each section can also list previous_secret_key_envs.
The runtime uses previous keys only to read values that an earlier key protected.
The administration guide and the events guide describe rotation.
Back up the current key and every previous key that the configuration lists. Store them apart from database backups, in a separate secret store with separate access control. A person who holds both a database backup and the keys can decrypt the stored secrets.
If you restore a database without the matching keys:
- The runtime cannot decrypt stored customer OIDC client secrets.
- The runtime cannot decrypt webhook signing keys.
- Feed cursors protected by a missing key become invalid.
- The OAuth issuer cannot sign tokens. Revoke the unreadable signing keys with the operator API so the runtime creates a new one; tokens signed earlier stop validating. The OAuth guide describes the recovery.
- People with two-step verification cannot finish signing in with an authenticator code.
Their recovery codes still work, and an operator can reset the factor with
account reset-mfa. Queued account messages that the key sealed are not delivered.
A lost key cannot be recovered from the database. Keep each previous key in your backups for as long as any database backup that needs it exists.
Configuration and environment secrets
Keep the runtime YAML configuration in version control or in your deployment system.
It names secrets but does not contain them.
Its *_env fields name environment variables that hold secrets: the database URL, service and directory key digests, OIDC client secrets, AuthZEN tokens, and the master keys.
Back up those values in your secret store.
Take a backup
Use standard PostgreSQL tools.
A logical backup with pg_dump works for small and medium databases:
pg_dump --format=custom --file=open-enterprise-runtime.dump "$BACKUP_DATABASE_URL"pg_dump reads one consistent snapshot, so the runtime can keep running.
The backup role needs read access to every table in the runtime schema.
For large databases or point-in-time recovery, use physical backups with WAL archiving. Follow the PostgreSQL documentation or your managed database service.
Record these details with each backup:
- The runtime version that was running.
- The last applied migration in
_sqlx_migrations. - The names of the master key variables in the configuration at that time.
Restore a backup
Stop every runtime replica.
Restore into an empty database:
pg_restore --exit-on-error --dbname="$RESTORE_DATABASE_URL" open-enterprise-runtime.dumpCheck that the runtime role has the same privileges as before.
Supply the current and previous master keys that were configured when the backup was taken.
Start the runtime version that took the backup, or a later version. An earlier version refuses to start because the database has migrations that it does not know.
Check that
/readyzreturns HTTP 200.Read a known organization and recent audit events through the API.
A restore returns the database to the backup point. Changes after that point are gone, including lifecycle events that consumers already received. Consumers must reconcile through the resource APIs. The events guide describes reconciliation snapshots.
Test restores
Restore a recent backup into an isolated database on a schedule.
Start a runtime against it with the same keys, then run the checks in steps 6 and 7.
Record the backup, the runtime version, the commands, and the results.
The v1 plan (docs/v1-plan.md) requires this evidence for its operational readiness gate.
Restoring an older snapshot
A snapshot cannot contain later revocations or consumed flows. Keep ingress closed and stop every runtime replica before restoring it. Rotate deployment service and operator keys, static directory credentials, and configured OAuth client/resource credentials in the secret store. Retain the current and previous encryption keyring needed to read the backup.
After restoring, run the offline invalidation command with the database owner's credentials:
enterprise-runtime invalidate-restored-state config.yaml --traffic-stoppedThe explicit flag acknowledges that replicas and traffic are stopped. The command commits one transaction before it returns. It disables canonical accounts, clears local password verifiers and factors, raises identity and machine epochs, and revokes restored sessions and credentials. It consumes or deletes pending flows, account links, approvals, codes and refresh state. It revokes issuer signing keys, disables webhook subscriptions and removes their delivery keys. It resets unfinished configuration tests while retaining the active configuration pointer. A deployment audit record reports the affected row counts without secret values.
Canonical user IDs, memberships, OAuth subjects, permission policy, immutable directory bindings, tombstones and known SAML replay records remain intact. Accounts require explicit review before new local or federated authentication can resume. The command cannot reconstruct revocations made after the snapshot. Reconcile current directory membership, identity-provider trust, organization policy and downstream application state before reapproving people or machines.
Supply the rotated environment credentials before restarting behind closed ingress. The issuer creates a new live signing key; revoked restored keys never return to JWKS. Review each configured SAML/OIDC connection and re-create directory and machine credentials through their supported management flows. For an approved local recovery owner, enable the account and local method, then issue a fresh link:
enterprise-runtime account config.yaml enable --user usr_approved
enterprise-runtime account config.yaml enable-local --user usr_approved
enterprise-runtime account config.yaml recover --user usr_approved --reset-factorsEnabling the method alone does not restore its old password or factors. Give the one-use recovery link to the verified holder through a trusted channel. Re-enroll required MFA before resuming protected access. Reconcile lifecycle consumers from current resource snapshots, then re-create and enable delivery subscriptions. Open ingress after these checks finish; background cleanup is insufficient.
npm run test:embedded:restore takes a real pg_dump, revokes a credential after that snapshot, and restores into a new isolated database.
It verifies the retained identity and replay state, rejects a wrong keyring, runs invalidation, and reopens an isolated listener with rotated credentials.
The test also issues an operator recovery link without SMTP.
It preserves the source database and writes sanitized results under work/embedded-evidence/.