Rivergate

Rotation and credentials

Rotate the keys that protect your secrets, schedule replacements for stored credentials, and issue short-lived database credentials on demand.

Rotation in Rivergate covers three separate things. Keep them distinct:

WhatWhat changesWhat does not
Key rotationThe keys that wrap other keys. Wrapped keys are rewritten.The secret values themselves, and the credentials they represent.
Replacement schedulesA durable reminder is created when a secret is due for replacement.Rivergate does not change the external credential.
Dynamic credentialsShort-lived database roles are created, renewed and revoked.Nothing is stored in Rivergate as a long-lived secret.

Key rotation

Key rotation re-wraps the hierarchy under new key versions. Old versions are retained, so existing secrets stay readable throughout, and each job is resumable and safe to repeat.

Rotating a key does not rotate your credentials

If a database password or API key may have leaked, change it at its source and publish the new value as a new secret version. Rewrapping protects how values are stored from now on; it cannot undo a disclosure that already happened.

Project key

Creates a new active project key and rewraps every stored data key in the project under it, in resumable PostgreSQL-backed batches.

POST /api/v1/organizations/{organization}/projects/{project}/key-rotations
GET  /api/v1/organizations/{organization}/projects/{project}/key-rotations/{job}

Organization key

Creates a new organization key and rewraps that organization’s project keys, plus the configuration keys of dynamic credential providers. Secret ciphertext and per-version data keys are unchanged.

POST /api/v1/organizations/{organization}/key-rotations
GET  /api/v1/organizations/{organization}/key-rotations/{job}

Wait for status: completed, then confirm existing secret versions still decrypt and provider configurations still load. Do not retire the old version merely because the job finished: backups may still depend on it.

Root key

Root rotation is a maintenance operation. The API and worker must be stopped while the database’s root pointer changes. Rehearse it against disposable data first.

  1. Back up the database and keep independent recovery copies of the current root-key directory. Choose an operator ID for audit attribution.
  2. Stop the API and worker, leaving PostgreSQL and Redis running.
    docker compose -f rivergate-deployment/compose.yaml stop api worker
  3. Create and activate a new immutable version, then back it up through your protected recovery process.
    go run ./cmd/root-keygen --key-dir /path/to/root-keys --version 2 --activate
  4. Create the audited rewrap job. The command records the new root version and prints a job ID.
    make -C rivergate root-key-rotate OPERATOR_ID=my-operator
  5. Start the API and worker with a keyring containing both versions. Startup validates the active root against PostgreSQL, and the worker rewraps organization keys and the OIDC configuration key in audited batches.
    docker compose -f rivergate-deployment/compose.yaml up -d api worker
  6. Watch progress with the job ID.
    go run ./cmd/root-key-rotate --key-dir /path/to/root-keys --job "$JOB_ID"
  7. Verify OIDC sign-in, secret reads, key metadata and audit integrity. Keep both root versions in protected recovery storage for every backup you may restore. Rivergate never deletes old root versions.
If startup fails mid-rotation

Restore the complete keyring including the new active version. Do not move the database pointer back by hand: some children may already be wrapped under the new root. Preserve your backups and follow a reviewed recovery procedure.

Static secret replacement schedules

Many secrets are credentials for systems Rivergate does not control. Re-encrypting the same value would not be rotation, so schedules do something honest instead: they create a durable, audited request asking a person or an approved integration to replace the credential.

PUT    .../secrets/{secret}/rotation-policy        # interval in seconds, 3600 to 31536000
GET    .../secrets/{secret}/rotation-policy
DELETE .../secrets/{secret}/rotation-policy
GET    .../secrets/{secret}/rotation-requests
  1. An authorized secret writer sets an interval from one hour to one year.
  2. When due, the worker records one pending request and a durable audit event. At most one request is pending per secret, and the schedule then advances.
  3. Someone rotates the credential at its source and publishes the replacement through the normal secret update. That new version completes the request in the same transaction.

Dynamic PostgreSQL credentials

For PostgreSQL targets, Rivergate can mint a fresh, short-lived login role on demand instead of storing a long-lived password. Each credential is a lease, one hour by default and 24 hours at most, that inherits one non-login base role you define.

1. Prepare the target

Use a dedicated PostgreSQL target, separate from Rivergate’s own database. Create a NOLOGIN base role holding only the permissions leased identities need — never an administrative or owner role. Then install the supplied security-definer functions as a target DBA:

psql "host=TARGET_HOST dbname=TARGET_DATABASE user=TARGET_DBA sslmode=verify-full" \
  --set=base_role=APP_LEASE_BASE_ROLE \
  --set=target_database=TARGET_DATABASE \
  --file=docs/operations/postgres-dynamic-credential-provider.sql

The script prompts for the password of the dedicated rivergate_dynamic_client role; keep it in a protected secret file for the Rivergate server. Grant the base role CONNECT on the target database and only the application privileges leases need.

2. Allowlist the target

Set DYNAMIC_CREDENTIAL_ALLOWED_TARGETS on both the API and the worker to a comma-separated list of exact host:port entries. Wildcards and URL patterns are rejected, and a registered DSN must match an entry. Production requires sslmode=verify-full. Also restrict API and worker network egress to those targets — an allowlisted hostname is not a substitute for egress controls.

3. Safety checks Rivergate enforces

Rivergate refuses to register a target unless SCRAM password hashing is active and the target reports that parameter and statement logging are off: log_parameter_max_length=0, log_parameter_max_length_on_error=0, log_statement=none, log_min_duration_statement=-1, log_min_duration_sample=-1, and pgaudit parameter and class logging disabled. These cover what PostgreSQL reports; you remain responsible for extensions, proxies, managed-database logs, pg_hba.conf and log collectors that might capture queries.

4. Register, issue, renew and revoke

POST   .../projects/{project}/dynamic-credential-providers            # body includes "dsn"
POST   .../dynamic-credential-providers/{provider}/leases             # {"duration_seconds":3600}
GET    .../dynamic-credential-leases/{lease}
POST   .../dynamic-credential-leases/{lease}/renew
DELETE .../dynamic-credential-leases/{lease}