Skip to content

Fix: Keep the config token out of the audited env - #254

Merged
ModeSevenIndustrialSolutions merged 3 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-253
Nov 2, 2026
Merged

ModeSevenIndustrialSolutions merged 3 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-253

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

INFO The workflow Copilot review request was accepted but no Copilot reviewer was added; no Copilot review was requested for this pull request, so a maintainer should request one.

Closes #253

Authored by an AI agent; human review required
Command Exit
uv run --locked python -m pytest tests -q 0
uv run --locked python -m pytest tests/test_config_token_isolation.py -q --runxfail (test commit, expected failures) 1
prek run --files tests/test_config_token_isolation.py 0
prek run --files action.yaml README.md tests/test_config_token_isolation.py .github/workflows/testing.yaml 0
aislop scan --staged --json (each commit; empty diagnostics) 0
zizmor --persona auditor .github/workflows/testing.yaml action.yaml 0

The github-code-monkey-bot workflow opened this pull request.
Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds; a maintainer must act on any finding that remains after that, and reviews every round before merge.


What changed

The Resolve allow-list via config step ran the setup-python interpreter with inputs.token in its environment. It ran after Install build products/dependencies had installed the audited project's wheels and requirements.txt into that same interpreter. A .pth file from any of those packages runs when the interpreter starts, so the audited project could read the token. That token is typically a PAT or App token with contents:read on a private repository.

This PR makes three changes, one per commit:

  1. Test: adds tests/test_config_token_isolation.py, first with strict xfail markers:
    • every step that references inputs.token comes before the install step;
    • a wheel carrying a marker-writing .pth goes into a venv, the config step's own script (read from action.yaml) runs with that venv first on PATH, and the test asserts the marker file is absent. A stub git that always fails keeps the test offline, and the test asserts that the helper reached its first git call;
    • a control test checks that the same .pth fires and sees the token under plain python3, so the main test cannot pass vacuously.
  2. Fix: moves the config step ahead of the install step and runs the resolver as python3 -I -S. The resolver imports only the standard library. -S still matters on self-hosted runners, where a persistent tool cache can hold packages that an earlier job installed. This commit removes the xfail markers. It also corrects the README note, which said the resolver used the runner's preinstalled python3 (it uses the setup-python one on PATH).
  3. CI: adds a tests-config-token-isolation job to testing.yaml, following the pattern of the existing install-guard and cache-scope jobs.

No other step references inputs.token.

Validation

  • uv run --locked python -m pytest tests -q: 89 passed, 2 xfailed after the test commit; 91 passed after the fix. Each commit leaves the suite green.
  • --runxfail on the test commit: the ordering test and the .pth test both fail for the expected reasons (the marker gets written).
  • prek run --files <changed files> on each commit: all hooks pass (gitlint, ruff, mypy, basedpyright, yamllint, actionlint, markdownlint, reuse, aislop and the rest).
  • aislop scan --staged --json for each commit, with ruff on PATH so the lint engine ran: empty diagnostics.
  • zizmor --persona auditor .github/workflows/testing.yaml action.yaml: no findings.

Points a reviewer may question

  • Step order: the step summary now shows the config allow-list block before the install output. Outputs (steps.config_resolve.outputs.*) are used only by later steps, so behaviour is otherwise unchanged.
  • Why -I -S as well as the move: the move alone covers GitHub-hosted runners. -S covers a reused self-hosted tool cache. It is safe because the resolver is stdlib-only, and that file is mirrored with harden-runner-block-action; this PR does not touch it.
  • Not covered: a git or python3 binary that an earlier job planted on a persistent self-hosted runner. That is outside what this action can control.
  • Test cost: the new test creates a venv and runs pip offline (--no-index), which takes a few seconds.

lf-releng-code-monkey-bot Bot and others added 3 commits October 31, 2026 14:47
The config step runs the setup-python interpreter with inputs.token
in its environment after the install step has put the audited
project into that interpreter's site-packages. A .pth file shipped
by any installed wheel runs at interpreter start-up and can read the
token.

Add tests that pin the fix: every step referencing inputs.token runs
before the install step, and the config step's python3 does not run
a hostile .pth already present in site-packages. A control test
proves the marker wheel does fire under plain python3, so the second
test cannot pass vacuously. Both fix-dependent tests are marked
strict xfail until the fix lands.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
The config step ran the setup-python interpreter with inputs.token in
its environment after the install step had put the audited project
and its dependencies into that interpreter. A .pth file from any of
those wheels runs at interpreter start-up, so the project could read
a token that typically grants contents:read on a private repository.

Move the config step ahead of the install step, so the token is gone
before any audited code reaches the interpreter, and run the resolver
with python3 -I -S. The resolver uses only the standard library, and
-S skips site-packages, which still matters where a self-hosted
runner's tool cache keeps packages from an earlier job. Remove the
expected-fail markers from the tests this makes pass, and correct the
README note that said the resolver used the runner's preinstalled
python3.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Add a job to the testing workflow that runs
tests/test_config_token_isolation.py, matching the existing jobs for
the install step guard and cache scope tests. Without it the new
tests would never run in CI and a regression could merge unnoticed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change isolating config resolution from the audited Python environment.

No open issues 🎉

What changed in this PR

This PR addresses #253 by isolating config resolution from the audited Python environment, preventing installed packages’ startup hooks from accessing the config token.

Changes:

  • Moves config resolution before package installation and runs the resolver with python3 -I -S.
  • Adds regression tests for token-step ordering and isolation from a marker-writing .pth file, plus a dedicated CI job.
  • Updates the README to describe the interpreter and isolation behavior.
File Description
tests/​test_config_token_isolation.py Tests step ordering and .pth isolation, with a control confirming the hook executes without isolation.
README.md Documents config resolution’s interpreter and token isolation.
action.yaml Runs config resolution before installation with isolated Python startup.
.github/​workflows/​testing.yaml Adds a dedicated config-token-isolation test job.

Review effort: Balanced

@ModeSevenIndustrialSolutions

Copy link
Copy Markdown
Member

Scope check for the reviewer: this PR covers the one step that holds token (config resolution), which now runs before the install and under python3 -I -S. I also checked the two pypa/gh-action-pip-audit steps at the end of action.yaml:

  • They receive no token. With virtual-environment empty, pip-audit installs into and runs from the same interpreter that holds the audited wheels; passing a venv would move both into it, not separate them. Code an audited package adds to start-up therefore runs in those steps, which is inherent to auditing an installed environment.
  • They only have whatever the calling job grants. All seven calling jobs in this organisation (python-workflows ×4, http-api-tool-docker ×2, test-python-project) grant only contents: read, with no id-token: write and no job-level secrets, so nothing is exposed there.

So no change is needed in this PR. A possible follow-up, separate from it, is a README sentence telling callers to give the auditing job no OIDC permission or secrets of its own.

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.

🤖 Dependamerge
Approved this pull request ✅

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 9fea5f6 into lfreleng-actions:main Nov 2, 2026
17 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-253 branch November 2, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the config token out of the audited environment

2 participants