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:
| What | What changes | What does not |
|---|---|---|
| Key rotation | The keys that wrap other keys. Wrapped keys are rewritten. | The secret values themselves, and the credentials they represent. |
| Replacement schedules | A durable reminder is created when a secret is due for replacement. | Rivergate does not change the external credential. |
| Dynamic credentials | Short-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.
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}
- Requires key-management permission (organization
owner). In the dashboard, use Keys and audit and choose Rotate project key. - Progress is checkpointed transactionally with its audit event. The job exposes only IDs, key versions and counters.
- If the worker restarts mid-job, it resumes from the stored position.
- Starting a rotation while one is already running returns the same job instead of creating another.
- Secret versions created afterward use the new active key.
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.
- Back up the database and keep independent recovery copies of the current root-key directory. Choose an operator ID for audit attribution.
- Stop the API and worker, leaving PostgreSQL and Redis running.
docker compose -f rivergate-deployment/compose.yaml stop api worker - 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 - 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 - 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 - Watch progress with the job ID.
go run ./cmd/root-key-rotate --key-dir /path/to/root-keys --job "$JOB_ID" - 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.
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
- An authorized secret writer sets an interval from one hour to one year.
- 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.
- 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.
- Rollback does not complete a request. Removing the schedule or deleting the secret cancels pending work.
- Requests contain only references, status and version metadata — never values.
- Rivergate does not notify anyone. Surface pending requests through your own process.
- Rivergate does not modify the external system or assert that the real credential changed.
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.
- Role names and passwords are generated and random. The password is returned once; Rivergate never stores it.
- The credential is returned only after the lease state and its audit event are committed. If the audit write fails, nothing is returned and Rivergate attempts to revoke the role.
- Lease metadata lives in PostgreSQL. Redis is not the source of truth for expiry or revocation.
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}
- Registering returns provider metadata only. The DSN is encrypted with a random key wrapped under the organization key.
- Issue, renew and revoke require an
Idempotency-Keyheader (at least 16 allowed characters). Reusing a key cannot produce a second credential. - If a client loses a successful issue response, the password cannot be retrieved. Check the lease status, then issue a new lease or renew with a new key.
- Renewal replaces the password and terminates existing sessions for the role.
- Revocation disables login, removes the base-role membership, clears the password and terminates current sessions. Failures retry with exponential backoff and are audited.
- The role’s
VALID UNTILblocks new logins at expiry; the worker terminates remaining sessions when it processes the expiry. Keep the worker running and monitored.