Repository navigation
Read the cluster key and bucket from the environment - #8752
Conversation
There was a problem hiding this comment.
Superseded by the review of
4819872f.
This review, of dd1d57ee
🛑 Significant concerns — One BLOCKING item: config-test.rs calls an undefined read helper, so the CLI crate's Rust test target does not compile. The production changes look correct.
Findings: 1 blocking · 1 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8752.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## BLOCKING (1)
### [Code Quality] config-test.rs calls an undefined `read` helper, so the crate's Rust test target does not compile
- **File:** src/workerd/server/cli/config-test.rs:43
## INFO (1)
### [Documentation] Clarify that the environment supplies the cluster key only when the config key is empty
- **File:** src/workerd/server/server/config.rs:2187
📋 Code Quality: 🛑 1 blocking
The new tests call an undefined read helper, so the Rust test target does not compile.
Recommendation:
- [BLOCKING] config-test.rs calls an undefined
readhelper, so the crate's Rust test target does not compile (src/workerd/server/cli/config-test.rs:43)
View full review
src/workerd/server/cli/config-test.rs:43 calls read(config), which is not defined in that module.
config-test.rsis mounted asconfig.rs's test module (#[path = "config-test.rs"] mod tests;) and starts withuse super::*;.config.rsdefines no item namedread. It definesread_file,read_stdinandread_key_file, and imports thestd::io::Readtrait.- The only
fn readin the cli directory is a private helper inwrangler-test.rs:40, which is not visible here. That helper also takesConfigby value, whilecluster_ofhas a&Config.
The tests that go through cluster_of cannot compile, so the crate's whole test target fails, existing tests included. Fix: read the message inside cluster_of, for example capnp::serialize::read_message(config.to_bytes().as_slice(), capnp::message::ReaderOptions::new()).unwrap(), or add a local helper that borrows the config.
The production logic in with_cluster_environment, read_key_file and the serve and compiled-binary paths in lib.rs looks correct.
📝 Documentation: 💬 1 info
The short-key error suggests an environment override that cannot replace a non-empty config key.
Recommendation: 💬 Optional Nits
- [INFO] Clarify that the environment supplies the cluster key only when the config key is empty (
src/workerd/server/server/config.rs:2187)
View full review
src/workerd/server/server/config.rs:2187-2188 suggests setting the key in WORKERD_CLUSTER_KEY or its file. A non-empty key in the config takes precedence, though, so the environment only helps when the config key is empty.
✅ All other checks passed
🔒 Security: ✅ LGTM
Key-file handling has a size cap and a regular-file check. The fallback runs only when serving, so compile does not embed environment secrets.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md update is consistent with the change.
⚡ Performance: ✅ LGTM
No performance concerns.
Reviewed commit: dd1d57ee
dd1d57e to
4819872
Compare
There was a problem hiding this comment.
Superseded by the review of
c3a2cf67.
This review, of 4819872f
✅ Approved — The earlier BLOCKING item, the undefined read helper in config-test.rs, is fixed: the test module now defines read(&Config) using config.rs's private helpers. The earlier note about the short-key message is addressed too, and nothing new was found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The key file is limited in size and must be a regular file. The fallback runs only when serving, so environment secrets are not embedded by compile.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md update matches the change.
📋 Code Quality: ✅ LGTM
🔄 Since last review: 2 findings resolved, 0 preserved, 0 new
The earlier BLOCKING finding is fixed. src/workerd/server/cli/config-test.rs:3-6 now defines read(&Config) using bytes_from_words and reader_options. Both are private to config.rs, and the child test module can see them through use super::*. The call clusterAuth(node, target) in cluster-test.mjs now matches the current signature.
The environment fallback runs only on the serve and compiled-binary paths, so workerd compile does not embed the key or bucket.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The short-key error message (src/workerd/server/server/config.rs:2187-2189) now says to fix the key in the config, or, for workerd serve, to leave it empty and set WORKERD_CLUSTER_KEY or a file named by WORKERD_CLUSTER_KEY_FILE. server-test.c++ expects the same text.
Reviewed commit: 4819872f
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8752 +/- ##
==========================================
- Coverage 67.30% 67.28% -0.03%
==========================================
Files 838 838
Lines 213835 213942 +107
Branches 32490 32490
==========================================
+ Hits 143927 143942 +15
- Misses 50811 50904 +93
+ Partials 19097 19096 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4819872 to
c3a2cf6
Compare
There was a problem hiding this comment.
Superseded by the review of
9fa8c668.
This review, of c3a2cf67
WORKERD_CLUSTER_BUCKET is used without trimming, so a value with a trailing newline (common from mounted ConfigMaps) gives the cluster a prefix that workerd deploy never writes to, and nodes quietly see no deployments. Also one INFO about the short-key error text.
Findings: 1 warning · 1 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8752.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Code Quality] WORKERD_CLUSTER_BUCKET is not trimmed like the key sources, so a trailing newline gives a bucket prefix that deploys never write to, and nodes quietly see no deployments.
- **File:** src/workerd/server/cli/config.rs:109
## INFO (1)
### [Code Quality] The short-key error tells the user to set WORKERD_CLUSTER_KEY even when the short key came from that variable, and it limits the advice to `workerd serve` although compiled binaries read the variables too.
- **File:** src/workerd/server/server/config.rs:2188
📋 Code Quality: ⚠️ 1 warning · 1 info
The bucket from WORKERD_CLUSTER_BUCKET is not trimmed the way the key is, so a trailing newline quietly breaks the cluster. The short-key error can also point users the wrong way.
Recommendation: 📝 Minor Comments
- [WARNING] WORKERD_CLUSTER_BUCKET is not trimmed like the key sources, so a trailing newline gives a bucket prefix that deploys never write to, and nodes quietly see no deployments. (
src/workerd/server/cli/config.rs:109) - [INFO] The short-key error tells the user to set WORKERD_CLUSTER_KEY even when the short key came from that variable, and it limits the advice to
workerd servealthough compiled binaries read the variables too. (src/workerd/server/server/config.rs:2188)
View full review
🔄 Since last review: 0 findings resolved, 0 preserved, 2 new (both raised by @ry [non-author] in the discussion and confirmed against the code)
The earlier fix still holds: config-test.rs defines its own read(&Config) helper, and the cluster test matches the clusterAuth(node, target) signature.
Bucket value is not trimmed (src/workerd/server/cli/config.rs:108-112)
Both key sources go through non_blank, which strips trailing whitespace (config.rs:181-185). var(CLUSTER_BUCKET) is used exactly as given. The bucket prefix code trims only / (cluster/bucket.rs:521). A bucket that ends in \n, which is common for a YAML | value or a ConfigMap built --from-file, gives the prefix cluster\n, while workerd deploy --bucket s3://b/cluster writes under cluster/. The nodes then never see a deployment, and nothing reports an error. A whitespace-only value also skips the "cluster.bucket is not set" error.
Short-key message (src/workerd/server/server/config.rs:2186-2193)
The length check runs after the environment fill. When the short key came from WORKERD_CLUSTER_KEY or the key file, the message tells the user to set those variables, which they already did. It also says the variables apply to workerd serve, but a binary from workerd compile reads them too.
✅ All other checks passed
🔒 Security: ✅ LGTM
The key file must be a regular file, and the read is capped at 4096 bytes, so a FIFO or device cannot hang the process. Setting both WORKERD_CLUSTER_KEY and WORKERD_CLUSTER_KEY_FILE is rejected. Error messages name the variable and path but never print the key. The fallback runs only when serving, so workerd compile never embeds the key from the environment.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md update matches the change.
⚡ Performance: ✅ LGTM
The environment fallback runs once at startup, and once per config reload under --watch. It re-serializes the config at most once and reads a key file of at most 4096 bytes.
📝 Documentation: ✅ LGTM
The workerd.capnp comments, the serve help and AGENTS.md describe the new environment fallback. The wording of the short-key error is covered in the Code Quality section.
Reviewed commit: c3a2cf67
A cluster node's config had to hold the cluster key, so a container image built from it, or a binary from `workerd compile`, carried the secret, and one image could not serve two clusters. `serve` now fills an empty `cluster.key` from WORKERD_CLUSTER_KEY, or from the file that WORKERD_CLUSTER_KEY_FILE names, such as a mounted Kubernetes Secret, ignoring trailing whitespace in either. The file must be a regular file of at most 4096 bytes that holds UTF-8 text. An empty `cluster.bucket` falls back to WORKERD_CLUSTER_BUCKET. Values in the config win, as they do for `bucketOptions`. The fallback runs in the serve path only, for a config file and for a binary from `workerd compile`, so `compile` never embeds the environment. A key or bucket that neither the config nor the environment sets ends the process with an error that names the variables. It does so under `--watch` too, since the fix may lie outside the config files.
c3a2cf6 to
9fa8c66
Compare
There was a problem hiding this comment.
✅ Approved — Both earlier findings (bucket trimming and the short-key error text) are fixed at this commit, and no new issues were found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The key file must be a regular file and is read with a 4096-byte cap. Setting both key variables is rejected. Errors never print the key. compile never embeds the key from the environment.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md update matches the change.
📋 Code Quality: ✅ LGTM
The bucket value is now trimmed by non_blank like the key sources (cli/config.rs:109), and tests cover a trailing newline and a blank value. cluster_key checks the key length itself and names where the key came from. The server's message (server/config.rs:2186-2191) now covers only a key set in the config.
⚡ Performance: ✅ LGTM
The fallback runs once at startup, and once per reload under --watch. It re-serializes the config at most once and reads a key file of at most 4096 bytes.
📝 Documentation: ✅ LGTM
The workerd.capnp comments and the serve help describe the environment fallback accurately.
Reviewed commit: 9fa8c668
A cluster node's config had to hold the cluster key, so a container
image built from it, or a binary from
workerd compile, carried thesecret, and one image could not serve two clusters.
cluster.keyis filled fromWORKERD_CLUSTER_KEY, or fromthe file that
WORKERD_CLUSTER_KEY_FILEnames, such as a mountedKubernetes Secret. An empty
cluster.bucketis filled fromWORKERD_CLUSTER_BUCKET. Values in the config win, as they do forbucketOptions.Trailing whitespace is ignored in the key, from either source, and in
the bucket, as from a mounted ConfigMap.
names its source.
binary from
workerd compile, socompilenever embeds theenvironment.
serveexits with an error naming the variables, under
--watchtoo.servehelp, AGENTS.mdComments in code files are counted with that file, except the
workerd.capnpcomments and the help text, which are documentation.