Repository navigation
feat: list a workspace build's secrets in coder secret list - #30388
Conversation
38c2f85 to
ae98426
Compare
560c559 to
2095f9d
Compare
|
8a7ae6d to
5269937
Compare
ae98426 to
1dd73cd
Compare
5269937 to
94384b5
Compare
|
/coder-agents-review |
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 1 | Last posted: Round 1, 33 findings (2 P2, 10 P3, 14 P4, 7 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #30388Findings
Contested and acknowledgedLaw analysisNot run. Effective additions 845 (threshold 1000). Round logRound 1Netero first pass: 1 P2, 2 P3, 5 P4, 1 Note. No P0, panel proceeds. Full panel (round 1). Multi-domain (Go, SQL, TS fixtures, auth-scoped endpoint), target 9-12. Specialists triggered: ging-go, ging-ts, ging-react, knuckle, kurapika, ryosuke, melody, nami, luffy. Core: pariston, mafuuu. Pool: bisky (tests changed, required), gon and leorio (round 1 floor). Wildcard: knov (random from distilled set). 15 reviewers; size exceeded because nine specialists triggered plus Bisky required and the Gon/Leorio floor. Cross-check: CRF-10 raised to P2 from five convergent P3s; consequence chain is wrong API answer plus on-disk winner still decided by manifest order, with no test (CRF-14). CRF-11 is a structural alternative that removes CRF-1 and CRF-15. Gon's P2 comment-restatement findings downgraded to Nit (convention, no behavior consequence) and combined into CRF-29; cli/secret.go:602 excluded because Leorio judged it useful and 630 is covered by CRF-13. Kurapika's authorization note, Ryosuke's structure note, and Bisky's test-authenticity note are confirmations, not findings. Reviewed against ea16e35..09bd487. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR adds a workspace build's secrets to coder secret list and moves user/build precedence into workspacesecrets.Resolve. Findings: 2 P2, 10 P3, 14 P4, 7 Nit.
The two P2s: file targets are compared as raw strings while the agent compares expanded, cleaned paths, so the listing can say a user secret's file is delivered when a build secret overwrites it; and the CLI errors inside a workspace when logged in as a different user who can read it. Moving the listing to a build-scoped route would remove that second error and the owner-mismatch 400.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/database/queries/workspace_secrets.sql:91: with no build filter, the history query has only a partial (cleared_at IS NULL) index leading withworkspace_id, so it scans cleared rows, which grow with every build.agent/agent.go:1643: the comment says file-collision order is alphabetical fromListUserSecretsWithValues, but the manifest lists user secrets then build secrets, so it names the wrong winner.coderd/wsbuilder/wsbuilder.go:649: copy-forward comparesfile_pathas raw strings, so~/a//band~/a/bare both kept and the agent writes both to one file.
Notes:
- The Go alias
UserSecret = WorkspaceSecretis generated as a second TypeScript interface, not an alias (site/src/api/typesGenerated.ts:11793). workspace_secrets.sql:92: the@workspace_build_id = nil OR ...filter usesworkspace_secrets_build_name_idxonly with a custom plan. lib/pq plans at bind time, so this holds today; a generic plan measured a sequential scan (36.8 ms vs 0.09 ms on 1M rows).
docs/user-guides/user-secrets.md:307
P3 [CRF-18] The user guide says the enabled column shows "which secrets are currently injected", which this PR makes false for a replaced user secret, and the guide does not mention build rows, the source and replaced by columns, or --workspace/--build-id. (Leorio)
Inside a workspace the command now lists rows the user never created, and this is the page they will open to find out why. Update the paragraph to describe build rows and the replaced-by rule, and add the build-over-user precedence to docs/admin/security/secrets.md:52-70, which only covers user secret versus template precedence.
🤖
🤖 This review was automatically generated with Coder Agents.
Documentation CheckUpdates Needed
Automated review via Coder Agents |
ea16e35 to
33ed593
Compare
176d080 to
753af38
Compare
33ed593 to
24e6709
Compare
753af38 to
84de5ab
Compare
24e6709 to
32bc85e
Compare
53ffbbb to
2ec6df6
Compare
e375d66 to
d850a41
Compare
2ec6df6 to
72923e9
Compare
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.*
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](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 3. **#30250 Set secrets on workspace builds (this PR)** 4. #30251 Deliver secrets to the agent 5. #30252 Docs 6. #30388 List a build's secrets 7. #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. <details> <summary>Example request</summary> ```json 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 } ] } ``` </details> <details> <summary>Implementation details</summary> - 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. </details> --- *Created by Coder Agents on behalf of @Emyrk.*
d850a41 to
67f8160
Compare
Delivers workspace secrets to the agent, so they show up as env vars and files in the workspace. 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 3. #30250 Set secrets on workspace builds 4. **#30251 Deliver secrets to the agent (this PR)** 5. #30252 Docs 6. #30388 List a build's secrets 7. #30459 Audit a build's secrets - The agent receives the secrets of the build that created it, alongside the owner's user secrets. - A workspace secret wins over a user secret on the same env var or file path. - An agent from an older build gets no workspace secrets. - The agent itself needs no changes. <details> <summary>Implementation details</summary> - `GetManifest` finds the agent's build through its resource and provisioner job, then lists that build's live secrets as `AsWorkspaceSecretManager`. - In this PR, precedence comes from order: user secrets are emitted first and workspace secrets after, so the agent applies the workspace value last. #30388 replaces this with `workspacesecrets.Resolve`, which decides one winner per target and is shared with the build secrets API. - The deployment's file path policy applies to both kinds of secret. When file delivery is blocked, a file-only secret is dropped. </details> --- *Created by Coder Agents on behalf of @Emyrk.*
Adds a short "Workspace secrets" section to the secrets security page, explaining what workspace secrets are and how they differ from template parameters. 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 3. #30250 Set secrets on workspace builds 4. #30251 Deliver secrets to the agent 5. **#30252 Docs (this PR)** 6. #30388 List a build's secrets 7. #30459 Audit a build's secrets - Workspace secrets are set on the create workspace or create build request. - They never reach the provisioner, so they stay out of build parameters, Terraform state, insights, and metrics. - The agent delivers them the same way as user secrets, and they can't be read back through the API. The section is intentionally brief. The API reference covers the request fields. --- *Created by Coder Agents on behalf of @Emyrk.*
72923e9 to
491f240
Compare
67f8160 to
5261723
Compare

coder secret listnow shows the current workspace build's secrets next to your user secrets, and which user secrets they replace. Part of RELAY-7.Stack (design decisions in #30248)
GET /workspacebuilds/{workspacebuild}/secretslists a build's secrets (metadata only, never values) and which user secret each one replaces.coder secret listincludes the current build's secrets. Outside a workspace, use--workspaceor--build-id.CODER_WORKSPACE_BUILD_ID, so the CLI knows which build it is running in.Implementation details
workspace_build_id; the agent sets it asCODER_WORKSPACE_BUILD_ID.coderd/workspacesecrets.Resolve(user, build, policy)decides which secret is delivered on each env var and file. The manifest no longer relies on entry order.codersdk.WorkspaceSecretembedsUserSecretand addsworkspace_build_id,ephemeral,cleared_at,env_replaces, andfile_replaces. Secrets whose values a later build cleared are still listed, withcleared_atset.sourceandreplaced byare shown by default only when a build is included;ephemeralis opt-in. The CLI makes two requests: user secrets, then build secrets.CODER_WORKSPACE_IDand its latest build.Decision log
(existing decision log, unchanged)
Created by Coder Agents on behalf of @Emyrk.