[CI workflows] GITHUB_TOKEN permissions hardening; CI cleanup/optimizations#926
Open
kdmukai wants to merge 5 commits into
Open
[CI workflows] GITHUB_TOKEN permissions hardening; CI cleanup/optimizations#926kdmukai wants to merge 5 commits into
kdmukai wants to merge 5 commits into
Conversation
18 tasks
CI: add pip cache to tests workflow to reduce runtime
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.
Summary
GITHUB_TOKENto "least privilege" (read-only) across CI workflowstests.ymlandbuild.yml.1.): Workflow permissions hardening
GitHub Actions inject a
GITHUB_TOKENthat provides access to the repo. The default scope comes from two places:permissions:block declared in the workflow itself.A
GITHUB_TOKENwithcontent: writepermissions would be difficult to extract from a CI job (malicious CI steps would have to slip past review and get merged) but would be extremely dangerous if successful (more or less equivalent to giving an attacker full maintainer privileges for that repo).That sounds scary, but note that PRs from downstream forks are ALWAYS limited to a read-only
GITHUB_TOKENin the related PR CI runs. This is why a malicious CI job would have to be merged first to be successful. So it's a highly unlikely scenario and so I do NOT think the current workflows (which don't declare explicit permissions) are at risk.However, another way to extract the
GITHUB_TOKENwould be if one of the actions we rely on were compromised (e.g.actions/checkout@v4). The worst-case scenario would be: we provide a writable token to a CI job that already runs internal to our repo (i.e. not in a PR context where it's inherently limited to read-only) AND one of the actions it relies on is compromised.But if we explicitly limit the
GITHUB_TOKENto read-only in the CI job (what this PR does), then even with a compromised action we would have zero real exposure (the attacker could also read any env vars in the CI job, but we don't inject any secrets via env vars).tldr:
Making the
GITHUB_TOKENexplicitly read-only in each CI workflow makes it obvious if a malicious PR tries to elevate it to writable AND protects us against an action step being compromised out from under us.This aligns with GitHub's own guidance to grant the token the least required access.
No step in these workflows currently writes anywhere, so this has zero effect on these jobs.
Notes for the future:
GITHUB_TOKENwithcontents: writein any CI job in our main repo.pull-requests: writeis less damaging but would still need thorough discussion.GITHUB_TOKENwith any write permissions, careful consideration should be taken if any third-party actions are used (e.g.marocchino/sticky-pull-request-comment@v2).2.) Cleanups suggested by Claude
2.a.): Cleanup —
tests.ymltimeout-minutes: 20on thetestjob — cap runaway test hangs (default is 6h).apt-get install -y --no-install-recommends libzbar0— defensive flags.-yavoids interactive prompts on future apt versions.--no-install-recommendsskips libzbar0's "Recommends" entry (libmagickcore-*-extra, which pulls in ImageMagick's format-support extras and a tree of graphics libraries via transitive deps) — we only need the core zbar library for QR decoding.python -m pip install --upgrade pip—setup-pythonalready ships arecent pip.
mkdir artifacts→mkdir -p artifacts— defensive against re-runs.--cov-appendfrom the first pytest invocation — there's no existing.coverageto append to on the first run; kept on the screenshot-generatorrun where it's actually doing something.
2.b.): Cleanup —
build.ymlconcurrency:block withgithub.refin the fallback — cancelssuperseded runs on the same branch/PR. Chose
github.ref(rather thangithub.shaas intests.yml) because the 30-min-per-target build has nodownstream consumers for intermediate commits; only the latest commit per ref
needs to be built.
timeout-minutes: 120on thebuildjob — caps the blast radius of a hungbuild without risking a legitimate cache-miss run being killed. Recent runs took up to 78 minutes.
delete unnecessary filesstep explaining why onlysrc/is kept from the seedsigner checkout.sha256sumjob: replacedgit init+git rev-parse --shortwith the bash substring${GITHUB_SHA::7}. Same output, no throwaway.gitdirectory, dropped theunused step
id.This pull request is categorized as a:
Checklist
I ran
pytestlocallyI included screenshots of any new or modified screens
Should be part of the PR description above.
I added or updated tests
Any new or altered functionality should be covered in a unit test. Any new or updated sequences require FlowTests.
I tested this PR hands-on on the following platform(s):
I have reviewed these notes:
Thank you! Please join our Devs' Telegram group to get more involved.