Repository navigation
fix(sdks/python): pin the CI tree, and make the SDK visible to a scanner - #347
Merged
Merged
Conversation
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.
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 #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 fsovermainreports four targets.sdks/pythonis not one of them:Trivy detects Python from
requirements.txt,poetry.lock,Pipfile.lock, or an installed.dist-info. The only manifest insdks/pythonwassetup.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.txtamong 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:
requirements.txtrequirements-ci.txtrequirements-dev.txtdev-requirements.txtrequirements/ci.txtpyproject.toml(bare, with[project].dependencies)That last row is worth stating on its own:
pyproject.tomlis 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.ymlranpip install --quiet pytest ., resolving six>=floors fresh on every run — same defect asdocs-sitebefore #337, so a break could appear or vanish with no commit behind it. Now:--no-depsis what makes the first line authoritative; without it pip re-resolvesinstall_requiresand can move a pinned version.install_requiresdeliberately 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, andrequirements.txtanswers "what does CI test" whilesetup.pyanswers "what does this package require."pip checkguards the seam between them. Mutation-checked rather than assumed:(First attempt at that mutation used
requests==2.24.0, which fails at install withResolutionImpossibleon an idna conflict — so it never reachedpip checkand proved nothing.psutilhas 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_requireshere 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 inrequirements.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
pipecosystem entry for/sdks/python, which needed the pinned tree to exist first for the same reasondocs-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
pythonlabel was added to.github/labels.ymland synced with.github/scripts/sync-labels.sh --apply, not created by the first PR that applies it. That is howjavagot onto the repository, and the comment recording it sits four lines above where I addedpython— doing it again with the note already written would be hard to defend.TestLabelsYAMLMatchesTheRepositoryfailed 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