Title: Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder · GitHub
Open Graph Title: Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder
X Title: Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder
Description: Secure environments for developers and their agents - Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder
Open Graph Description: Secure environments for developers and their agents - Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder
X Description: Secure environments for developers and their agents - Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder
Opengraph URL: https://github.com/coder/coder
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled","articleBody":"The per-owner limits for user secrets and the per-build limits for workspace secrets are enforced by Postgres triggers that add up `octet_length(value)`. When dbcrypt is enabled, `value` holds base64 ciphertext (nonce + plaintext + GCM tag). That is about `4/3 * (plaintext + 28)` bytes, so a stored value is roughly a third larger than its plaintext.\n\nAs a result:\n\n- **The effective limit depends on whether encryption is on.** With encryption, the 24 KiB env cap fits only about 18 KiB of plaintext, and the 200 KiB total cap fits about 150 KiB. `codersdk/usersecretvalidation.go` documents this as acceptable because stored bytes are an upper bound on what gets transmitted.\n- **Turning on encryption can break rows that already exist.** A value that fit as plaintext may go over the limit once it is encrypted:\n - **User secrets** (`trigger_user_secrets_per_user_limits`, `000509_user_secrets_limits.up.sql`): the trigger runs `BEFORE INSERT OR UPDATE`. When `coder server dbcrypt rotate` encrypts a user's secrets that are close to the cap, the UPDATE can fail with `user has reached the user secrets ... limit`.\n - **Workspace secrets** (`trigger_workspace_secrets_per_build_limits`, `000613_workspace_secrets.up.sql`, #30248): the trigger runs only on `BEFORE INSERT`, so rotate succeeds. The next build then copies the previous build's secrets forward (`persistSecrets` in `coderd/wsbuilder/wsbuilder.go`, #30250), the INSERT goes over the limit, and the build fails with a 400. Ordinary start, stop, autostart and autostop builds that don't change any secret fail too. Autostop has no user to see the 400. The only recovery is to remove a secret by name on a build.\n\nWorkspace secrets intentionally follow the user secrets model for now. This issue tracks fixing both together.\n\n## Possible approaches\n\n1. **Check plaintext size in Go.** Compute sizes from plaintext before dbcrypt encrypts the value. Keep the count check, and possibly a looser byte check, in the trigger as a backstop. For workspace secrets this is race-free, because one transaction writes all of a build's secrets. User secrets are written by concurrent API calls, so they would still need DB-side enforcement for the aggregate limits.\n2. **Store the plaintext length in a column**, such as `value_bytes`. Triggers add up that column instead of `octet_length(value)`, and dbcrypt keeps it unchanged. The DB stays the source of truth, and the limits behave the same with or without encryption.\n3. **Keep measuring stored bytes but make migrations safe.** For example, rotate checks or reports rows that would go over the limit, and workspace secret copy-forward does not re-enforce limits on values that are carried over unchanged.\n\n## Acceptance\n\n- The same plaintext secrets fit within the limits whether or not dbcrypt is enabled, or the difference is a documented and deliberate choice.\n- Enabling encryption or running `dbcrypt rotate` on near-cap data does not fail, and later workspace builds that copy those secrets forward do not fail either.\n- Regression tests for both tables: seed near-cap plaintext, enable encryption or run rotate, then update a user secret and run a workspace build.\n\nRaised in review: https://github.com/coder/coder/pull/30249#discussion_r4199073495\n\n---\n\nGenerated by Coder Agents on behalf of @Emyrk.\n\n","author":{"url":"https://github.com/Emyrk","@type":"Person","name":"Emyrk"},"datePublished":"2026-10-06T20:11:40Z","url":"https://github.com/coder/coder/issues/30441"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:7ec2e673-25d5-5d85-9635-f8e395635e10 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ABA2:1AE20C:1E76517:268BABA:6B015F0D |
| html-safe-nonce | fd8d28310506ff8e59343f5a7a69de3cf28b0af14802ae0aa4f49ccc14e812c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkEyOjFBRTIwQzoxRTc2NTE3OjI2OEJBQkE6NkIwMTVGMEQiLCJ2aXNpdG9yX2lkIjoiNjQyNzk3OTg1NjY1MDI2NDMzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f7cb0c3b3a4cb1c49cca2800442a035ee468d97357610f27e53a08db94a77780 |
| hovercard-subject-tag | repository:440752086 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/coder/coder/issues/30441 |
| twitter:image | https://repository-images.githubusercontent.com/440752086/eb56ccad-14f2-4c61-a024-20d1e77296c1 |
| twitter:card | summary_large_image |
| og:image | https://repository-images.githubusercontent.com/440752086/eb56ccad-14f2-4c61-a024-20d1e77296c1 |
| og:image:alt | Secure environments for developers and their agents - Secret byte limits measure ciphertext, which breaks near-cap secrets when dbcrypt is enabled · Issue #30441 · coder/coder |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-cache |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width