Skip to content

feat(enterprise/dbcrypt): encrypt workspace secrets - #30249

Merged
Emyrk merged 2 commits into
mainfrom
steven/ws-secrets/dbcrypt
Oct 15, 2026
Merged

Emyrk merged 2 commits into
mainfrom
steven/ws-secrets/dbcrypt

Conversation

@Emyrk

@Emyrk Emyrk commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Encrypts workspace secret values at rest with the existing database encryption keys, and adds workspace secrets to the coder server dbcrypt commands. Part of RELAY-7.

Stack (design decisions in #30248)

  1. feat: add workspace secrets table, queries, and RBAC #30248 Database schema, queries, and RBAC
  2. feat(enterprise/dbcrypt): encrypt workspace secrets #30249 Encryption at rest (this PR)
  3. feat: set workspace secrets on workspace builds #30250 Set secrets on workspace builds
  4. feat: deliver workspace secrets in the agent manifest #30251 Deliver secrets to the agent
  5. docs(docs/admin/security): document workspace secrets #30252 Docs
  6. feat: list a workspace build's secrets in coder secret list #30388 List a build's secrets
  7. feat(coderd): list workspace secrets on workspace build audit entries #30459 Audit a build's secrets
  • Values are encrypted when a secret is written and decrypted when it is read.
  • dbcrypt rotate and dbcrypt decrypt re-encrypt or decrypt workspace secrets, 1,000 at a time.
  • dbcrypt delete clears workspace secret values instead of deleting the rows, so build history is kept.
Implementation details
  • InsertWorkspaceSecret and UpdateEncryptedWorkspaceSecretValue encrypt, and ListActiveWorkspaceSecrets and GetWorkspaceSecrets decrypt. Only live rows reach these paths, so there is no NULL handling.
  • Rotate and decrypt page through GetWorkspaceSecrets by id, so memory is bounded on large deployments. Only live rows are listed, about one set per workspace.
  • If a build clears a row between the list and the update, the update matches no row and that row is skipped.
  • Secret size limits count stored ciphertext bytes, the same as user secrets. Fixing that for both is tracked in Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled #30441.

Created by Coder Agents on behalf of @Emyrk.

@linear-code

linear-code Bot commented Oct 1, 2026

Copy link
Copy Markdown

RELAY-7

@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from a970b35 to daf45ed Compare October 1, 2026 14:52
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from 87d458e to e66489e Compare October 1, 2026 14:52
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from e66489e to d8181da Compare October 1, 2026 15:42
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch 2 times, most recently from 35c7bbb to e214652 Compare October 1, 2026 15:54
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from d8181da to 23c9372 Compare October 1, 2026 15:54
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from e214652 to f9db4b2 Compare October 2, 2026 14:27
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch 2 times, most recently from e4c9015 to 192d209 Compare October 5, 2026 19:43
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch 2 times, most recently from 88c4bfd to 21dacb4 Compare October 5, 2026 20:10
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 21dacb4 to f21bd7c Compare October 6, 2026 01:53
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from a7199ed to 89ea493 Compare October 6, 2026 01:53
@Emyrk

Emyrk commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-10-06 18:15 UTC by @Emyrk

Review history
  • R1 (2026-10-06): 12 reviewers, 7 Nit, 1 P1, 1 P2, 5 P3, 4 P4, REQUEST_CHANGES. Review

deep-review v0.13.0 | Round 1 | 89ea493..f21bd7c

Last posted: Round 1, 18 findings (1 P1, 1 P2, 5 P3, 4 P4, 7 Nit), REQUEST_CHANGES. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Open dbcrypt.go:1104 ListActiveWorkspaceSecrets wrapper untested R1 Netero Yes
CRF-2 P3 Open cliutil_test.go:1642 TestDeleteWorkspaceSecrets passes if rows are deleted R1 Netero Yes
CRF-3 P4 Open dbcrypt.go:1083 Unreachable NULL branches in encrypt/decrypt helpers R1 Netero Yes
CRF-4 P4 Open cliutil.go:250 ErrNoRows and skip branches in Rotate/Decrypt uncovered R1 Netero Yes
CRF-5 Note Note (body) cliutil.go:531 dbcrypt delete changes meaning of cleared_at R1 Netero No
CRF-6 P1 Open dbcrypt.go:1091 Per-build byte caps measure ciphertext; copy-forward of plaintext-era secrets fails every later build R1 Mafuuu P1, Ryosuke P2, Knuckle P2, Pariston P2, Hisoka P2, Kurapika P3, Kite Note Yes
CRF-7 P4 Open cliutil.go:235 Rotate/Decrypt load all workspace secret values in one call R1 Hisoka P4, Ryosuke Note, Knuckle Note Yes
CRF-8 P3 Open database-encryption.md:22 Encrypted fields list omits workspace_secrets.value; no stack PR adds it R1 Gon P3, Leorio P3, Mafu-san P3, Mafuuu P4 Yes
CRF-9 P3 Open server_dbcrypt.go:201 dbcrypt delete prompt and docs do not mention clearing workspace secrets R1 Leorio, Mafu-san Yes
CRF-10 Nit Open cliutil.go:554 Delete doc comment omits workspace_secrets clear R1 Leorio Yes
CRF-11 P3 Open cliutil_test.go:1815 TestFullLifecycleAllHandledTables does not seed workspace_secrets R1 Bisky Yes
CRF-12 P4 Open cliutil_test.go:380 Rotate OK and Decrypt tests never check seed is encrypted under A R1 Bisky Yes
CRF-13 Nit Open cliutil_test.go:426 SkipsCleared test is a query test in the CLI test file; comment restates assertions R1 Bisky, Gon Yes
CRF-14 P3 Open cliutil_test.go:1645 Comment claims row retention is checked; assertion does not check it R1 Gon P2 Yes
CRF-15 Nit Open cliutil_test.go:1620 TestDeleteWorkspaceSecrets doc omits that Delete clears in place R1 Gon P2 Yes
CRF-16 Nit Open cliutil_test.go:369 Rotate/Decrypt test docs restate test names (369, 1597) R1 Gon P2 Yes
CRF-17 Nit Open cliutil.go:492 "explicitly clear the key id" omits that empty primary cipher writes plaintext R1 Gon P2 Yes
CRF-18 Nit Open cliutil.go:529 SQL comment restates the UPDATE R1 Gon P2 Yes
CRF-19 Nit Open dbcrypt.go:1080 Helper docs narrate bodies and duplicate the cleared-row fact (1062, 1080) R1 Gon P2 Yes
CRF-20 P2 Dropped by orchestrator (Leorio judged the same comments useful: they name the race and why skipping is correct) cliutil.go:251 ErrNoRows comments carry a filler clause (251, 495) R1 Gon No
CRF-21 OOS Out of scope (body) dbcrypt.go:1038 ~20 hand-written decrypt slice loops could share one generic helper R1 Ging-go No
CRF-22 OOS Out of scope (body) 000509_user_secrets_limits.up.sql:103 user_secrets caps measure ciphertext on INSERT OR UPDATE; rotate may abort R1 Ryosuke, Pariston, Knuckle No
CRF-23 OOS Out of scope (body) 000613_workspace_secrets.up.sql:124 Per-build trigger is BEFORE INSERT only R1 Hisoka No
CRF-24 OOS Out of scope (body) cliutil_test.go:1815 Lifecycle test table list is hand-maintained and already misses chat_mcp_servers R1 Bisky No
CRF-25 OOS Out of scope (body) server_dbcrypt.go:201 Delete prompt already omitted user secrets, SSH keys, MCP headers, AI provider keys R1 Leorio, Mafu-san, Gon No
CRF-26 OOS Out of scope (body) database-encryption.md:22 Encrypted list already omitted ai_providers and AI provider key columns R1 Leorio, Mafu-san, Gon No
CRF-27 OOS Out of scope (body) cliutil.go:517 sqlDeleteEncryptedUserTokens and Decrypt doc names under-describe scope R1 Gon No

Contested and acknowledged

Round log

Round 1

Full panel (round 1). Netero first pass: 1 P2, 1 P3, 1 P4, 2 Notes, no P0, so panel proceeded. Panel: ging-go, ryosuke, knuckle, kurapika, pariston, mafuuu, bisky, gon, leorio, hisoka, mafu-san, wildcard kite (12; multi-domain target 9-12: Go plus SQL, security-sensitive encryption). Orchestrator verified the copy-forward in #30250 (persistSecrets in wsbuilder runs on every build transition and re-inserts through InsertWorkspaceSecret), and verified #30252 does not add workspace_secrets.value to database-encryption.md. CRF-6 settled at P1 (highest panel rating; stop, autostop, and delete builds blocked). Gon's comment findings downgraded to Nit except CRF-14 (misleading). Reviewed against 89ea493..f21bd7c.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@Emyrk
Emyrk marked this pull request as ready for review October 6, 2026 18:15
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from f21bd7c to 2eb9e1b Compare October 6, 2026 18:20
@coderagents

coderagents Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/admin/security/database-encryption.md (open) - workspace_secrets.value is now an encrypted database field (encrypted on insert, covered by dbcrypt rotate and dbcrypt decrypt, cleared by dbcrypt delete), but the "currently encrypted" database fields list on this page does not include it. The stack's docs PR (docs(docs/admin/security): document workspace secrets #30252) documents workspace secrets in docs/admin/security/secrets.md but does not update this list.

Automated review via Coder Agents

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR encrypts workspace_secrets.value through dbcrypt and adds the table to dbcrypt rotate, decrypt, and delete. Findings: 1 P1, 1 P2, 5 P3, 4 P4, 7 Nit.

The wrapper set is complete: every query that reads or writes value is wrapped, and GetWorkspaceSecretsHistory selects no value. The P1 is the interaction between encryption and the per-build byte caps in the enforce_workspace_secrets_per_build_limits trigger.

Out of scope (needs a ticket or explicit acceptance by a human):

  • enterprise/dbcrypt/dbcrypt.go:1038: about 20 hand-written decrypt loops over slices repeat the same shape; each new encrypted table adds another copy.
  • coderd/database/migrations/000509_user_secrets_limits.up.sql:103: user_secrets caps also measure stored bytes and run BEFORE INSERT OR UPDATE, so dbcrypt rotate may stop with a check violation at a user whose plaintext env secrets exceed about 18.4 KiB (inferred, not run).
  • coderd/database/migrations/000613_workspace_secrets.up.sql:124: the per-build trigger runs BEFORE INSERT only, so any UPDATE that rewrites value skips the caps.
  • enterprise/dbcrypt/cliutil_test.go:1815: the lifecycle test's table list is maintained by hand and already misses chat_mcp_servers; deriving it from foreign keys to dbcrypt_keys would keep it current.
  • enterprise/cli/server_dbcrypt.go:201: the delete prompt already omitted user secrets, Git SSH keys, MCP server headers, and AI provider keys, so operators confirm without the full list of what is destroyed.
  • docs/admin/security/database-encryption.md:22: the encrypted-fields list already omitted the ai_providers and AI provider key columns.
  • enterprise/dbcrypt/cliutil.go:517: sqlDeleteEncryptedUserTokens and the Decrypt doc describe only user tokens, but both cover many more tables.

Notes:

  • enterprise/dbcrypt/cliutil.go:531: dbcrypt delete sets cleared_at on the latest build's live rows, so cleared_at no longer means only "superseded by a later build" as the column comment in 000613 says, and history readers cannot tell the two apart.

docs/admin/security/database-encryption.md:22

P3 [CRF-8] The list of encrypted fields does not include workspace_secrets.value, and no PR in this stack adds it. (Gon, Leorio, Mafu-san, Mafuuu)

Operators use this list to see what rotate, decrypt, and delete touch. #30252 changes only docs/admin/security/secrets.md. Add - `workspace_secrets.value` here, in the PR that adds the encryption.

🤖

enterprise/cli/server_dbcrypt.go:201

P3 [CRF-9] The dbcrypt delete confirmation prompt does not say the command now clears workspace secret values. (Leorio, Mafu-san)

After confirming, running workspaces lose the secrets in their agent manifest until a build supplies them again, and the prompt lists only OAuth and Git auth tokens. Add a line such as - Encrypted workspace secret values (rows are kept; values are cleared), and update database-encryption.md:185, which says the command "will delete all encrypted user tokens".

🤖

enterprise/dbcrypt/cliutil_test.go:1815

P3 [CRF-11] TestFullLifecycleAllHandledTables does not seed a workspace_secrets row, so its doc comment ("seeds one row in every table Rotate/Decrypt/Delete actually loop over") is false after this PR. (Bisky)

With workspaceSecrets = nil inserted before the decrypt loop, this test passes and only TestDecryptWorkspaceSecrets fails. Seed a workspace secret through cryptDBA and assert it is under cipherB after rotate and plaintext after decrypt.

🤖

enterprise/dbcrypt/cliutil.go:554

Nit [CRF-10] The Delete doc comment says it "deletes all user tokens", and after this PR it also clears workspace secret values in place. (Leorio)

Suggested: "Delete removes or clears every encrypted value and revokes all ciphers. Rows in gitsshkeys, ai_providers, and workspace_secrets are kept with their encrypted columns cleared; rows in the other tables are deleted."

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread enterprise/dbcrypt/dbcrypt.go Resolved
Comment thread enterprise/dbcrypt/dbcrypt.go Resolved
Comment thread enterprise/dbcrypt/cliutil_test.go Resolved
Comment thread enterprise/dbcrypt/cliutil_test.go Resolved
Comment thread enterprise/dbcrypt/dbcrypt.go Resolved
Comment thread enterprise/dbcrypt/cliutil_test.go Resolved
Comment thread enterprise/dbcrypt/cliutil_test.go Resolved
Comment thread enterprise/dbcrypt/cliutil.go Resolved
Comment thread enterprise/dbcrypt/cliutil.go Resolved
Comment thread enterprise/dbcrypt/dbcrypt.go Resolved
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch 2 times, most recently from 0e26c17 to 97253a3 Compare October 7, 2026 10:01
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from e1c97c8 to 8e4631d Compare October 7, 2026 22:33
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch 2 times, most recently from 4999a47 to 8e32030 Compare October 8, 2026 15:52
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from 8e4631d to 6ddd097 Compare October 8, 2026 15:52
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 8e32030 to 4c6093f Compare October 12, 2026 14:59

@dylanhuff-at-coder dylanhuff-at-coder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 4c6093f to a72ce46 Compare October 15, 2026 15:34
@Emyrk
Emyrk force-pushed the steven/ws-secrets/db branch from 9a091b9 to f2c82bf Compare October 15, 2026 17:44
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from a72ce46 to 31c6268 Compare October 15, 2026 17:44
@Emyrk
Emyrk changed the base branch from steven/ws-secrets/db to graphite-base/30249 October 15, 2026 18:32
@Emyrk
Emyrk force-pushed the graphite-base/30249 branch from f2c82bf to 7aef110 Compare October 15, 2026 18:33
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 31c6268 to 84cc16c Compare October 15, 2026 18:33
@graphite-app
graphite-app Bot changed the base branch from graphite-base/30249 to main October 15, 2026 18:33
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 84cc16c to 22b2580 Compare October 15, 2026 18:33

Emyrk commented Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Merge activity

  • Oct 15, 7:00 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 15, 7:01 PM UTC: @Emyrk merged this pull request with Graphite.

@Emyrk
Emyrk merged commit 58a71f6 into main Oct 15, 2026
30 checks passed
@Emyrk
Emyrk deleted the steven/ws-secrets/dbcrypt branch October 15, 2026 19:01
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants