Skip to content

feat: set workspace secrets on workspace builds - #30250

Merged
Emyrk merged 7 commits into
mainfrom
steven/ws-secrets/api
Oct 15, 2026
Merged

Emyrk merged 7 commits into
mainfrom
steven/ws-secrets/api

Conversation

@Emyrk

@Emyrk Emyrk commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Lets clients set secrets when creating a workspace or a build. Secrets are saved with the build and are never sent to the provisioner. 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
  3. feat: set workspace secrets on workspace builds #30250 Set secrets on workspace builds (this PR)
  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
  • secrets is a new field on the create workspace and create build requests.
  • Each secret is delivered as an env var, a file, or both. ephemeral secrets last for one build only.
  • Secrets carry forward to every later build until a request replaces or removes them.
  • A secret set on another secret's env var or file path replaces that secret entirely.
  • A null value removes a secret, which needs update permission on the owner's workspace secrets.
  • Deleting a workspace clears its secret values.

Secrets are stored but not delivered to the agent until #30251.

Example request
POST /api/v2/workspaces/{workspace}/builds
{
  "transition": "start",
  "secrets": [
    { "name": "openai-key", "value": "sk-...", "env_name": "OPENAI_API_KEY" },
    { "name": "kubeconfig", "value": "apiVersion: v1 ...", "file_path": "~/.kube/config" },
    { "name": "session-jwt", "value": "eyJ...", "env_name": "SESSION_JWT", "ephemeral": true },
    { "name": "old-token", "value": null }
  ]
}
Implementation details
  • Validation reuses the user secret field rules and the file path delivery policy. It rejects:
    • duplicate names, env names, or file paths within one request
    • a removal that also sets a target or ephemeral
  • In the build transaction, the builder:
    1. copies the previous build's live, non-ephemeral secrets that the request does not name or take over
    2. inserts the requested secrets
    3. "Earlier builds' rows are cleared when the new build's job completes
  • Copying and clearing run as AsWorkspaceSecretManager, so autostart and other system-initiated builds work without secret permissions. Requested secrets are authorized as the build's actor.
  • Each row records source (request or carry_forward).
  • Per-build limit violations return a 400.
  • A completed delete in provisionerdserver, or an orphan delete in the builder, clears the workspace's values and keeps the rows.

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/api branch from 3beba2d to 3a43ddc Compare October 1, 2026 14:52
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from daf45ed to 35c7bbb Compare October 1, 2026 15:42
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch 2 times, most recently from 0a37eee to 7f09f79 Compare October 1, 2026 15:54
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 35c7bbb to e214652 Compare October 1, 2026 15:54
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread codersdk/workspacesecrets.go Resolved
@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/api branch from 7f09f79 to d0eaabe Compare October 2, 2026 14:27
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from f9db4b2 to 88c4bfd Compare October 5, 2026 19:43
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch 2 times, most recently from 1dbfe65 to 2ce6bf7 Compare October 5, 2026 20:10
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 88c4bfd to 21dacb4 Compare October 5, 2026 20:10
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch from 4a8b7cc to b9ebc8b Compare October 6, 2026 01:53
@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/api branch from b9ebc8b to 8ae63e0 Compare October 6, 2026 18:20
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from f21bd7c to 2eb9e1b Compare October 6, 2026 18:20
@Emyrk
Emyrk marked this pull request as ready for review October 6, 2026 18:32
@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:32 UTC by @Emyrk

Review history
  • R1 (2026-10-06): 13 reviewers, 5 Nit, 1 P1, 6 P2, 11 P3, 8 P4, REQUEST_CHANGES. Review

deep-review v0.13.0 | Round 1 | 2eb9e1b..8ae63e0

Last posted: Round 1, 31 findings (1 P1, 6 P2, 11 P3, 8 P4, 5 Nit), REQUEST_CHANGES. Review

Finding inventory

Finding inventory: PR #30250

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Open coderd/workspacesecrets.go:26 File path policy check returns user-secret wording, option description says user secrets only, untested R1 Netero, Gon Yes
CRF-2 P3 Open coderd/wsbuilder/wsbuilder.go:742 insertSecret error mapping (limits, file_path conflict, authz) untested R1 Netero Yes
CRF-3 P4 Open coderd/wsbuilder/wsbuilder.go:675 !prev.Value.Valid checks a state the schema rules out R1 Netero Yes
CRF-4 P4 Open coderd/workspaces_test.go:6727 Comment says removal uses empty value; request uses nil R1 Netero Yes
CRF-5 Nit Open coderd/workspaces_test.go:6663 AsSystemRestricted with false nolint reason; narrower context exists R1 Netero Yes
CRF-6 P1 Open coderd/wsbuilder/wsbuilder.go:702 Removal and target takeover delete secrets without actor workspace_secret authorization R1 Kurapika P1, Ryosuke P2, Mafuuu P2, Hisoka P2, Pariston P3 Yes
CRF-7 P2 Open coderd/wsbuilder/wsbuilder.go:674 Delete build copies live secret values; never cleared after soft delete R1 Knuckle, Melody, Mafuuu, Hisoka, Pariston, Ryosuke, Zoro Yes
CRF-8 P2 Open coderd/wsbuilder/wsbuilder.go:683 Ephemeral secret claiming a persistent secret's target permanently deletes it R1 Hisoka Yes
CRF-9 P3 Open coderd/wsbuilder/wsbuilder.go:683 Claiming one target of a two-target secret drops the whole secret silently R1 Melody, Pariston, Bisky, Zoro Yes
CRF-10 P3 Open codersdk/workspaces.go:132 SDK and generated API docs omit the target takeover rule R1 Leorio P3, Mafuuu P3, Gon P2, Hisoka P4 Yes
CRF-11 P2 Open coderd/workspacebuilds.go:389 Secrets accepted on stop/delete; ephemeral secret there is never delivered R1 Mafuuu Yes
CRF-12 P2 Open codersdk/workspacesecrets.go:46 Omitted value with env_name/file_path is treated as removal and passes validation R1 Chopper Yes
CRF-13 P2 Open coderd/wsbuilder/wsbuilder.go:636 Workspace secret writes and removals produce no audit entry R1 Kurapika Yes
CRF-14 P2 Open coderd/wsbuilder/wsbuilder.go:689 Copy-forward re-insert can fail limit trigger and abort stop/autostop/delete R1 Knuckle Yes
CRF-15 P3 Open coderd/wsbuilder/wsbuilder.go:668 Undecryptable live secret makes every build (stop, delete) fail with 500 R1 Hisoka Yes
CRF-16 P3 Open coderd/workspacesecrets.go:16 Secret validation lives in handlers; Builder.Secrets relies on callers R1 Ryosuke Yes
CRF-17 P3 Open coderd/workspacesecrets.go:32 Duplicate env_name/file_path in one request reach DB, no field Validations R1 Chopper P3, Zoro P3, Mafuuu P4, Leorio P4 Yes
CRF-18 P3 Open coderd/workspacesecrets.go:11 Doc says duplicate name "silently wins"; it actually fails with 500 R1 Gon P2, Leorio P4, Zoro Yes
CRF-19 P3 Open coderd/wsbuilder/wsbuilder.go:747 403 message names neither missing permission nor next step R1 Leorio Yes
CRF-20 P4 Open coderd/wsbuilder/wsbuilder.go:745 Check-violation message "rejected" names no cause R1 Chopper, Leorio Yes
CRF-21 P4 Open coderd/wsbuilder/wsbuilder.go:722 insertSecret dereferences Value; relies on comment to avoid nil panic R1 Ryosuke, Zoro Yes
CRF-22 P3 Open codersdk/workspacesecrets.go:34 Exported predicate named Remove() reads as an action R1 Gon P3, Zoro Nit Yes
CRF-23 Nit Open coderd/workspacesecrets.go:25 Shared helpers named for user secrets R1 Gon Yes
CRF-24 Nit Open coderd/wsbuilder/wsbuilder.go:625 Comments restate code or repeat the type doc (12 locations) R1 Gon Yes
CRF-25 Nit Open codersdk/workspacesecrets.go:22 Field docs use Go names in generated JSON API docs R1 Leorio Yes
CRF-26 Nit Open coderd/wsbuilder/wsbuilder.go:657 firstBuild then getLastBuild for one lookup R1 Zoro Yes
CRF-27 P4 Open codersdk/workspacesecrets_test.go:24 New code uses deprecated ptr.Ref instead of new(expr) R1 Ging-Go Yes
CRF-28 P3 Open coderd/workspaces.go:635 Create-workspace secret validation rejection never tested R1 Bisky Yes
CRF-29 P4 Open coderd/workspaces_test.go:6841 EnvNameConflict asserts only status code R1 Bisky Yes
CRF-30 P4 Open coderd/workspaces_test.go:6723 ClearedAt loop cannot fail R1 Bisky Yes
CRF-31 P4 Open coderd/wsbuilder/wsbuilder_test.go:1487 Clear expected MaxTimes(1); removing the call passes tests R1 Bisky, Gon Yes
CRF-32 Nit Dropped by orchestrator (coder/coder squash-merges; PR title becomes the commit) 8ae63e0 Commit subject vague R1 Leorio No
CRF-33 Note Note (body) coderd/workspacesecrets.go:16 Once delivered, file_path gives admins without exec a code-run path R1 Kurapika No
CRF-34 Note Note (body) codersdk/workspaces.go:132 Field ships ungated before delivery in #30251 R1 Ryosuke, Leorio No
CRF-35 Note Note (body) coderd/wsbuilder/wsbuilder.go:689 One row per secret per build, never purged R1 Knuckle No
CRF-36 Note Note (body) codersdk/workspacesecrets.go:28 Ephemeral secrets lost if their build fails R1 Pariston No
CRF-37 Note Note (body) CI 21 CI jobs fail; logs unreadable; local build and tests pass R1 Netero No
CRF-38 OOS Out of scope (body) coderd/database/migrations/000613_workspace_secrets.up.sql:94 Limit trigger measures ciphertext R1 Knuckle No
CRF-39 OOS Out of scope (body) coderd/usersecrets.go:52 DisableUserSecretFilePath flag name now also governs workspace secrets R1 Ryosuke No
CRF-40 OOS Out of scope (body) coderd/autobuild/lifecycle_executor_test.go:60 Existing ptr.Ref calls not migrated R1 Ging-Go No
CRF-41 OOS Out of scope (body) codersdk/organizations.go:263 RichParameterValues comment padded R1 Gon No

Contested and acknowledged

Round log

Round 1

Round 1, full panel. Netero: 2 P3, 2 P4, 1 Nit, no P0. Law not run (632 effective additions).
Panel (13): ging-go, kurapika, ryosuke, knuckle, melody (specialists); pariston, mafuuu (core); bisky, hisoka, chopper, gon, leorio (pool); zoro (wildcard). Multi-domain target 9-12 plus wildcard.
Cross-check: CRF-6 at P1 (Kurapika; 4 reviewers reproduced; higher wins). Gon's P2 on comment restatements downgraded to Nit (convention violation; Gon rated all 16 comment items P2) and consolidated into CRF-24. CRF-10 and CRF-18 set at P3 (keep-argument: published contract misleads clients; downgrade: consequence matches CRF-9 at P3 from four reviewers, Gon's P2 was uniform). Gon's claim that Times(1) for the clear breaks withBuild callers disproved: changing to Times(1) passes go test ./coderd/wsbuilder/. CRF-32 dropped (keep-argument: unsquashed history; drop: squash merge).
Reviewed against 2eb9e1b..8ae63e0.

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.

@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 accepts secrets on workspace create and build requests and persists them per build in wsbuilder. Findings: 1 P1, 6 P2, 11 P3, 8 P4, 5 Nit.

CI reports 21 failed jobs; the job logs could not be read from this environment. Locally, go build ./coderd/... ./codersdk/... ./enterprise/... and the new tests pass.

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

  • coderd/database/migrations/000613_workspace_secrets.up.sql:94: the per-build limit trigger measures stored ciphertext, so dbcrypt changes the effective caps and dbcrypt rotate can leave rows over them (the trigger is BEFORE INSERT only).
  • coderd/usersecrets.go:52: the DisableUserSecretFilePath flag now also governs workspace secrets, but its name says user secrets.
  • coderd/autobuild/lifecycle_executor_test.go:60: about 11 existing ptr.Ref calls were not migrated to new(expr), so new code keeps copying them.
  • codersdk/organizations.go:263: the RichParameterValues comment is padded.

Notes:

  • coderd/workspacesecrets.go:16: once #30251 delivers secrets, organization-admin and owner with NoOwnerWorkspaceExec can run code as the workspace user through a file_path such as ~/.bashrc. Template pushes already allow this, so it is a second path, not a new capability.
  • codersdk/workspaces.go:132: secrets ships ungated on two public request types; if a release includes this PR without #30251, secrets are accepted and never delivered.
  • coderd/wsbuilder/wsbuilder.go:689: copy-forward adds one row per non-ephemeral secret per build and nothing purges them. Query cost stays flat (partial live index); table size and GetWorkspaceSecretsHistory grow.
  • codersdk/workspacesecrets.go:28: ephemeral secrets are lost if the build they were set on fails or is canceled, so a retry must resend them.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread codersdk/workspaces.go Resolved
Comment thread coderd/workspacesecrets.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/workspaces_test.go Resolved
Comment thread coderd/workspaces_test.go Resolved
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 4999a47 to 8e32030 Compare October 8, 2026 15:52
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch 2 times, most recently from 33819cd to f7cb17f Compare October 12, 2026 14:59
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch from 8e32030 to 4c6093f Compare October 12, 2026 14:59
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/wsbuilder/wsbuilder.go Resolved
Comment thread coderd/apidoc/swagger.json Resolved
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch from f7cb17f to b0321fb Compare October 15, 2026 15:34
@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/api branch from 5f7311b to b51bf01 Compare October 15, 2026 17:44
@Emyrk
Emyrk force-pushed the steven/ws-secrets/dbcrypt branch 3 times, most recently from 84cc16c to 22b2580 Compare October 15, 2026 18:33
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch from 0a0afe6 to c5daedf Compare October 15, 2026 18:33
@Emyrk
Emyrk dismissed coder-agents-review[bot]’s stale review October 15, 2026 18:53

Addressed all feedback

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:03 PM UTC: Graphite rebased this pull request as part of a merge.
  • Oct 15, 7:20 PM UTC: @Emyrk merged this pull request with Graphite.

@Emyrk
Emyrk changed the base branch from steven/ws-secrets/dbcrypt to graphite-base/30250 October 15, 2026 19:01
Emyrk added a commit that referenced this pull request Oct 15, 2026
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](https://linear.app/codercom/issue/RELAY-7/agent-relay-deliver-provider-credentials-via-coder-secrets-instead-of).

**Stack** (design decisions in #30248)
1. #30248 Database schema, queries, and RBAC
2. **#30249 Encryption at rest (this PR)**
3. #30250 Set secrets on workspace builds
4. #30251 Deliver secrets to the agent
5. #30252 Docs
6. #30388 List a build's secrets
7. #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.

<details>
<summary>Implementation details</summary>

- `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 #30441.

</details>

---

*Created by Coder Agents on behalf of @Emyrk.*
@Emyrk
Emyrk changed the base branch from graphite-base/30250 to main October 15, 2026 19:01
@Emyrk
Emyrk force-pushed the steven/ws-secrets/api branch from c5daedf to 93d0747 Compare October 15, 2026 19:02
@Emyrk
Emyrk merged commit f25b629 into main Oct 15, 2026
33 checks passed
@Emyrk
Emyrk deleted the steven/ws-secrets/api branch October 15, 2026 19:20
@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