Skip to content

fix(agent-server): drop pip's vendored pkg_resources - #5991

Merged
aivong-openhands merged 2 commits into
mainfrom
fix/agent-server-drop-pip-pkg-resources
Oct 15, 2026
Merged

aivong-openhands merged 2 commits into
mainfrom
fix/agent-server-drop-pip-pkg-resources

Conversation

@aivong-openhands

@aivong-openhands aivong-openhands commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Drop pip's unused vendored pkg_resources flagged for setuptools CVEs


AGENT:

Why

The agent-server -python and -python-slim images still report CVE-2025-47273 and CVE-2026-59890. Both are in setuptools 70.3.0, which pip 26.2.1 bundles only for its pkg_resources module. There is no fixed copy to bundle instead. setuptools removed pkg_resources in 82.0.0, and the CVE-2026-59890 fix only arrived in 83.0.0. So this PR removes pkg_resources from the pip that the pip-revendored stage already rebuilds.

On Python 3.11 and later, pip reads installed packages with importlib.metadata by default. It imports pkg_resources only 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_METADATA to a false value. Before, pip printed a deprecation warning and continued. Now it fails with an ImportError when it reads installed packages.

Summary

  • The pip-revendored stage deletes setuptools==70.3.0 from pip's vendor.txt and removes pip's pkg_resources.patch before vendoring sync. The rebuilt pip and its bom.cdx.json then contain no setuptools.
  • The retirement guard also checks whether upstream pip still bundles 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-runtime from openhands-agent-server/openhands/agent_server/docker/Dockerfile, then scan it with trivy image --scanners vuln.

  • Trivy 0.74.0, python-node-runtime from main vs. 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.
  • pip in the built image — installs from PyPI work, including two source packages built with --no-binary=:all:. Uninstall and reinstall from pip's HTTP cache work. pip check, show, freeze, inspect and debug all work.
  • _PIP_USE_IMPORTLIB_METADATA=0 — pip list fails with ImportError: cannot import name 'pkg_resources'. Nothing in this repo sets the variable.

Video/Screenshots

N/A.

Design Doc

None.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:c35c32c-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-c35c32c-python \
  ghcr.io/openhands/agent-server:c35c32c-python

All tags pushed for this build

ghcr.io/openhands/agent-server:c35c32c-golang-amd64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-golang-amd64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-golang-amd64
ghcr.io/openhands/agent-server:c35c32c-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:c35c32c-golang-arm64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-golang-arm64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-golang-arm64
ghcr.io/openhands/agent-server:c35c32c-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:c35c32c-java-amd64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-java-amd64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-java-amd64
ghcr.io/openhands/agent-server:c35c32c-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:c35c32c-java-arm64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-java-arm64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-java-arm64
ghcr.io/openhands/agent-server:c35c32c-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:c35c32c-python-amd64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-amd64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-amd64
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-amd64
ghcr.io/openhands/agent-server:c35c32c-python-arm64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-arm64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-arm64
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-arm64
ghcr.io/openhands/agent-server:c35c32c-python-minimal-amd64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-minimal-amd64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-minimal-amd64
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:c35c32c-python-minimal-arm64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-minimal-arm64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-minimal-arm64
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:c35c32c-python-slim-amd64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-slim-amd64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-slim-amd64
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:c35c32c-python-slim-arm64
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-slim-arm64
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-slim-arm64
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:c35c32c-golang
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-golang
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-golang
ghcr.io/openhands/agent-server:c35c32c-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:c35c32c-java
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-java
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-java
ghcr.io/openhands/agent-server:c35c32c-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:c35c32c-python-minimal
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-minimal
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-minimal
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-minimal
ghcr.io/openhands/agent-server:c35c32c-python-slim
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python-slim
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python-slim
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime-slim
ghcr.io/openhands/agent-server:c35c32c-python
ghcr.io/openhands/agent-server:c35c32cde9c1539962b26e058fe8bd5fe0ebe9aa-python
ghcr.io/openhands/agent-server:fix-agent-server-drop-pip-pkg-resources-python
ghcr.io/openhands/agent-server:c35c32c-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., c35c32c-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., c35c32c-python-amd64) are also available if needed

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>
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL499091986360% 
report-only-changed-files is enabled. No changed files were found in the coverage report :)

@aivong-openhands
aivong-openhands marked this pull request as ready for review October 14, 2026 21:40
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 all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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-revendored deletes setuptools==70.3.0 from pip's _vendor/vendor.txt, asserts no setuptools== line survives, and removes tools/vendoring/patches/pkg_resources.patch before vendoring sync. The rebuilt wheel and its bom.cdx.json contain no setuptools, so CVE-2025-47273 and CVE-2026-59890 disappear from the shipped -python/-python-slim images.
  • The retirement guard now also probes pkg_resources upstream, and documents the intended retirement condition (upstream drops pkg_resources and fixes urllib3/msgpack).

Verification performed on c35c32c

  • Pulled pip 26.2.1 source; tarball SHA-256 matches the ADD --checksum pin (65cac79d…).
  • Reproduced the stage locally (venv + vendoring==1.4.0 sync, then pip wheel .). Result: pip/_vendor/pkg_resources is absent, bom.cdx.json drops the setuptools 70.3.0 component and records urllib3 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 by pkg_resources/, pkg_resources.pyi, vendor.txt, and bom.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, and pip install from PyPI all succeed.
  • Confirmed the documented regression is exactly as stated: _PIP_USE_IMPORTLIB_METADATA=0 pip list now fails with ImportError: 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 patches importlib.metadata._PIP_USE_IMPORTLIB_METADATA = False on 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; the Pip re-vendoring retirement workflow 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

@aivong-openhands
aivong-openhands merged commit f5f849f into main Oct 15, 2026
55 checks passed
@aivong-openhands
aivong-openhands deleted the fix/agent-server-drop-pip-pkg-resources branch October 15, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants