#33 [Feature]: Add secret version history and rollback
Originally created by: thomijasir
Originally owned by: thomijasir
Feature description
Keep earlier encrypted versions of each secret, let people browse them, and let a project manager roll a secret back to an earlier value from the CLI or the web UI.
Current behavior
Every write bumps the secret's version number but overwrites the stored ciphertext, so earlier values are gone. Audit events say that a change happened but cannot bring the old value back.
Why we need this
A bad rotation or a broken import can take an application down right away. Operators need a quick way back to a value that worked, with an audit trail.
Design
Rollback is per secret. Restoring a whole environment to an earlier point in time is tracked separately (see the follow-up issue linked below).
Storage. A new secret_versions table gets one row per write, including the current version. Each row stores the encrypted value, the change type (created, updated, imported, rolled_back, or legacy for values that existed before the migration), the source version for rollbacks, the actor, and the time. Rows reference secrets(environment_id, key) with ON DELETE CASCADE.
Retention. The newest 20 versions of each key keep their ciphertext. Older rows keep their metadata, lose their ciphertext, and show as expired. The count is set with secret_history_versions in server.toml or DOPBASE_SECRET_HISTORY_VERSIONS (2 to 1000). Pruning runs inside each write, so a lower setting applies to a key on its next write.
Deletion. Deleting a secret, an environment, or a project removes the history for those keys. Import in replace mode removes history for the keys it deletes.
Rollback. Rollback decrypts the chosen version and saves its value as a new version (current + 1). History is never edited. The ciphertext AAD binds the version number, so old ciphertext is never copied into the current row.
Concurrency. Clients send the current version they showed the user as expectedVersion. If the secret changed in the meantime the server answers 409 SECRET_VERSION_CONFLICT and writes nothing.
API
| Method and path | Access | Notes |
|---|---|---|
GET /api/v1/environments/{id}/secrets/{key}/versions?limit=&before= |
same as secret list |
Newest first, { items, nextBefore, retainedVersions }, limit 1 to 200 (default 50). Metadata only. |
POST /api/v1/environments/{id}/secrets/{key}/versions/{version}/reveal |
project manager, recent authentication, CSRF | Returns the value of one version. Audited as secret.version_revealed. |
POST /api/v1/environments/{id}/secrets/{key}/rollback |
project manager, recent authentication, CSRF | Body { version, expectedVersion? }. Audited as secret.rolled_back. |
Errors: SECRET_NOT_FOUND, SECRET_VERSION_NOT_FOUND (404), SECRET_VERSION_IS_CURRENT (409), SECRET_VERSION_CONFLICT (409), SECRET_VERSION_EXPIRED (410).
CLI
dopbase secret history ENVIRONMENT KEY [--limit N] [--before VERSION]prints version, change, actor, time, and status (current, available, expired).dopbase secret get ENVIRONMENT KEY --version N [--reveal]shows one version's metadata or value.dopbase secret rollback ENVIRONMENT KEY [VERSION] [--yes]picks a version interactively when VERSION is left out, shows the current and target versions, asks for confirmation, then rolls back. Without a terminal, VERSION and--yesare required.
Web UI
Each row in the secrets table gets a History button. It opens a dialog that lists versions, reveals an old value after a password check (hidden again after 30 seconds), and rolls back after one confirmation. A conflict reloads the history and asks the user to try again.
Security and compatibility
- Version rows use the same envelope encryption and AAD as current secrets.
- History lists and audit events never contain values.
- Rollback and version reveal need a project manager, recent authentication for browser sessions, and the CSRF header. Runner tokens, service accounts, and agent tokens are refused.
- Master key rekeying and backup restore cover
secret_versions. Older backups get the backfill when restore migrates them. - History reads are not audited, the same as
secret list.
Out of scope
- Editing or manually redacting a version.
- Restoring a deleted secret, and rolling back a whole environment. Both move to the follow-up issue.
- Restoring runner tokens or account credentials.
Acceptance criteria
- [ ] Creates, updates, imports, project init, and rollbacks each store a version row.
- [ ] History lists metadata only, newest first, with paging.
- [ ] Rollback creates a new version and leaves earlier rows unchanged.
- [ ] Runtime serves a restored value only after the rollback commits.
- [ ] Expired, current, missing, and tampered versions cannot be restored, and nothing is written when they are rejected.
- [ ] Rollback and version reveal are audited without plaintext.
- [ ] Rekey and backup restore keep retained versions decryptable.
- [ ] CLI and web UI cover browse, reveal, and rollback.
Test scenarios
Migration and backfill, repository writes and pruning, crypto rekey, authorization and recent authentication, CSRF, API errors, concurrent updates and expectedVersion, delete and import purge, audit events, backup round trips, CLI parsing and terminal prompts, and web UI controller and component tests.
Documentation
CLI commands and cheat sheet, the web UI secrets page, the API reference, audit events, retention settings, and how version numbers, rollback, and deletion behave.
Related
- [#120] (dual-key rotation) can build on
secret_versions. - [#29] (restart
runprocesses when secrets change): after a rollback, running processes keep the old value until they restart.
Follow-up
Environment-wide rollback and restoring deleted secrets: [#135]
Originally posted by: bosd
Note for whoever implements this: [#122] (dual-key rotation, [#120]) keeps a secret's replaced value in six nullable
previous_*columns onsecrets(previous_version,previous_ciphertext,previous_value_nonce,previous_wrapped_key,previous_key_nonce,previous_expires_at). Each slot keeps the version and AAD it was encrypted with.When
secret_versionslands, the rotation slot should move into it: migrate theprevious_*data into a version row with a retire deadline and drop the columns. No re-encryption is needed, and the rotation API (previousVersion/previousExpiresAt, rotate/promote) stays the same; only the repository layer changes. See the discussion on [#120].Related
Tickets: #120
Tickets:
#122Ticket changed by: dopbase