Repository navigation
test-determinism: keep the issue token out of every process that runs project code - #2797
Merged
Merged
Conversation
… project code The measure job held issues: write and passed GH_TOKEN to measure-flakes.py, which gave its whole environment to cargo, every build script, proc macro and test, and left the job token in the checkout. Measuring now holds no grant beyond contents: read and saves what it found with --save; a separate file job holds issues: write, loads that file with --load and runs only gh. cargo_env also drops GH_TOKEN and GITHUB_TOKEN, and every checkout here sets persist-credentials: false. check_privileged_job_runs_only_its_own_code now reads cargo commands and measure-flakes.py beside a token, a job-level secret or a persisted write credential. Closes brave#2789
Collaborator
Author
|
Fixed: the selftest now drives |
netzenbot-reviewer
approved these changes
Oct 20, 2026
bbondy
approved these changes
Oct 20, 2026
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.
Closes #2789
User impact: none -- CI hardening; the weekly flake report and the filed issues read the same.
The problem
The weekly Test determinism job holds a token that can create, edit, close and label issues and pull requests. It passes that token to
contrib/measure-flakes.py, which gives its whole environment tocargo, so every build script, proc macro and test of every crate inCargo.lockcan read it. The checkout also leaves the job token in the working tree. The security check that exists to catch a privileged job running third-party code reads onlynpm,pnpmandyarn, so it reports nothing here.Reproduce
upstream/main, runsed -n 137,146p .github/workflows/test-determinism.ymlandsed -n 477,481p contrib/measure-flakes.py: the Measure step setsGH_TOKEN, andcargo_envcopiesos.environ.GH_TOKEN=x python3 -c "import runpy;m=runpy.run_path('contrib/measure-flakes.py');print('GH_TOKEN' in m['cargo_env']())": printsTrue.check_privileged_job_runs_only_its_own_code()against that workflow: it returns[].Expected: no process cargo starts sees the token, and the check names the step. After this change, step 2 prints
Falseand the check namesmeasure-flakes.pyon the old workflow (selftest fixture) and returns nothing on the new one. The tests aretest_privileged_job_runs_project_codeinagents/skills/security-audit/selftest.pyand themeasure-flakes.py --selftestcheck.The fix
measurenow holds onlycontents: read, checks out withpersist-credentials: false, and runsmeasure-flakes.py --save, so no token is in it at all. A newfilejob (the only one holdingissues: write, ubuntu, no toolchain) downloads the saved measurement for the two filing legs and runsmeasure-flakes.py --load, which runs no cargo and so no project code. The machine description is saved with the measurement so issues still name the host that ran the suite.cargo_envalso dropsGH_TOKENandGITHUB_TOKEN. The security check now reportscargo build|test|clippy|run|nextest|install|check|bench|docandcontrib/measure-flakes.py(not in--loadmode) in a step that holds a secret, a job-level secret,id-token: write, or a write grant with a checkout that persists credentials.Test plan
contrib/measure-flakes.py --selftest— passedpython3 agents/skills/security-audit/selftest.py— passedBRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 make check-affected— scripts, spec, security, locales, versions, narration, reviewdog, docs, npm, deps passed. One Rust test,a_replaced_submodule_a_smudged_entry_and_a_socket_read_as_git_reads_them, failed here only because this host's/tmpand the worktree are on different filesystems (CrossesDevices); it passes withTMPDIRon the worktree's filesystem. Untouched by this diff.measure,file) have not run; they run only on the schedule or a dispatch. Docker gates skipped: host-only.Test evidence
--selftest"no token reaches the environment cargo and the tests inherit"cargo_envreturningdict(os.environ)test_privileged_job_runs_project_codemeasure-flakes.pyat line 144; the old check returned[]contents: readbuilds are clean--loadfiles without cargo, naming the measuring host--dry-run