Skip to content

fix(sdks/python): pin the CI tree, and make the SDK visible to a scanner - #347

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/python-sdk-pinning-and-scanning
Aug 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/python-sdk-pinning-and-scanning

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #343.

Two problems, one file. Both were measured rather than reasoned about, and one of them was measured wrong first — see the filename note below, which is the most useful thing in this PR.

The scanning gap

trivy fs over main reports four targets. sdks/python is not one of them:

docs-platform/package-lock.json    npm
go.mod                             gomod
sdks/java/pom.xml                  pom
sdks/javascript/package-lock.json  npm

Trivy detects Python from requirements.txt, poetry.lock, Pipfile.lock, or an installed .dist-info. The only manifest in sdks/python was setup.py, which is on none of those lists. So this SDK's 16 declared dependencies were scanned by nothing — the exact complaint #201 filed against the JavaScript SDK, in the one directory closing #201 did not reach. With this branch it reports five targets, sdks/python/requirements.txt among them, 0 vulnerabilities.

The filename is load-bearing, and I got it wrong first

I wrote this file as requirements-ci.txt, because that name says what it is. Trivy does not detect that name. Scanned in a scratch directory it reported no targets at all — so the file would have looked exactly like the fix, passed review, and left the scanning gap precisely where it was.

Tested each candidate:

filename detected
requirements.txt yes
requirements-ci.txt no
requirements-dev.txt no
dev-requirements.txt no
requirements/ci.txt no
pyproject.toml (bare, with [project].dependencies) no

That last row is worth stating on its own: pyproject.toml is the modern-practice answer and it does not solve this problem. #343's body says otherwise; I wrote that before testing it, and the issue is wrong on that point.

The header comment in the file says all of this and says not to rename it for tidiness, because the failure mode is silent.

The unpinned tree

ci.yml ran pip install --quiet pytest ., resolving six >= floors fresh on every run — same defect as docs-site before #337, so a break could appear or vanish with no commit behind it. Now:

pip install --quiet -r requirements.txt
pip install --quiet --no-deps .
pip check
pytest tests/ -q

--no-deps is what makes the first line authoritative; without it pip re-resolves install_requires and can move a pinned version.

install_requires deliberately stays as ranges. A library that pins its transitive tree pins it for every consumer, so "add a lockfile" is not the right instruction for a library — the split is the standard one, and requirements.txt answers "what does CI test" while setup.py answers "what does this package require."

pip check guards the seam between them. Mutation-checked rather than assumed:

$ # requirements.txt pinned to psutil==5.7.0, install_requires says >=5.8.0
$ pip check
objectfs 0.1.0 has requirement psutil>=5.8.0, but you have psutil 5.7.0.
exit=1

(First attempt at that mutation used requests==2.24.0, which fails at install with ResolutionImpossible on an idna conflict — so it never reached pip check and proved nothing. psutil has no transitive dependencies, which is why it's the right probe.)

Two dependencies removed rather than pinned

Neither was a dependency of this package:

  • asyncio>=3.4.3 — a stdlib module since Python 3.4; python_requires here is >=3.8. The PyPI distribution of that name is a 3.3-era backport, and at 4.0.0 it is now a deliberate empty stub whose own summary reads "Deprecated backport of asyncio; use the stdlib package instead" — dist-info and no modules. Checked in a scratch venv: with it installed, asyncio.__file__ still resolves to the stdlib, so it shadowed nothing. It still declared a dependency the SDK does not have, and older resolutions of that range are not empty stubs.
  • typing-extensions>=4.0.0 — imported nowhere. It still appears in requirements.txt, because pytest pulls it in transitively, which is the difference between the two files in one line.

The four that remain are each imported by name: requests, yaml, psutil, aiohttp. 71 tests pass with both removals applied.

Dependabot

A pip ecosystem entry for /sdks/python, which needed the pinned tree to exist first for the same reason docs-platform's security updates needed a lockfile: with only ranges, no installed version is known, so a vulnerable dependency cannot be identified as vulnerable.

Its python label was added to .github/labels.yml and synced with .github/scripts/sync-labels.sh --apply, not created by the first PR that applies it. That is how java got onto the repository, and the comment recording it sits four lines above where I added python — doing it again with the note already written would be hard to defend. TestLabelsYAMLMatchesTheRepository failed on the declared-but-missing label first, which is the check working.

Expect one non-obvious PR shape from this entry: because the tree is frozen including transitives, a transitive bump arrives as a requirements.txt-only change with no manifest edit. That is correct here, and the opposite of the npm case, where a manifest change without a lockfile change is now a test failure (#332, merged as #345).

Verification

trivy fs --scanners vuln .                              5 targets, sdks/python present, 0 vulns
pip install -r requirements.txt && pip install --no-deps .
pip check                                               No broken requirements found.
pytest tests/ -q                                        71 passed, 25 subtests passed
go test ./internal/config/ -count=1 -race               ok  (labels + lockfile gates)
npx markdownlint-cli CHANGELOG.md                       361 (baseline)

Closes #343.

Two problems, one file. setup.py declared 16 dependencies as unbounded
>= floors with no lockfile, so the sdk-metrics job resolved all of them
fresh on every run - the defect #337 fixed for docs-site, in another
language. And nothing scanned them: trivy fs reported four targets
(go.mod, sdks/java/pom.xml, and the two package-lock.json files) with
sdks/python absent, because Trivy detects Python from requirements.txt,
poetry.lock, Pipfile.lock or an installed .dist-info, and the only
manifest here was setup.py. It now reports five.

The filename is load-bearing and cost a rewrite to find. This was first
written as requirements-ci.txt, which Trivy does not detect - scanned in
a scratch directory it reported no targets, so the file would have read
as the fix while leaving the gap where it was. requirements-dev.txt,
dev-requirements.txt and requirements/ci.txt are equally invisible, and a
bare pyproject.toml is not detected either.

install_requires stays as ranges, because a library that pins its
transitive tree pins it for every consumer. pip check now runs between
install and test to catch the one thing that split can get wrong; verified
by mutation - psutil==5.7.0 against a >=5.8.0 floor reports the conflict
and exits 1.

Two entries removed rather than pinned, because neither was a dependency:
asyncio has been stdlib since 3.4 and this package requires >=3.8, and
typing-extensions is imported nowhere. 71 tests pass with both gone.

The pip ecosystem entry needed the pinned tree to exist first, for the
same reason docs-platform security updates needed a lockfile. Its python
label was added to labels.yml and synced from there, rather than being
created by the first PR to apply it - which is how java got onto the
repository.
@scttfrdmn scttfrdmn added the type: security Security vulnerability or hardening label Aug 4, 2026
@scttfrdmn scttfrdmn added priority: medium Important but not urgent area: sdk Client SDKs (Python, Java, JavaScript) area: ci-cd CI workflows, gates, and release automation effort: small Small effort - 2-4 hours labels Aug 4, 2026
@scttfrdmn
scttfrdmn merged commit 3e1b544 into main Aug 4, 2026
30 checks passed
@scttfrdmn
scttfrdmn deleted the fix/python-sdk-pinning-and-scanning branch August 4, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci-cd CI workflows, gates, and release automation area: sdk Client SDKs (Python, Java, JavaScript) effort: small Small effort - 2-4 hours priority: medium Important but not urgent type: security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sdks/python pins nothing and is scanned by nothing: 16 floor-only dependencies, no manifest any scanner reads

1 participant