Skip to content

Fix: Query the package index without pip - #181

Merged
keanjapesan merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:feat/stdlib-index-query
Nov 3, 2026
Merged

keanjapesan merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:feat/stdlib-index-query

Conversation

@ModeSevenIndustrialSolutions

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces #173. The action ran python3 -m pip index with whichever python3 the caller's PATH held, from the caller's workspace, inside pypi-publish-action's publish job. A pip/ or ensurepip/ package in the checkout, a workspace .venv on PATH, or PYTHONPATH, PYTHONHOME and user-site settings reaching the workspace could all run checkout code. #173 closed those routes one at a time and grew to ~3,000 lines that each review round found more gaps in. This removes the routes instead: the action no longer runs pip, ensurepip, or any Python from PATH.

Changes

  • scripts/check_index.py (standard library only) reads the project's page from the simple API, asking for PEP 691 JSON and accepting PEP 503 HTML, takes versions from wheel and sdist filenames, and compares them as PEP 440 defines (1.0.0RC1 matches 1.0.0rc1; 1.0 matches 1.0.0).
  • Interpreter. setup-uv runs in the action's directory with UV_NO_CONFIG/UV_NO_PROJECT, the pattern the other setup-uv PRs merged. uv then installs its own pinned, hash-checked Python under runner.temp, and the script runs as python -I from the action's directory. -I ignores PYTHON* variables and the user site and keeps the working directory off sys.path.
  • Install step. uv runs under env -i with an explicit allow-list: its own install and cache directories under runner.temp, UV_NO_CONFIG/UV_NO_PROJECT, and proxy, certificate and UV_NATIVE_TLS settings for self-hosted runners. No caller variable (PATH, VIRTUAL_ENV, CONDA_PREFIX, any UV_* or PYTHON*) reaches it, so none can choose the interpreter or redirect the download. It also refuses an interpreter path outside its install directory.
  • setup-uv step. setup-uv itself runs uv python find and then executes the interpreter it finds (--version, for its cache key), whether or not caching is on. Caller variables can steer that lookup into the checkout: CI caught a planted python3 on PATH, and review found VIRTUAL_ENV, CONDA_PREFIX, UV_INTERNAL__PARENT_INTERPRETER and macOS's PYTHONEXECUTABLE. Rather than chase each, the step sets UV_PYTHON_PREFERENCE to an invalid value, so uv refuses its arguments before any lookup and nothing runs. setup-uv then reports the Python version as unknown, which the action never reads; setup-uv v10.3.3 makes no other uv call for these inputs. An inherited UV_PYTHON_ARCH would make setup-uv probe uv first, a probe the invalid preference would fail, so the step sets it empty. The step also sets tool-bin-dir under runner.temp: setup-uv would otherwise add the caller's HOME or XDG_* bin directory to PATH for later steps, where a planted bash or env would run. Every directory setup-uv adds to PATH is then the action's own. (UV_NO_MODIFY_PATH is deliberately not set: setup-uv's own bare uv call would then resolve on the caller's PATH, which the isolation job caught.) The action's own uv calls use setup-uv's absolute uv-path output. The other merged setup-uv PRs share this lookup; their tests planted interpreters in the workspace, not via PATH or these variables, so they would not have seen it.
  • requirements/uv.txt pins uv for Dependabot (new pip ecosystem entry), as python-twine-check-action does. The pin also fixes which Python builds and hashes uv accepts.
  • Egress. The interpreter downloads from releases.astral.sh, already in the organisation's harden-runner allow-list.

Behaviour changes

  • A 404 means the project is absent; any other failure to read the index (unreachable host, HTTP error, malformed page) fails the step whatever EXIT_ON_FAIL says, where it used to report the package missing.
  • An invalid project name or PEP 440 version fails the step, without echoing the value. So does a page the script cannot fully read: a JSON entry without a non-empty string filename, HTML cut inside a tag or with an unparsable link, a body shorter than its Content-Length or chunking, an unknown character set, or JSON nested past the parser's limit.
  • The URL the step requests and logs is rebuilt from the parsed host, port and path, so nothing else from the input authority reaches the log. An authority that does not parse fails without its text, credentials included.
  • Credentials in INDEX_URL (https://user:token@host/simple) go as HTTP Basic auth to that host alone (never across a redirect) and are never printed. Redirects stay within http(s), never https to http.
  • Versions count regardless of the runner's Python or platform (pip hid files the runner could not install), and yanked releases count, since the index still holds them. PACKAGE_MATCH is true when the project page lists any distribution, pre-releases included.

Scope

The action trusts the caller's PATH, as any composite action must: the runner finds bash there for every step, and setup-uv runs ldd and tar from it. A job that puts a directory from its checkout on PATH runs that checkout's code whatever any action does. What the action guards is the interpreter it runs, which nothing on PATH or in the caller's PYTHON*/UV_* settings decides.

The inputs and outputs are unchanged; pypi-publish-action, the one caller, needs no change.

Tests

  • tests/test_check_index.py (101 cases, replacing tests/test_pip_fallback.py): PEP 440 normalisation and rejection, filename parsing, credentials and log redaction, and end-to-end runs of the script as the action runs it against a local HTTP index serving JSON and HTML pages: every case the integration job checks, plus HTTP 500, malformed JSON and file entries, truncated HTML, short and cut-chunked bodies, an unknown charset, an unexpected content type, a redirect to file://, an unreachable host, authentication, and invalid inputs (no request is made). A workspace holding json.py, base64.py, urllib/, sitecustomize.py and usercustomize.py, with PYTHONPATH, PYTHONSTARTUP and PYTHONUSERBASE pointing at it, imports none of them. The install step's own script runs against a stub uv to check what environment reaches it and that an outside path is refused.
  • test_setup_uv_lookup_refuses_before_running_anything runs the real uv with every interpreter selector uv 0.13.5's Python crates read, planted at once: a control lookup executes the bait, and the setup-uv step's env runs nothing. test_install_step_gives_uv_nothing_from_the_caller checks the exact environment the install step hands uv.
  • New CI job Workspace Isolation (Ubuntu and macOS, each with a request leg and an active-environment leg, so UV_PYTHON cannot mask active-environment discovery) runs the action twice, cold then warm, against a workspace planted with those modules, a fake python3, python and uv first on PATH, a .venv with pyvenv.cfg and conda-meta, pyproject.toml/uv.toml/.python-version, and hostile PYTHONPATH, PYTHONHOME, PYTHONUSERBASE, PYTHONSTARTUP, PYTHONEXECUTABLE, __PYVENV_LAUNCHER__, UV_NO_CACHE, UV_PYTHON_ARCH, UV_PYTHON_INSTALL_MIRROR and an XDG_BIN_HOME holding bait env and bash, plus either UV_PYTHON, UV_PYTHON_SEARCH_PATH, UV_PYTHON_INSTALL_DIR and UV_PYTHON_PREFERENCE, or VIRTUAL_ENV, CONDA_PREFIX, CONDA_DEFAULT_ENV, UV_INTERNAL__PARENT_INTERPRETER, UV_INTERNAL__TEST_PYTHON_MANAGED and UV_CACHE_DIR. A control shows the bait runs for a Python that is not isolated; the job then checks no bait ran, no checkout directory reached PATH, and both runs returned the right outputs.
  • The existing Action Testing job against TestPyPI is unchanged and its expectations hold.

Validation

Local, before push: 101 tests pass; a local run of the isolation job's planted workspace through the action's own step scripts on macOS runs no bait (and, with the location-variable unset removed, the install step refuses the planted interpreter); live queries against PyPI and TestPyPI match every integration expectation. prek hooks pass, aislop scores 100 with no findings, and zizmor --persona auditor reports nothing. In CI, the isolation job passes on Ubuntu and macOS with its control showing the bait live.

This comment was marked as outdated.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 17:10

This comment was marked as outdated.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 17:21

This comment was marked as outdated.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 08:43

This comment was marked as outdated.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 08:50

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 14:18
This was referenced Nov 3, 2026
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.

3 participants