Skip to main content
Version: Alpha

Credential keyring operations

This page is for operators who manage the encryption keys that protect credentials stored in Golf's database. It covers configuring the keyring, running the key commands, rotating to a new key under a maintenance window, and the limits of retirement and recovery.

Provider and source authority

This portable contract describes its linked source snapshot. For current deployment instructions, use current installation, authentication and native Cloudflare guides. Historical receipts do not verify later builds.

What the keyring covers​

Golf has a bounded operator workflow for re-encrypting:

  • stored PAT/OAuth/local session credentials
  • pending OAuth PKCE verifiers
  • persistent local-account forge credentials
  • immutable infrastructure profile-version credentials
  • delegated automation tokens
  • personal/instance native Codex snapshots

It retains the existing AES-256-GCM codec, adds immutable key labels and uses a database active-key policy.

note

Re-encryption does not rotate the underlying provider token, OAuth client secret, database password or Git key.

The earlier three-family native qualification follows product commit 15dc1e5. The historical keyring contract and implementation ledger distinguish the implemented maintenance workflow from unqualified rolling deployment, live OAuth exchange across activation and backup recovery.

Supply configuration securely​

Environment variablePurpose
DATABASE_URLGolf's database connection with migration/operator permissions; never Forgejo's database.
GOLF_ENCRYPTION_KEYExisting canonical padded base64 32-byte secret, configured under reserved label legacy.
GOLF_ENCRYPTION_KEYSJSON object mapping labels to canonical padded base64 32-byte secrets; maximum 16 total keys and 16 KiB JSON.
GOLF_ACTIVE_ENCRYPTION_KEYConfigured write label, required with the JSON keyring and present in it. Legacy-only configuration defaults to legacy.

Label rules:

  • 1–64 ASCII characters: start with a letter or digit, then letters, digits, ., _ or -.
  • Duplicate JSON labels are rejected.
  • If both configuration forms specify legacy material, the bytes must match.

Keep secrets out of command arguments and committed files.

Never replace the secret behind an existing label

The database permanently binds registered labels to their material. Runtime needs every key still used by any retained encrypted credential family, including expired sessions/verifiers and disabled local accounts, and its configured active label must match database policy.

Standby labels become bound on explicit activation. On a fresh JSON-only setup, explicitly activate a nonlegacy label before starting the normal server.

Compose and Helm​

Compose forwards these variables. Helm reads individually optional entries from the existing Secret so either configuration form works, but runtime still requires a valid complete keyring. Every replica must agree on the material and active policy. A Secret change does not update running processes; the chart does not automate key cutover.

Run key commands​

Build from the product checkout with make build. These are server commands, distinct from the user-facing read-only bin/golf CLI. Securely supply the database and key environment first:

./bin/golf-server keys status
./bin/golf-server keys activate
./bin/golf-server keys rotate --batch-size 100 --max-batches 10
./bin/golf-server keys retirement-check --key-id legacy

The container binary is /usr/local/bin/golf. With an already-built image and running database, a one-off command can use Compose's configured environment:

docker compose run --rm --no-deps golf keys status

Options and output​

SettingValue
--timeout (all commands)1s to 5m, default 60s
Rotation batch sizeDefault 100 total rows per batch; maximum 1,000
Rotation batches per invocationDefault 10; maximum 100
Result schemaschema_version: "golf.keys.v1", separate from golf.cli.v1
Result statescomplete, partial, eligible, failed or interrupted

Results contain safe labels and counts. No output contains key material, fingerprints, ciphertext or provider credentials.

A partial rotation can exit zero

Inspect the state and remaining counts. An interrupted command can have durable earlier batches.

What status does​

Status is not strictly read-only:

  • Opening the database applies migrations.
  • The first legacy bootstrap authenticates all existing session/verifier/local-account ciphertext before registering the material binding. It reads 500 rows per page under one locked transaction; this bounds memory, not total duration.
  • A wrong key or corrupt ciphertext fails without erasing credentials.
  • Later status is not a full nonlegacy integrity scan.

Change keys with a maintenance boundary​

  1. Preserve the current database/key recovery path. Prepare a new label and random 32-byte key while retaining all old material still needed by live rows or backups.
  2. Stop admission, drain every old Golf writer and in-flight OAuth exchange, then stop old application instances. An operator command does not discover or drain your fleet.
  3. Give the operator the complete keyring with the new configured active label. Inspect status, run activate, and inspect its result. Activation changes write policy; it does not rewrite existing ciphertext.
  4. Start only correctly configured instances with the new active label and all required read keys. Check availability and existing authenticated workflows.
  5. Run bounded rotate calls until status shows no uses of the old label. Busy locked rows may yield a partial result; resume later. Each nonempty batch commits rewritten rows and its operator event together.
  6. Run retirement-check for the old inactive label. It requires zero uses in all four credential families, including expired sessions/attempts and disabled local accounts. Only then review removal from active configuration, separately preserving secrets needed to restore older backups.
This is not transparent rolling rotation

A database trigger rejects ciphertext written with a nonactive label, and policy locks order activation against writes. That fence cannot undo a provider refresh already completed outside PostgreSQL, so draining old issuers is required. A stale in-flight issuer can still force a later sign-in if provider rotation succeeds but persistence fails.

What re-encryption preserves​

  • Session IDs, cookies, expiry and provider credentials.
  • For local accounts: passwords, mappings, roles and credential versions.

Operator events are separate from user Account activity. Their actor is the PostgreSQL role, not a verified human. Ordinary history/material-binding edits are guarded, but a database owner can alter those guards.

Local accounts​

Status additionally reports local_accounts per key; rotation reports rotated_local_accounts. Disabled accounts still retain recoverable ciphertext and block retirement. Local-account ciphertext has its own authenticated domain and immutable random binding, including under the legacy label. The isolated native local-authentication proof rotates active and disabled accounts, removes the legacy key and verifies subsequent password/source access.

Retirement and recovery limits​

An eligible retirement check records evidence. It:

  • never erases memory, environment files, backups or external secrets;
  • does not permanently disable the label or revoke provider access. The same registered material can be explicitly activated again.

The migration refuses downgrade while policy or any row uses a nonlegacy label; a permitted downgrade still drops crypto-event history and registered bindings. Do not equate binary rollback with a safe schema/key rollback.

Qualification evidence​

The qualified old-binary trial creates PAT sessions and a pending PKCE attempt on product f79bf6f, then checks byte-identical ciphertext/IDs/bindings/expiry/kinds after migration. PAT cookies survive drained activation, partial rotation, restart/resume and legacy-key removal; the pending verifier decrypts/consumes on a denied callback.

Real PostgreSQL race tests cover material/domain binding, rollback, busy rows, expired records, metadata guards and OAuth HTTP fixtures. The full real-PostgreSQL race suite passes, including the callback’s database-time expiry check after a held-row wait. The ordinary actual-provider OAuth refresh regression also passes on the final image using legacy-key configuration, with provider settings restored afterward. Neither result proves a live OAuth token exchange across a key change.

Recovery​

The canonical Docker recovery increment captures every configured key and preserves registry/policy/crypto history while invalidating restored session and PKCE ciphertext. Its native restore/restart qualification passes for the bounded canonical Docker profile; it does not prove a live OAuth exchange across recovery.

Kubernetes cutovers, mixed-version rolling activation, broader recovery, emergency compromise procedures, application age/envelope/KMS migration, secret erasure and FIPS assurance remain separate work. Backup age encryption does not replace the application credential codec.

tip

Retain historical material before discarding any key used by older backups.

Infrastructure profile credentials​

Current key availability, rotation, retirement checks and append-only crypto events also include encrypted infrastructure connection versions. Each version has a separate authenticated domain and immutable profile/version binding.

Historical versions remain required by object-backed runs after a newer profile is saved or activated. Do not discard their credentials or key material merely because the head is no longer active. Re-encryption preserves endpoint/bucket/prefix/provider bindings and does not rotate underlying S3/R2 credentials.

See infrastructure settings and the current authoritative keyring contract. The earlier pinned qualifications above remain historical evidence, not proof of every current storage/recovery combination.

Managed native Codex snapshots​

Schema022 includes encrypted native Codex auth snapshots in the existing infrastructure_connection domain with a distinct golf:codex-account:v1 connection binding. Availability/bootstrap checks, bounded rotation, usage counting and retirement include them.

Counter meaning

The existing infrastructure_connections and rotated_infrastructure_connections counters aggregate saved infrastructure profile credentials and native Codex snapshots; they are not counts solely of provider profiles.

This rotates encryption at rest, not provider access/refresh tokens; native Codex owns renewal. Account/key lifecycle database checks pass. Named instance connections retain per-connection encrypted bindings at schema023. Full schema022/schema023 encrypted backup/fresh restore remains unqualified. See personal coding-agent accounts.