Repository navigation
Conversation
…otation needs GetChatAutomationsWithWebhookSecretByOwnerID lists the rows that hold a webhook secret, and UpdateEncryptedChatAutomationWebhookSecret rewrites only the secret and its key ID. Both are system-only in dbauthz, like the chat MCP server pair, and nothing outside the dbcrypt commands calls them.
…tion InsertChatAutomation encrypts the secret and sets its key ID, and GetChatAutomationByID decrypts it. dbcrypt encrypts only in the methods it overrides, so a test now fails with the method name when a database.Store method takes or returns a WebhookSecret and dbCrypt does not override it.
… and delete Rotate and Decrypt handle a user's chat automations in the same transaction as the user's other encrypted rows, so a concurrent change of a secret fails the transaction and never writes a stale secret back. Delete blanks the secret to the empty string instead of removing the row, because a webhook row must hold a secret.
…field error A row with a key ID and data that is not base64 made the decrypt error quote the stored value. For a column that is plaintext by mistake, such as a webhook secret, that put the secret into an error message.
…hooks chatd will run the user_prompt_submit hooks when a turn starts from a message that has prompt_hooks_pending set. This adds the queries that step needs. ResolveChatMessagePromptHooks clears the flag and either rewrites the content or soft-deletes the message. InsertChatMessages and InsertChatQueuedMessageWithCreator carry the flag, and UpdateChatQueuedMessageContent clears it because an edit runs the hooks on the new content. Both soft deletes clear the flag, so a deleted row never blocks the down migration. ClearChatMessagesPromptHooks serves a context reset. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…solvePromptHooks A message keeps its prompt_hooks_pending flag when it moves from the queue into history, so chatd can run the hooks when the message starts a turn. ResolvePromptHooks is the transition that clears the flag and rewrites or soft-deletes the message. It runs from R0, R1 and R1P and does not change the status. A flagged row must be a user message visible to the user and the model, because chatd looks for flagged rows in the history the user sees. ClearContext clears the flags of the rows it hides, since those messages never start a turn. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…nked row, log the guard set
…utomations-dbcrypt
…flagged message When a generation step finds a message with prompt_hooks_pending set, it runs the user_prompt_submit hooks first, outside any transaction, and one short transaction applies the result and clears the flag. A rewrite replaces the content, a denial deletes the message and fails the chat with kind hook_denied in the same transaction, and a failure that is not a denial fails the chat and keeps the message. With hooks off the flag is cleared and the message stays as saved. If a worker dies before the transaction commits, the flag is still set and the next worker runs the hooks again. Nothing sets the flag yet, so no existing chat is affected. A manual title no longer sends a message that still waits for its hooks to a model. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…utomations-prompt-hooks
…repeat a behavior The history query skips deleted rows, so a flagged message is never deleted. Each removed test is covered by a test that a mutant of the product code turns red alone.
…de guard The guard now also finds a secret inside a named field (sqlc.embed) and a query whose SQL names webhook_secret, so a bare-column query or a parameter with another name cannot skip its override. A corrupt secret stops rotate and decrypt with a decrypt error, and a key ID cannot name an empty secret.
…very prompt Reading the prompt query for the title and summary generators sent a flagged message to a model before its hooks ran. The query now skips it. Also drop the content version input and the context boundary skip that no path can reach, and describe the transition in the state diagram.
…utomations-prompt-hooks
…utomations-prompt-hooks
…utomations-dbcrypt Drop A1's fail-closed InsertChatAutomation stub and its test: the real override and TestChatAutomations replace them.
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…rypt delete prompt
…ssion share instead of copying it
…utomations-prompt-hooks
…o tk/automations-dbcrypt
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Docs previewLinks open this pull request's preview at https://pr-32076.docs.cdr-preview.dev, which updates with each push. Check 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. Preview sites for each built commit (2)Every built commit keeps its own preview, newest first. Previews aren't indexed by search engines and are deleted when this pull request is merged or closed. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
- TestChatAutomations/KeysSet: drop the InTx twin of each case. The tx store is the same dbCrypt type, and every Rotate and Decrypt test already runs through InTx. - TestChatAutomations/KeysSet: drop the NotEqual that requireEncryptedEquals already implies. - TestChatAutomations/KeylessReplica: delete. KeysUnset, TestEncryptDecryptField/NoKeys, /MissingKey and KeysSet/EmptySecret own each branch it ran. - TestChatAutomations/DecryptErr: keep one case. TestChatAutomationsCorruptSecret and TestEncryptDecryptField/MissingKey own the corrupt data and missing key branches. - TestWebhookSecretMethodsAreOverridden: drop the list loop, which TestChatAutomationQueries/ListRowHasNoSecret owns, and the self-check on a type the test built. - TestRotateChatAutomations: drop the read-back through a cipher B store, since the raw key ID and decrypted value asserts already cover it. - TestDeleteChatAutomations: drop the CHECK recheck UPDATE, since Delete's own UPDATE must pass the CHECK. Replace the xmin loop with a value check on the plaintext row. - TestDecryptChatAutomations: drop the xmin loop. Decrypt needs coderd stopped, so a no-op rewrite has no observable effect.
…st uses them - enterprise/dbcrypt: the InsertChatAutomation webhook secret refusal and TestChatAutomationWebhookSecret go to #32076, which encrypts the secret instead. - coderd/database/migrations: the organization_id checks of enforce_chat_automation_organization, the dump.sql lines and the organization-change cases of TestChatAutomationOrganizationTrigger go to the PR that adds an organization move. - coderd/database/dbauthz: the chatd update grant on chat_automation and its direct Authorize(Update) assert go to the PR that adds the run-recording queries. - coderd/database/dbgen: chatAutomationGenCtx goes away. dbgen.ChatAutomation uses genCtx and the dbauthz test seeds its automations through rawDB.
The previous commit deleted TestChatAutomations/KeylessReplica. It was the only test that reads a pre-existing plaintext webhook secret through GetChatAutomationByID on a keyed store. A deployment that created a webhook automation before it enabled encryption stores that row as plaintext with a NULL key ID, so a broken read would fail every by-ID read of it until a rotate. Restore the case unchanged. It also covers a keyless replica that reads a sealed row, which must return DecryptFailedError and not the ciphertext. Each break below turns only this case red in `go test ./enterprise/dbcrypt/ -run TestChatAutomations`: - GetChatAutomationByID decrypts every non-empty secret under the primary key: fails at dbcrypt_internal_test.go:2499. - GetChatAutomationByID skips decryption when no cipher is loaded: fails at :2505. - decryptChatAutomation treats a key ID with no cipher as plaintext: fails at :2505. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…utomations-dbcrypt # Conflicts: # enterprise/dbcrypt/dbcrypt_internal_test.go
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Part of CODAGT-1135.
Stacked on #32067. Review only this diff. It merges after #32067.
Why
Chat automations store a webhook secret in
chat_automations.webhook_secret. dbcrypt encrypts only in the methods it overrides, so a writer without an override would store the secret in plaintext and nothing would encrypt it later. This PR makes the database layer encrypt the secret before any code writes one. As the RFC says, dbcrypt encrypts the column when the deployment sets--external-token-encryption-keys. Without keys the column holds plaintext, as it does for external auth tokens today.What changed
InsertChatAutomationencrypts the secret and setswebhook_secret_key_id.GetChatAutomationByIDdecrypts it. The list query still returns no secret.dbcrypt rotate,decryptanddeletecover the column. Two new queries serve only these commands (system actor in dbauthz).deleteblanks the secret to the empty string and keeps the row, because a webhook row must hold a secret.database.Storemethod takes or returns aWebhookSecret, or its query names the column, anddbCrypthas no override of that name. A later update or rotate query cannot forget its override.dbcrypt deleteconfirmation prompt that names the blanked webhook secrets.Scope
No handler, API type or writer of the secret. A NULL or empty secret is not encrypted: it keeps a NULL key ID and rotation skips it, like AI provider keys.
Tradeoffs
rotateanddecrypthandle a user's automations in the existing per-user transaction. If coderd rewrites a secret at the same time, the transaction fails and the command stops with an error. It never writes a stale secret back. A rerun works. The commands never changewebhook_secret_version.dbcrypt deleteleaves webhook automations enabled with an empty secret. A request must never verify against an empty secret, so the webhook route has to reject it.dbcrypt rotatehas run.Live check
On a local Enterprise build with keys set, a webhook row inserted through the dbcrypt store left no plaintext in the raw column.
dbcrypt rotate,decryptanddeletethen ran against that database and ended as intended. On a database that a running coderd has used,rotatestops at the key revoke because ofcrypto_keysrows. That gap is older than this PR (issue 25381).Generated with
xum• Model:anthropic:claude-sonnet-5-5• Thinking:xhigh