feat: add enable/disable support for user secrets - #27537
Conversation
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
c99977f to
a9d7b61
Compare
Documentation CheckRe-checked at Updates Needed
New in this push
No outstanding documentation work. Automated review via Coder Agents |
dylanhuff-at-coder
left a comment
There was a problem hiding this comment.
Overall looks good, left two comments
| if req.Enabled != nil { | ||
| postEnabled = *req.Enabled | ||
| } | ||
| if postEnabled && postEnvName == "" && postFilePath == "" { |
There was a problem hiding this comment.
I think this may introduce a race condition. If two concurrent PATCHes can both read a secret with env and file targets, separately clear one target, pass this check, and serialize to an enabled row with neither target.
There was a problem hiding this comment.
Yep you're right. I added a database constraint to seal this hole up.
| delete Delete a secret | ||
| list List secrets, or show one by name | ||
| update Update a secret | ||
| create Create a secret |
There was a problem hiding this comment.
It would be nice to have enabled be passed as a flag to create and update
There was a problem hiding this comment.
Def worth it for ergonomics. Added.
Adds an enabled flag to user secrets so users can temporarily stop a secret from being injected into workspaces without deleting it. - Add enabled BOOLEAN NOT NULL DEFAULT true to user_secrets. Existing rows with both env_name and file_path empty are migrated to enabled = false, preserving their current not-injected behavior. - Require at least one of env_name or file_path on every write. Explicit enabled = false is now the only way to express "stored but not injected"; the agent manifest layer no longer special-cases both-empty rows and instead skips disabled secrets. - Expose enabled through the REST API (POST default true, PATCH toggle), codersdk, and generated site types. - Track enabled in the audit log field map. - Add coder secret enable <name> and coder secret disable <name>. Existing sessions keep injected values until the agent manifest is refetched (workspace restart); live revocation is tracked separately. Deprecation note: PATCHes that clear both env_name and file_path used to silently disable injection and now return 400 with guidance to use enabled = false instead.
Adds a per-row Switch control on the user secrets management page so a user can enable or disable each secret. Disabled secrets remain visible and editable but are not injected into workspaces. A target-less secret (no environment variable and no file path) cannot be enabled from the UI; the toggle is disabled with a tooltip prompting the user to add an injection target first. This mirrors the API invariant that an enabled secret must have at least one target. Toggle failures are surfaced via toast. Storybook stories cover the submit, error, and target-less tooltip cases.
…atabase Close a read-modify-write race in the user secret PATCH handler. The handler computes the post-update env_name/file_path/enabled from a stale pre-read, so two concurrent PATCHes that each clear a different target could both pass the check and serialize to an enabled row with no target. Add a user_secrets_enabled_requires_target CHECK constraint (NOT enabled OR env_name <> '' OR file_path <> '') as the race-safe source of truth, and map the violation to the same 400 the API returns. Also add CLI ergonomics and docs requested in review: - coder secret create/update gain an --enabled flag; --enabled=false stores a secret without injecting it. - coder secret list gains an enabled column. - Document the enabled field, disable semantics, and the new commands in the user secrets guide and admin secrets overview. Add a constraint regression test and update tests that created target-less enabled secrets to be disabled.
907bb7f to
ae9168b
Compare
Adds an enabled flag to user secrets so a secret can be stored but temporarily kept out of workspaces without deleting it. The first commit adds the backend changes, the second commit adds the enable/disable toggle to the user secrets management page
Behavior
REST API / SDK / CLI / UI
Behavior notes