Repository navigation
Do not let the node's umask decide who can read a segment - #404
Merged
Merged
Conversation
Both of these were found by enabling segbuild on the mainnet node and reading
what it actually did, which is the only way either would have surfaced.
The node runs under `UMask=0077`. Sensible hardening, and the builder inherited
it, so the first segment it produced was `drwx--S---`: correct, verified, and
openable by nothing but the node.
drwx--S--- 909-9420001-9429888 <- built by the node
-rw------- BOUNDARIES
-rw------- BUILT
drwxrwsr-x 055-5849091-5895185 <- built offline, under a normal umask
That is the worst shape a failure can take here, because it is silent and it
looks like something else. The build log says 9,888 blocks and 9,888 state roots
verified, which is true. A consumer then gets a permission error, which looks
nothing like "this segment is fine, you just cannot read it" -- and `du` reports
1 MB, because it cannot descend. The set exists to be read by other processes,
so the mode is now set explicitly after the rename rather than inherited: 0755
for directories, 0644 for files, and the same for the logs, which are
operational state a human and the offline tools read. Loosening the unit's umask
would have been the wrong fix; the node's hardening is not the problem.
Best-effort and not fatal: a segment that is correct but awkwardly permissioned
is still correct, so a failure logs the `chmod` that fixes it and carries on.
Unix only, gated, because CI builds this on Windows too.
The second half is the same defect one layer up. The node started with the set
owned by the user who had built it offline, could not append `BOUNDARIES`, said
so once:
WARN segbuild: could not record the catch-up boundary at #9429867:
opening /var/lib/rustock/segbuild/BOUNDARIES: Permission denied
and then had nothing further to say, because the next attempt would have come a
gigabyte of writes later -- about a month. The feature was inert and the log
looked healthy. So startup now probes the directory by writing a file and
removing it, and refuses with the `chown`/`chmod`/`setgid` commands that fix it.
That is §7.2's rule: "the set is current" is not the same as "this node can
extend it", and a config error that makes the feature impossible belongs at
startup, before anything is serving, not in a single warning.
With both in place the node closed its 10,888-block coverage gap in 108 seconds
at 92 blk/s, verifying every state root, into a 232 MB segment recorded against
the chain's own hash at #9,429,888.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defects found by enabling segbuild on the mainnet node and reading what it actually did. Neither would have surfaced any other way — both tests and CI pass with them present.
A segment nothing could read
The node runs under
UMask=0077. Sensible hardening, and the builder inherited it, so the first segment it produced was openable by nothing but the node:That is the worst shape a failure can take here, because it is silent and it looks like something else:
All true. The segment is correct. A consumer then gets a permission error, which looks nothing like "this segment is fine, you just cannot read it" — and
dureports 1 MB, because it cannot descend into it.The set exists to be read by other processes, so the mode is now set explicitly after the rename rather than inherited:
0755for directories,0644for files, and the same for the logs, which are operational state a human and the offline tools read. Loosening the unit's umask would have been the wrong fix — the node's hardening is not the problem.Best-effort and not fatal: a segment that is correct but awkwardly permissioned is still correct, so a failure logs the
chmodthat fixes it and carries on.#[cfg(unix)]-gated, because CI builds this on Windows too.The same defect one layer up: inert, and quiet about it
The node started with the set owned by the user who had built it offline, could not append
BOUNDARIES, said so once:…and then had nothing further to say, because the next attempt would have come a gigabyte of writes later — about a month. The feature was inert and the log looked healthy.
Startup now probes the directory by writing a file and removing it, and refuses with the commands that fix it:
That is §7.2's rule applied where it belongs: "the set is current" is not the same as "this node can extend it", and a config error that makes the feature impossible goes at startup, before anything is serving, rather than into a single warning.
What the node did once both were understood
108 seconds for a 10,888-block coverage gap, every state root verified, into a 232 MB segment, recorded against the chain's own hash at #9,429,888 — checked independently with
block_info, which reports9dc24584for that height, matchingBUILT. NoHALTED, noUNCOVERED.Two numbers worth recording from that run, because both differ from what the design assumed:
909, not098.next_indexcontinues from the highest present, and the set holds900–908from the pre-fork work. Correct per §4.4, and worth knowing before someone greps for0NN-.cut_at, the startup catch-up cut, which ignores the counter —BOUNDARIESrecords itsapprox_bytesas0. Its length came from the size of the gap, not from the target. An earlier draft of this description extrapolated "~43,000-block segments" from it; that is wrong twice over, and the real figure is unknown until the first size-cut segment. See the note below, which is the part worth acting on.A target in write-bytes, a property about read-bytes
--segbuild-target-mbcounts bytes written by executed blocks. A segment holds its range's read set — every node the replay touched — which is a superset. The existing set shows how far apart they are:094-9017692-9133347097-9230009-9420000055-5849091-5895185909-9420001-9429888So a 1 GB write target will not produce a 1 GB segment on disk — and "fits in a consumer's memory", which is the property the byte target exists to protect, is about the sealed size. None of the segments above was byte-targeted: the offline build took its boundaries from a chunk list, so this builder is the first thing that actually cuts by bytes, and the ratio is era-dependent.
Nothing here changes that, deliberately — the first size-cut segment will measure it, and
--segbuild-target-mbis a restart away from being adjusted. Flagging it rather than guessing a correction.Verification
CLI bin 164, execution
segment_build5 (new test reproducesUMask=0077and asserts a consumer can read the result), clippy clean acrossrustock-cli,rustock-executionandrustock-storagewith--all-targets.🤖 Generated with Claude Code