Skip to content

zola, nushell: fetch crates before loading the getrandom shim - #1326

Merged
bryan-minimal merged 1 commit into
mainfrom
fix/rust-shim-fetch-first
Nov 5, 2026
Merged

bryan-minimal merged 1 commit into
mainfrom
fix/rust-shim-fetch-first

Conversation

@bryan-minimal

Copy link
Copy Markdown
Member

Fixes #974.

zola and nushell preloaded their deterministic getrandom/getentropy shim over a plain cargo build --locked. That command also downloads crates, so cargo's TLS sessions ran on the shim's fixed bytes. Both now follow the codex pattern from #878: cargo fetch --locked runs first, with no shim and real entropy, and the shim is preloaded only on cargo build --frozen --release, which cannot use the network. Each package keeps its own inline shim. Converting them to detbuild (#884) is left for a follow-up.

Both builds have the network. zola declares needs.internet itself. nushell gets it through rust, which declares it, so nushell's build is networked although its own build.ncl has no needs.

Build scripts that download: I took every registry crate in zola 0.23.6's and nushell 0.116.1's Cargo.lock (1,389 crates, all platforms, no git dependencies), downloaded each .crate from crates.io, and searched every build script for network access, including custom build = paths such as aws-lc-sys's builder/. None downloads anything. curl-sys and libgit2-sys run git submodule update only when their vendored C source is missing, which never happens for a registry crate. A few others call git for local metadata only. So no RUSTY_V8_ARCHIVE-style fail-closed or pinned Source is needed.

The other two shim carriers named in the #884 review:

  • codex is already fetch-first. It runs cargo fetch --locked unshimmed, then LD_PRELOAD=... cargo build --frozen, and fails closed on rusty_v8 with RUSTY_V8_ARCHIVE=/nonexistent/.... No change.
  • verus-latest is networked through its closure: git's runtime dependency curl declares needs.internet. Its preloaded steps are offline anyway. Every crate comes from the sha256-pinned vendor tarball through [source.crates-io] replace-with = "vendored-sources", and CARGO_NET_OFFLINE=true is exported for both the preloaded cargo build and the cargo run -p cargo-verus that invokes cargo again. I scanned its build scripts the same way (371 registry crates plus verus's own four build.rs) and none downloads. No change here. The preloaded commands carry no explicit --offline flag, which the new detbuild_preload_guard.py would require once verus moves to detbuild. That flag belongs with the conversion, not a separate rebuild of verus.

Verification, in a local min session (pkgbuild loadout, fresh activate per run):

  • min package build --rebuild --verbose zola finished. The log shows all 665 Downloaded lines before the first Compiling line and none after. The shimmed --frozen step built zola in 3m50s. min check --packages zola: every check passes, including the standalone smoke test.
  • min package build --rebuild --verbose nushell finished. All 984 Downloaded lines come from the unshimmed fetch, then LD_PRELOAD=/tmp/libdetrand.so cargo build --frozen --release compiled with no further download. min check --packages nushell: all pass.
  • Negative control (throwaway worktree, never pushed): the same zola build.sh with only the cargo fetch --locked line removed. The shimmed build failed in the networked sandbox with no matching package named 'giallo' found ... offline mode (via --frozen), exit 101. So the shimmed step cannot reach the network even when the sandbox allows it, and every crate it compiles came from the unshimmed fetch.

Reproducibility: output bytes should not change. The fetch only fills cargo's registry cache with the crates Cargo.lock already pinned and checksummed. The compile step still sees the same sources, flags and shim, and --frozen adds nothing beyond --locked except refusing the network. The fetch runs for all targets, so the offline build has every platform-conditional crate it might resolve.

🤖 Generated with Claude Code

Both builds preloaded the deterministic getrandom/getentropy shim over a
plain `cargo build --locked`, which also fetches crates, so cargo's TLS ran
on the shim's fixed bytes. Fetch first with real entropy (`cargo fetch
--locked`), then preload only the offline `cargo build --frozen`, as codex
does (#878). nushell has the network through `rust` (needs.internet), zola
declares it itself.

No build script in either dependency graph downloads (every build script of
every registry crate in both Cargo.locks scanned), so the frozen build needs
no network. Output is unaffected: the same locked crates compile the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 5, 2026 02:11
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 52 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 68 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8211e3f and ceb8ed4.

Files selected for processing: 2

  • packages/nushell/build.sh
  • packages/zola/build.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope matches the title. Two build scripts change, and every hunk traces to the fetch-first change for #974. The zola comment move is part of that change.

Clobber none. git log on both files shows the CVE-2026-111943 lock patch from #955 as the last earlier change. Both scripts keep that patch and its checks, and cargo fetch --locked runs after them, so the fetch uses the patched lock.

Correctness the change is good. The order matches packages/codex/build.sh:56-81. nushell has the network through rust, which declares dns and internet at packages/rust/build.ncl:48-52. The lock patches change only versions and checksums in the lines I read, so they add no new crate to the audited graph.

The three findings are low or nit. Two are about comments, and one is about a missing guard.

Residual risk the claim that no build script downloads is a point-in-time audit for 0.23.6 and 0.116.1. Nothing fails closed on a version bump, and --frozen does not stop a build.rs. Repeat the audit when these packages change version, or convert them to detbuild.

Not checked I did not build, by instruction, so the claim that output bytes do not change is unverified. I could not reproduce the 1,389-crate audit, because the request for the upstream Cargo.lock files was denied. gitleaks was not run. I read the diff, and it holds no credential. No dependency manifest changed.

Comment thread packages/zola/build.sh
SHIM
gcc -shared -fPIC -O2 -o /tmp/detrand.so /tmp/detrand.c
LD_PRELOAD=/tmp/detrand.so cargo build --locked --release
LD_PRELOAD=/tmp/detrand.so cargo build --frozen --release

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low · This fix has no regression guard, so a later edit can restore cargo build --locked under the shim without a failure. detbuild_preload_guard.py matches only libdetbuild.so, so it skips /tmp/detrand.so here and /tmp/libdetrand.so at packages/nushell/build.sh:71. The negative control in the PR body ran once and is not committed. The same gap applies to codex and verus-latest. Convert these packages to detbuild, or extend the guard to match the inline shims.

Comment thread packages/zola/build.sh
# Deterministic build-time entropy (the guide's prescribed shim): interposes
# getrandom/getentropy so build.rs / proc-macro / rustc-internal HashMaps
# iterate identically every build. Runtime binary is unaffected. It wraps only
# the offline BUILD: `--frozen` refuses any network access.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low · The comment says --frozen refuses any network access. That is true for cargo only. A build.rs can still download under the shim, and .github/scripts/detbuild_preload_guard.py:54-57 says so. The next reader can take this line as proof that the shimmed step is offline, but only the version-specific audit supports that. packages/nushell/build.sh:70 has the same wording, and packages/codex/build.sh:67 is the existing source of it. Write that --frozen stops cargo from fetching.

Comment thread packages/nushell/build.sh
# Scope the shim to the cargo build only — no global export/unset window.
LD_PRELOAD=/tmp/libdetrand.so cargo build --locked --release
# Scope the shim to the cargo build only — no global export/unset window — and
# keep that build offline: `--frozen` refuses any network access.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · This PR moves the zola shim explanation down to the shim, but the nushell explanation stays at lines 24-30. That text now sits above the CVE block and about 25 lines from the shim, with the new fetch block also between them. Move it to line 54 so that the two scripts have the same layout.

@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit ee9e6e7 Nov 5, 2026
15 checks passed
@bryan-minimal
bryan-minimal deleted the fix/rust-shim-fetch-first branch November 5, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zola, nushell: fetch crates before loading the getrandom shim

2 participants