Repository navigation
fix(agent-server): drop pip's vendored pkg_resources - #5991
Conversation
pip 26.2.1 vendors pkg_resources from setuptools 70.3.0, which Trivy reports as CVE-2025-47273 and CVE-2026-59890. setuptools removed pkg_resources in 82.0.0, before the 83.0.0 fix for CVE-2026-59890, so there is no patched version to re-vendor. Remove it in the existing pip-revendored stage instead; pip only imports it for the deprecated pkg_resources metadata backend, which is off by default on Python 3.11+. Extend the retirement guard so it also tracks whether upstream pip still vendors pkg_resources. Co-authored-by: openhands <openhands@all-hands.dev>
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Correct the claim that setuptools removed pkg_resources before both CVE fixes (CVE-2025-47273 was fixed in 78.1.1), and state what setting _PIP_USE_IMPORTLIB_METADATA=0 now does instead of how pip selects it. Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Approved. The change is correctly scoped to this repository (the agent-server Docker image, which this repo owns) and matches the linked issue #5988 (now closed) exactly.
What the head does
pip-revendoreddeletessetuptools==70.3.0from pip's_vendor/vendor.txt, asserts nosetuptools==line survives, and removestools/vendoring/patches/pkg_resources.patchbeforevendoring sync. The rebuilt wheel and itsbom.cdx.jsoncontain no setuptools, so CVE-2025-47273 and CVE-2026-59890 disappear from the shipped-python/-python-slimimages.- The retirement guard now also probes
pkg_resourcesupstream, and documents the intended retirement condition (upstream dropspkg_resourcesand fixes urllib3/msgpack).
Verification performed on c35c32c
- Pulled pip 26.2.1 source; tarball SHA-256 matches the
ADD --checksumpin (65cac79d…). - Reproduced the stage locally (venv +
vendoring==1.4.0 sync, thenpip wheel .). Result:pip/_vendor/pkg_resourcesis absent,bom.cdx.jsondrops thesetuptools 70.3.0component and recordsurllib3 2.8.0/msgpack 1.2.1, with no component added or changed. Diffing the vendored tree against the urllib3/msgpack-only variant differs solely bypkg_resources/,pkg_resources.pyi,vendor.txt, andbom.cdx.json— every other vendored package stays byte-identical, satisfying the issue's "use pip's own tooling, change nothing else" criterion. - The built wheel installs and behaves:
pip list,pip check(clean),pip freeze,pip debug, andpip installfrom PyPI all succeed. - Confirmed the documented regression is exactly as stated:
_PIP_USE_IMPORTLIB_METADATA=0 pip listnow fails withImportError: cannot import name 'pkg_resources' from 'pip._vendor'. pip reaches that backend only when that env var is set to a false value or a distributor patchesimportlib.metadata._PIP_USE_IMPORTLIB_METADATA = Falseon Python 3.11–3.13; this repository sets neither. - Repo's focused tests pass:
tests/agent_server/test_docker_build.py,tests/cross/test_agent_server_build_metadata.py,tests/cross/test_update_npm_pin.py,tests/cross/test_update_debian_snapshot.py(85 passed). GitHub Actions on this head: 52 check runs, 0 failures; thePip re-vendoring retirementworkflow ran and passed. Note: the Docker daemon could not run in the review sandbox, so the image itself was not rebuilt here; the Dockerfile steps were reproduced against the real pip source instead.
Non-blocking note
This is the first time the self-reinstall path (pip install --force-reinstall <wheel>) shrinks pip's installed file set — pip/_vendor/pkg_resources/ was in the previous install's RECORD and is absent from the new wheel. The PR's Trivy before/after evidence indicates it is removed correctly. A quick confirmation on the built image that no stale pip/_vendor/pkg_resources directory remains would close the loop. Not a merge blocker.
✅ APPROVED
HUMAN:
Drop pip's unused vendored pkg_resources flagged for setuptools CVEs
AGENT:
Why
The agent-server
-pythonand-python-slimimages still report CVE-2025-47273 and CVE-2026-59890. Both are in setuptools 70.3.0, which pip 26.2.1 bundles only for itspkg_resourcesmodule. There is no fixed copy to bundle instead. setuptools removedpkg_resourcesin 82.0.0, and the CVE-2026-59890 fix only arrived in 83.0.0. So this PR removespkg_resourcesfrom the pip that thepip-revendoredstage already rebuilds.On Python 3.11 and later, pip reads installed packages with
importlib.metadataby default. It importspkg_resourcesonly for its deprecated older backend, which upstream plans to remove (pypa/pip#13317). The one behaviour change is for anyone who sets_PIP_USE_IMPORTLIB_METADATAto a false value. Before, pip printed a deprecation warning and continued. Now it fails with anImportErrorwhen it reads installed packages.Summary
pip-revendoredstage deletessetuptools==70.3.0from pip'svendor.txtand removes pip'spkg_resources.patchbeforevendoring sync. The rebuilt pip and itsbom.cdx.jsonthen contain no setuptools.pkg_resources. It asks for the stage to be removed only once upstream has also fixed urllib3 and msgpack.Issue Number
Refs #5988.
How to Test
Build
--target python-node-runtimefromopenhands-agent-server/openhands/agent_server/docker/Dockerfile, then scan it withtrivy image --scanners vuln.python-node-runtimefrommainvs. this branch — findings drop from 180 to 178. The only removals are CVE-2025-47273 and CVE-2026-59890 (setuptools 70.3.0), and nothing is added.--no-binary=:all:. Uninstall and reinstall from pip's HTTP cache work.pip check,show,freeze,inspectanddebugall work._PIP_USE_IMPORTLIB_METADATA=0—pip listfails withImportError: cannot import name 'pkg_resources'. Nothing in this repo sets the variable.Video/Screenshots
N/A.
Design Doc
None.
Type
Notes
None.
This PR was drafted by an AI agent on behalf of the user.
@aivong-openhands can click here to continue refining the PR
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:c35c32c-pythonRun
All tags pushed for this build
About Multi-Architecture Support
c35c32c-python) is a multi-arch manifest supporting both amd64 and arm64c35c32c-python-amd64) are also available if needed