From 26391d90adda1137e7f093048dff705a855b0c11 Mon Sep 17 00:00:00 2001 From: chen21019 Date: Sun, 8 Nov 2026 17:16:20 +0800 Subject: [PATCH 1/5] fix: rollback canceled Stack service upgrades through the native owner --- .github/workflows/security-release-gate.yml | 6 +- COMPATIBILITY.md | 10 ++ README.md | 7 ++ executor/handlers/upgrade_handler.go | 2 +- executor/handlers/upgrade_handler_test.go | 116 ++++++++++++++++++++ 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 executor/handlers/upgrade_handler_test.go diff --git a/.github/workflows/security-release-gate.yml b/.github/workflows/security-release-gate.yml index 03cf8248..effb1277 100644 --- a/.github/workflows/security-release-gate.yml +++ b/.github/workflows/security-release-gate.yml @@ -21,7 +21,7 @@ jobs: env: DAPPER_IMAGE: pasturestack/compose-cli-dapper:${{ github.sha }} TRIVY_IMAGE: aquasec/trivy:0.74.0@sha256:62b1e65e8869bc4b4c6aa4fa2b21595256c7c2f6018a9d9ad61caf87187c1969 - VERSION_OVERRIDE: 0.14.43 + VERSION_OVERRIDE: 0.14.44 PLATFORM_COMPAT_JAR_URL: https://github.com/PastureStack/orchestration-engine/releases/download/v0.183.281/orchestration-engine-0.183.281.jar PLATFORM_COMPAT_JAR_SHA256: da2a8a51562ed16e296f7e29e99482bb44042ff0834cca679bbe01d951ba1682 @@ -71,7 +71,7 @@ jobs: } run_ci - artifact="dist/artifacts/compose-executor-0.14.43-linux-amd64.gz" + artifact="dist/artifacts/compose-executor-0.14.44-linux-amd64.gz" test -s "$artifact" cp "$artifact" /tmp/compose-executor-first.gz @@ -83,7 +83,7 @@ jobs: mkdir -p evidence/product gzip -cd "$artifact" > evidence/product/compose-executor chmod +x evidence/product/compose-executor - evidence/product/compose-executor --version | grep -F '0.14.43' >/dev/null + evidence/product/compose-executor --version | grep -F '0.14.44' >/dev/null cp "$artifact" evidence/ ( cd evidence diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 847cb19d..2f67bf50 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -1,5 +1,15 @@ # Compatibility Contract +## 0.14.44 candidate: cancelled Stack service rollback + +The native Compose Stack rollback handler recognizes `canceled-upgrade` instead +of the nonexistent `cancel` state. Existing upgraded-service rollback, native +waiting and active-service behavior remain unchanged. A real HTTP-client +regression covers these states; original CI and publication are still pending. +Stack-level child-generation consistency is enforced by the matching Engine +owner, not by extra requests or configuration repairs in the AI layer. + + ## 0.14.43 published: stable approved Catalog service hashes Private preview and delegated service creation share one typed request and diff --git a/README.md b/README.md index 7f289ab0..7a6e4e40 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,13 @@ PastureStack is an independent community effort to preserve, audit, and moderniz **Upstream:** [`rancher/rancher-compose-executor`](https://github.com/rancher/rancher-compose-executor). This GitHub fork preserves upstream history, authorship, dates, tags, licenses, and bundled dependency notices; PastureStack maintenance is consolidated into one commit after the preserved upstream boundary. +## Development candidate + +The 0.14.44 source candidate repairs native rollback of a Stack service in +`canceled-upgrade`. It preserves the existing wait and per-service native action +contract. This source change is not a published binary or deployed-workflow +acceptance; the current published version remains 0.14.43. + ## Project status The maintained source uses Ubuntu 26.04, Go 1.27.3, and Python 3.14.9 for integration-source verification. Ubuntu build packages, the base image, and Go archives are fixed by snapshot, exact version, and SHA-256. Go dependencies are managed by `go.mod` and a reproducible module vendor tree. AWS access uses AWS SDK for Go v2; container structures use the maintained Moby API module; the command parser uses urfave/cli v3. The abandoned AWS SDK v1, Rancher generated-client modules, event-subscriber module, `docker/libcompose`, and other GOPATH-era dependencies have been removed. The small Rancher 1.6 protocol boundary retained by this compatibility CLI is maintained and tested locally. The Dapper builder does not embed a Docker CLI or mount a Docker socket; Docker is required only on the host to create and run the isolated builder. The maintained binaries are `pasturestack-compose` and `compose-executor`; `platform-compose.yml` is the preferred companion file. Releases are built and verified from the preserved source history; this repository does not enable automated deployment. diff --git a/executor/handlers/upgrade_handler.go b/executor/handlers/upgrade_handler.go index f42fda8d..e47d94bd 100644 --- a/executor/handlers/upgrade_handler.go +++ b/executor/handlers/upgrade_handler.go @@ -103,7 +103,7 @@ func RollbackStack(event *events.Event, apiClient *client.RancherClient) error { if err := wait(apiClient, &service); err != nil { return err } - if service.State == "upgraded" || service.State == "cancel" { + if service.State == "upgraded" || service.State == "canceled-upgrade" { service, err := apiClient.Service.ActionRollback(&service) if err != nil { return err diff --git a/executor/handlers/upgrade_handler_test.go b/executor/handlers/upgrade_handler_test.go new file mode 100644 index 00000000..757efc39 --- /dev/null +++ b/executor/handlers/upgrade_handler_test.go @@ -0,0 +1,116 @@ +package handlers + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "reflect" + "sync" + "testing" + + "github.com/PastureStack/compose-cli/internal/events" + client "github.com/PastureStack/compose-cli/internal/rancherclient/v2" +) + +func TestRollbackStackCanceledUpgradeUsesNativeRollbackAndWait(t *testing.T) { + for _, state := range []string{"canceled-upgrade", "upgraded", "active", "upgrading"} { + t.Run(state, func(t *testing.T) { + var mu sync.Mutex + var trace []string + rolledBack := false + var server *httptest.Server + service := func(current string) map[string]interface{} { + return map[string]interface{}{ + "id": "1s7", "type": "service", "state": current, "transitioning": "no", + "links": map[string]string{"self": server.URL + "/services/1s7"}, + "actions": map[string]string{"rollback": server.URL + "/services/1s7?action=rollback"}, + } + } + server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + defer mu.Unlock() + w.Header().Set("Content-Type", "application/json") + encode := func(value interface{}) { + if err := json.NewEncoder(w).Encode(value); err != nil { + t.Errorf("encode fixture response: %v", err) + } + } + switch { + case r.Method == http.MethodGet && r.URL.Path == "/schemas": + w.Header().Set("X-API-Schemas", server.URL+"/schemas") + encode(map[string]interface{}{"data": []interface{}{ + map[string]interface{}{"id": "stack", "resourceMethods": []string{"GET"}, "links": map[string]string{"collection": server.URL + "/stacks"}}, + map[string]interface{}{"id": "service", "resourceMethods": []string{"GET"}, "links": map[string]string{"collection": server.URL + "/services"}}, + map[string]interface{}{"id": "publish", "collectionMethods": []string{"POST"}, "links": map[string]string{"collection": server.URL + "/publish"}}, + }}) + case r.Method == http.MethodGet && r.URL.Path == "/stacks/1st7": + encode(map[string]interface{}{ + "id": "1st7", "externalId": "current-id", "previousExternalId": "previous-id", + "environment": map[string]string{"VALUE": "current"}, "previousEnvironment": map[string]string{"VALUE": "previous"}, + "links": map[string]string{"services": server.URL + "/stacks/1st7/services"}, + }) + case r.Method == http.MethodGet && r.URL.Path == "/stacks/1st7/services": + listed := service(state) + if state == "upgrading" { + listed["transitioning"] = "yes" + } + encode(map[string]interface{}{"data": []interface{}{listed}}) + case r.Method == http.MethodGet && r.URL.Path == "/services/1s7" && r.URL.RawQuery == "": + current := state + if rolledBack { + current = "active" + } else if state == "upgrading" { + current = "upgraded" + } + trace = append(trace, "GET "+current) + encode(service(current)) + case r.Method == http.MethodPost && r.URL.Path == "/services/1s7" && r.URL.Query().Get("action") == "rollback": + trace = append(trace, "POST rollback") + if rolledBack || state == "active" { + t.Error("unexpected duplicate or active-child rollback") + } + rolledBack = true + pending := service("rolling-back") + pending["transitioning"] = "yes" + encode(pending) + case r.Method == http.MethodPost && r.URL.Path == "/publish": + trace = append(trace, "POST reply") + var result client.Publish + if err := json.NewDecoder(r.Body).Decode(&result); err != nil { + t.Errorf("decode original reply: %v", err) + } else if result.Name != "reply.one" || result.Data["externalId"] != "previous-id" || result.Data["previousExternalId"] != nil || result.Data["previousEnvironment"] != nil { + t.Errorf("original rollback reply changed: %#v", result) + } else if environment, ok := result.Data["environment"].(map[string]interface{}); !ok || environment["VALUE"] != "previous" { + t.Errorf("previous environment not restored: %#v", result.Data) + } + encode(map[string]interface{}{}) + default: + t.Errorf("unexpected native route: %s %s", r.Method, r.URL.Path) + http.NotFound(w, r) + } + })) + defer server.Close() + c, err := client.NewRancherClient(&client.ClientOpts{Url: server.URL + "/schemas"}) + if err != nil { + t.Fatal(err) + } + event := &events.Event{ID: "rollback-event", ResourceID: "1st7", ReplyTo: "reply.one"} + if err := RollbackStack(event, c); err != nil { + t.Fatal(err) + } + mu.Lock() + defer mu.Unlock() + first := state + if first == "upgrading" { + first = "upgraded" + } + want := []string{"GET " + first, "POST rollback", "GET active", "POST reply"} + if state == "active" { + want = []string{"GET active", "POST reply"} + } + if !reflect.DeepEqual(trace, want) { + t.Fatalf("native rollback/readiness order = %v, want %v", trace, want) + } + }) + } +} From c61cc5cb19581df7e28cb6c777c61148f65d7552 Mon Sep 17 00:00:00 2001 From: chen21019 Date: Sun, 8 Nov 2026 17:22:01 +0800 Subject: [PATCH 2/5] build: fetch the pinned CA package from the official Ubuntu snapshot --- Dockerfile.dapper | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 1bd3e755..21faf4e0 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -3,7 +3,7 @@ FROM ubuntu:26.04@sha256:2260313b31c8c011cd2eebe728008efac1b3982be73eb71348ea264 COPY ubuntu-apt.lock /licenses/ubuntu-apt.lock COPY ubuntu-security-packages.lock /licenses/ubuntu-security-packages.lock COPY ubuntu-apt-security.lock /licenses/ubuntu-apt-security.lock -ADD --checksum=sha256:5b6326f1932cfd7be57130561dc78192f09ed9f58bfbe6606ed0c50510c3b6cd https://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20260816ubuntu0.26.04.1_all.deb /tmp/ca-certificates.deb +ADD --checksum=sha256:5b6326f1932cfd7be57130561dc78192f09ed9f58bfbe6606ed0c50510c3b6cd https://snapshot.ubuntu.com/ubuntu/20261104T000000Z/pool/main/c/ca-certificates/ca-certificates_20260816ubuntu0.26.04.1_all.deb /tmp/ca-certificates.deb ARG GO_VERSION=1.27.3 ARG GO_SHA256_amd64=65efbc80fdc1fa2cd2631cad5b481777a68e8725f34e89f50fc6ac714e379b40 @@ -48,7 +48,7 @@ ENV DEBIAN_FRONTEND=noninteractive \ XDG_CONFIG_HOME=/tmp/go-config \ PATH=/go/bin:/usr/local/go/bin:${PATH} -ADD --checksum=sha256:5b6326f1932cfd7be57130561dc78192f09ed9f58bfbe6606ed0c50510c3b6cd https://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20260816ubuntu0.26.04.1_all.deb /opt/pasturestack-ca-certificates.deb +ADD --checksum=sha256:5b6326f1932cfd7be57130561dc78192f09ed9f58bfbe6606ed0c50510c3b6cd https://snapshot.ubuntu.com/ubuntu/20261104T000000Z/pool/main/c/ca-certificates/ca-certificates_20260816ubuntu0.26.04.1_all.deb /opt/pasturestack-ca-certificates.deb RUN set -eux; \ . /licenses/ubuntu-apt.lock; \ bootstrap_snapshot=${UBUNTU_APT_SNAPSHOT}; \ From 08cb85a32f7a8287b4566445ec15aec6196aeac7 Mon Sep 17 00:00:00 2001 From: chen21019 Date: Sun, 8 Nov 2026 17:44:34 +0800 Subject: [PATCH 3/5] build: repair pinned pip bytes and bounded compatibility downloads --- .github/dapper-unfixed.json | 44 ++++++++++++ .../test_builder_vulnerability_policy.py | 16 +++++ .github/workflows/builder-security.yml | 6 +- Dockerfile.dapper | 2 +- scripts/install-python-security-tools | 8 +-- scripts/pip-security/README.md | 21 ++++-- scripts/pip-security/build-pip-overlay.py | 57 ++++++++++++++-- .../pip-security/check-pip-vendor-slice.py | 43 ++++++++++-- .../filter-pip-vendor-findings.py | 27 ++++++-- scripts/pip-security/inputs.json | 21 +++++- scripts/pip-security/test-pip-overlay.py | 3 +- scripts/pip-security/test-pip-vex.py | 67 ++++++++++++++++++- .../pip-security/vendor_source_inventory.py | 2 +- scripts/run-platform-compat | 3 +- 14 files changed, 279 insertions(+), 41 deletions(-) diff --git a/.github/dapper-unfixed.json b/.github/dapper-unfixed.json index e76856a9..63050776 100644 --- a/.github/dapper-unfixed.json +++ b/.github/dapper-unfixed.json @@ -3901,6 +3901,50 @@ "officialEvidence": "https://ubuntu.com/security/CVE-2026-82560", "reason": "Ubuntu26.04 remains vulnerable without a released fix. Exact Dapper build-only package; Trivy Ubuntu severity MEDIUM. Upstream CVSS7.5 remains disclosed.", "checkedAt": "2026-11-05" + }, + { + "package": "libpython3.14-minimal", + "purl": "pkg:deb/ubuntu/libpython3.14-minimal@3.14.4-1ubuntu0.2?arch=amd64&distro=ubuntu-26.04", + "checkedAt": "2026-11-08", + "status": "no_official_fix", + "id": "CVE-2026-7210", + "severity": "MEDIUM", + "reason": "Canonical Ubuntu 26.04 Python 3.14 status is Vulnerable with no official fixed resolute package (official page updated 2026-11-06, verified by the release owner on 2026-11-08). Upstream repair depends on libexpat; no unpublished cherry-pick or not-affected claim is used. Retain this exact Medium raw finding; any FixedVersion, severity increase or changed package identity remains rejected.", + "version": "3.14.4-1ubuntu0.2", + "officialEvidence": "https://ubuntu.com/security/CVE-2026-7210" + }, + { + "package": "libpython3.14-stdlib", + "purl": "pkg:deb/ubuntu/libpython3.14-stdlib@3.14.4-1ubuntu0.2?arch=amd64&distro=ubuntu-26.04", + "checkedAt": "2026-11-08", + "status": "no_official_fix", + "id": "CVE-2026-7210", + "severity": "MEDIUM", + "reason": "Canonical Ubuntu 26.04 Python 3.14 status is Vulnerable with no official fixed resolute package (official page updated 2026-11-06, verified by the release owner on 2026-11-08). Upstream repair depends on libexpat; no unpublished cherry-pick or not-affected claim is used. Retain this exact Medium raw finding; any FixedVersion, severity increase or changed package identity remains rejected.", + "version": "3.14.4-1ubuntu0.2", + "officialEvidence": "https://ubuntu.com/security/CVE-2026-7210" + }, + { + "package": "python3.14", + "purl": "pkg:deb/ubuntu/python3.14@3.14.4-1ubuntu0.2?arch=amd64&distro=ubuntu-26.04", + "checkedAt": "2026-11-08", + "status": "no_official_fix", + "id": "CVE-2026-7210", + "severity": "MEDIUM", + "reason": "Canonical Ubuntu 26.04 Python 3.14 status is Vulnerable with no official fixed resolute package (official page updated 2026-11-06, verified by the release owner on 2026-11-08). Upstream repair depends on libexpat; no unpublished cherry-pick or not-affected claim is used. Retain this exact Medium raw finding; any FixedVersion, severity increase or changed package identity remains rejected.", + "version": "3.14.4-1ubuntu0.2", + "officialEvidence": "https://ubuntu.com/security/CVE-2026-7210" + }, + { + "package": "python3.14-minimal", + "purl": "pkg:deb/ubuntu/python3.14-minimal@3.14.4-1ubuntu0.2?arch=amd64&distro=ubuntu-26.04", + "checkedAt": "2026-11-08", + "status": "no_official_fix", + "id": "CVE-2026-7210", + "severity": "MEDIUM", + "reason": "Canonical Ubuntu 26.04 Python 3.14 status is Vulnerable with no official fixed resolute package (official page updated 2026-11-06, verified by the release owner on 2026-11-08). Upstream repair depends on libexpat; no unpublished cherry-pick or not-affected claim is used. Retain this exact Medium raw finding; any FixedVersion, severity increase or changed package identity remains rejected.", + "version": "3.14.4-1ubuntu0.2", + "officialEvidence": "https://ubuntu.com/security/CVE-2026-7210" } ] } diff --git a/.github/scripts/test_builder_vulnerability_policy.py b/.github/scripts/test_builder_vulnerability_policy.py index ed6f22f7..e649a00e 100644 --- a/.github/scripts/test_builder_vulnerability_policy.py +++ b/.github/scripts/test_builder_vulnerability_policy.py @@ -196,6 +196,22 @@ def test_kernel_runtime_present_rejected(self): def test_repository_mismatch_rejected(self): self.ledger["repository"] = "other" with self.assertRaises(ValueError): self.check() + def test_python_7210_exact_nofix_does_not_allow_a_fix_or_identity_drift(self): + self.ledger = json.loads((Path(__file__).resolve().parents[1] / "dapper-unfixed.json").read_text()) + rows = [r for r in self.ledger["unfixed"] if r["id"] == "CVE-2026-7210"] + self.assertEqual({r["package"] for r in rows}, {"libpython3.14-minimal", "libpython3.14-stdlib", "python3.14", "python3.14-minimal"}) + self.assertEqual(len(rows), 4) + for row in rows: + finding = {"VulnerabilityID": row["id"], "PkgName": row["package"], + "InstalledVersion": row["version"], "PkgIdentifier": {"PURL": row["purl"]}, + "Severity": "MEDIUM", "FixedVersion": ""} + self.report["Results"][0]["Vulnerabilities"] = [finding] + self.assertEqual(self.check(), []) + for field, value in [("FixedVersion", "3.14.4-1ubuntu0.3"), ("Severity", "HIGH"), + ("PkgIdentifier", {"PURL": row["purl"] + "&changed=1"})]: + self.report["Results"][0]["Vulnerabilities"] = [dict(finding, **{field: value})] + self.assertTrue(self.check(), (row["package"], field)) + def test_malformed_report_rejected(self): self.report["Results"][0]["Vulnerabilities"] = "not-a-list" with self.assertRaises(ValueError): self.check() diff --git a/.github/workflows/builder-security.yml b/.github/workflows/builder-security.yml index 4964e965..d5a1516e 100644 --- a/.github/workflows/builder-security.yml +++ b/.github/workflows/builder-security.yml @@ -61,15 +61,15 @@ jobs: case "$path" in *.whl) if test -e "$path"; then - printf "%s %s\n" be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a "$path" | sha256sum -c - + printf "%s %s\n" 2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36 "$path" | sha256sum -c - else printf "REMOVED_OLD_DISTRO_WHEEL %s\n" "$path" fi ;; esac done test "$(find /usr/share/python-wheels -maxdepth 1 -name "pip-*.whl" | wc -l)" -eq 1 - printf "%s %s\n" be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a \ - /usr/share/python-wheels/pip-26.2.2+pasturestack.1-py3-none-any.whl | sha256sum -c - + printf "%s %s\n" 2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36 \ + /usr/share/python-wheels/pip-26.2.2+pasturestack.2-py3-none-any.whl | sha256sum -c - ' > evidence/distro-pip-seed-paths.txt - name: Retain raw scan and apply exact pip and builder policies run: | diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 21faf4e0..e02abdd6 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -115,7 +115,7 @@ RUN python3 /opt/python-security/scripts/build-pip-overlay.py --work /tmp/pip-ov rm -rf /tmp/pip-overlay-build ADD --checksum=sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl /opt/python-security/certifi-2026.10.19-py3-none-any.whl COPY scripts/install-python-security-tools /usr/local/bin/install-python-security-tools -ENV VIRTUALENV_PIP=26.2.2+pasturestack.1 VIRTUALENV_EXTRA_SEARCH_DIR=/usr/share/python-wheels VIRTUALENV_NO_PERIODIC_UPDATE=1 +ENV VIRTUALENV_PIP=26.2.2+pasturestack.2 VIRTUALENV_EXTRA_SEARCH_DIR=/usr/share/python-wheels VIRTUALENV_NO_PERIODIC_UPDATE=1 RUN PYTHON_SECURITY_VIRTUALENV_PYTHON=python3 bash /usr/local/bin/install-python-security-tools RUN case "${DAPPER_HOST_ARCH}" in \ diff --git a/scripts/install-python-security-tools b/scripts/install-python-security-tools index b4f66248..85540091 100644 --- a/scripts/install-python-security-tools +++ b/scripts/install-python-security-tools @@ -1,11 +1,11 @@ #!/usr/bin/env bash # Keep Ubuntu's ABI; install the reproducible local pip security rebuild and seeds. set -euo pipefail -expected=26.2.2+pasturestack.1 +expected=26.2.2+pasturestack.2 pip_wheel=/opt/python-security/pip-$expected-py3-none-any.whl certifi_wheel=/opt/python-security/certifi-2026.10.19-py3-none-any.whl test -s "$pip_wheel" -printf '%s %s\n' be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a "$pip_wheel" | sha256sum -c - +printf '%s %s\n' 2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36 "$pip_wheel" | sha256sum -c - test -s "$certifi_wheel" if dpkg-query -W -f='${db:Status-Status}' python3-pip 2>/dev/null | grep -qx installed; then apt-get purge -y python3-pip @@ -14,12 +14,12 @@ PYTHONPATH="$pip_wheel" python3 -m pip install --break-system-packages --no-inde install -d /usr/share/python-wheels find /usr/share/python-wheels -maxdepth 1 -type f -name 'pip-*.whl' -delete install -m 0644 "$pip_wheel" /usr/share/python-wheels/ -python3 -c 'import pip, certifi, pip._vendor.certifi as c; assert pip.__version__ == "26.2.2+pasturestack.1"; assert certifi.__version__ == c.__version__ == "2026.10.19"' +python3 -c 'import pip, certifi, pip._vendor.certifi as c; assert pip.__version__ == "26.2.2+pasturestack.2"; assert certifi.__version__ == c.__version__ == "2026.10.19"' python3 /opt/python-security/scripts/test-pip-overlay.py scratch=$(mktemp -d) trap 'rm -rf "$scratch"' EXIT if python3 -c 'import ensurepip' 2>/dev/null; then - python3 -c 'import ensurepip; assert ensurepip.version() == "26.2.2+pasturestack.1"' + python3 -c 'import ensurepip; assert ensurepip.version() == "26.2.2+pasturestack.2"' python3 -m venv "$scratch/venv" ensurepip_status=$expected else diff --git a/scripts/pip-security/README.md b/scripts/pip-security/README.md index 9d0a314d..e8444351 100644 --- a/scripts/pip-security/README.md +++ b/scripts/pip-security/README.md @@ -1,12 +1,13 @@ # 共用 pip 安全重包 -這是內部衍生版本 `26.2.2+pasturestack.1`,不是 PyPA 官方 pip 發布。 +這是內部衍生版本 `26.2.2+pasturestack.2`,不是 PyPA 官方 pip 發布。 所有專案及映像的對外 release tag 仍使用原本的純數字規則。 來源是官方 pip `26.2.2` 的 commit `b3b696fe2122f2339d782517559bfade2cb6b879`。使用上游 `vendoring==1.4.0` -及 pip 原有的三份 urllib3 patches,把官方 PyPI urllib3 改成 `2.8.0`。 -不手改 urllib3 原始碼、不 debundle。其餘內嵌 library 的每一個檔案均須 +及 pip 原有的三份 urllib3 patches,把官方 PyPI urllib3 改成 `2.8.0`, +並沿共用 recipe 納入官方 msgpack `1.2.3` pure-Python wheel。 +不手改 library 原始碼、不 debundle。其餘內嵌 library 的每一個檔案均須 保持原始 SHA-256;licenses、內嵌 CycloneDX SBOM 及 wheel RECORD 全部保留。 ## 建置 @@ -24,10 +25,10 @@ python3 build-pip-overlay.py --work /tmp/pip-rebuild --output /tmp/pip-dist2 \ 下載後的 vendoring、安裝工具與 wheel 建置使用 `PIP_NO_INDEX=1`。 每次建置都做兩次 wheel 並比較位元組,驗證全部 RECORD hashes、無 native -extension、保留 license,以及只有 urllib3 library 有變更。 +extension、保留 license,以及只有 urllib3/msgpack library 有變更。 輸出為 wheel、`build-evidence.json`、`pip-vendor.cdx.json`、工具 hash lock -與來源 manifest。已在 Python 3.12 建出 wheel SHA-256: -`be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a`。 +與來源 manifest。正常建置必須符合共用已驗證的 wheel SHA-256: +`2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36`。 ## 安裝與三種 seed 路徑 @@ -60,7 +61,7 @@ bash verify-pip-runtime.sh --virtualenv /usr/share/python-wheels - CVE-2026-57585:上游 fix commit `2c56ddb5d0025ed481d962c0f5d62d19dec7476d` 只修 Cython/C 實作;本 wheel 無 `.so/.pyd`,實際 `Unpacker` 為 `pip._vendor.msgpack.fallback`。 - 不為消除套件名稱掃描結果而更動未受影響的 msgpack。 + 共用 recipe 使用官方 msgpack 1.2.3,仍不將獨立安裝的舊版套件納入排除。 - setuptools 70.3.0 僅保留 `pkg_resources`;CVE-2025-47273 所需的 `setuptools/package_index.py` 與 CVE-2026-59890 所需的 `setuptools/command/egg_info.py` 均不存在。 @@ -87,3 +88,9 @@ distribution、外來 CycloneDX/SPDX、不同 bytes 與未知 wheel。虛擬環 app-data 放在其自有暫存目錄,不留下另一份未追蹤 seed。 官方政策:https://pip.pypa.io/en/stable/development/vendoring-policy/ + + +CVE-2026-8643 已由上游 pip 26.1.2 修正。本版僅在 exact `.2` wheel、 +299 個 vendor 檔案與 157 個 live core 檔案及完整集合逐 byte 相符時, +資格化舊 distro seed 的該筆 metadata finding;不是 no-fix 豁免。 +Compose 原有全檔案來源盤點與 foreign distribution 拒絕保持。 diff --git a/scripts/pip-security/build-pip-overlay.py b/scripts/pip-security/build-pip-overlay.py index 88b53806..21918a0b 100644 --- a/scripts/pip-security/build-pip-overlay.py +++ b/scripts/pip-security/build-pip-overlay.py @@ -134,25 +134,61 @@ def main(): assert (generated / "__init__.py").is_file() shutil.rmtree(vendor / "urllib3") # exact disposable source subtree only shutil.copytree(generated, vendor / "urllib3") + # Build the official msgpack sdist without C extensions, then use the same + # upstream vendoring tool/namespace as pip. No hand-copied namespace code. + msgpack_parent = scratch / "msgpack-source" + msgpack_parent.mkdir() + with tarfile.open(paths["msgpack-source"][0]) as archive: + for member in archive.getmembers(): + assert not member.issym() and not member.islnk() + assert (msgpack_parent / member.name).resolve().is_relative_to(msgpack_parent) + archive.extractall(msgpack_parent, filter="data") + msgpack_source = next(msgpack_parent.iterdir()) + msgpack_environment = dict(environment, MSGPACK_PUREPYTHON="1") + run([python, "-m", "pip", "wheel", "--no-build-isolation", "--no-deps", + "--wheel-dir", downloads, msgpack_source], scratch, msgpack_environment) + msgpack_wheels = list(downloads.glob("msgpack-1.2.3-py3-none-any.whl")) + assert len(msgpack_wheels) == 1 + with zipfile.ZipFile(msgpack_wheels[0]) as archive: + assert not any(name.endswith((".so", ".pyd")) for name in archive.namelist()) + msgpack_scoped = scratch / "msgpack-vendoring" + msgpack_vendor = msgpack_scoped / "src/pip/_vendor" + msgpack_vendor.mkdir(parents=True) + (msgpack_vendor / "vendor.txt").write_text("msgpack==1.2.3\n") + (msgpack_scoped / "tools/vendoring/patches").mkdir(parents=True) + (msgpack_scoped / "pyproject.toml").write_text("""[tool.vendoring] + destination = "src/pip/_vendor/" + requirements = "src/pip/_vendor/vendor.txt" + namespace = "pip._vendor" + protected-files = ["vendor.txt"] + patches-dir = "tools/vendoring/patches" + [tool.vendoring.transformations] + drop = ["*.dist-info/", "bin/"] +""") + run([python, "-m", "vendoring", "sync", "-v"], msgpack_scoped, environment) + assert (msgpack_vendor / "msgpack/__init__.py").is_file() + shutil.rmtree(vendor / "msgpack") # exact disposable source subtree only + shutil.copytree(msgpack_vendor / "msgpack", vendor / "msgpack") vendor_txt = vendor / "vendor.txt" text = vendor_txt.read_text() assert text.count("urllib3==2.7.0") == 1 - vendor_txt.write_text(text.replace("urllib3==2.7.0", "urllib3==2.8.0")) + assert text.count("msgpack==1.1.2") == 1 + vendor_txt.write_text(text.replace("urllib3==2.7.0", "urllib3==2.8.0").replace("msgpack==1.1.2", "msgpack==1.2.3")) version_file = source / "src/pip/__init__.py" version_file.write_text(version_file.read_text().replace('__version__ = "26.2.2"', f'__version__ = "{config["version"]}"')) readme = vendor / "README.rst" with readme.open("a") as handle: handle.write("\n\nPastureStack security rebuild\n============================\n\n" - "This downstream local-version wheel uses released urllib3 2.8.0\n" + "This downstream local-version wheel uses released urllib3 2.8.0 and msgpack 1.2.3\n" "through upstream vendoring 1.4.0 and pip's unchanged urllib3\n" - "patches. Other vendored library sources and licenses are unchanged.\n" + "patches and pure-Python msgpack. Other vendored sources and licenses are unchanged.\n" "It is not an official PyPA pip release.\n") run([python, "-c", "from pathlib import Path; from vendoring.sbom import create_sbom_file; create_sbom_file('pip._vendor', Path('src/pip/_vendor/vendor.txt'), Path('src/pip/_vendor/bom.cdx.json'))"], source, environment) current = {str(p.relative_to(vendor)): sha(p) for p in vendor.rglob("*") if p.is_file()} allowed = {"vendor.txt", "README.rst", "bom.cdx.json"} - assert {p: value for p, value in original.items() if not p.startswith("urllib3/") and p not in allowed} == { - p: value for p, value in current.items() if not p.startswith("urllib3/") and p not in allowed} + assert {p: value for p, value in original.items() if not p.startswith(("urllib3/", "msgpack/")) and p not in allowed} == { + p: value for p, value in current.items() if not p.startswith(("urllib3/", "msgpack/")) and p not in allowed} wheels = [] for suffix in ("first", "second"): directory = scratch / suffix @@ -180,11 +216,18 @@ def main(): assert "pip/_vendor/pkg_resources/__init__.py" in names assert not any("setuptools/package_index" in name for name in names) shutil.copy2(vendor / "bom.cdx.json", output / "pip-vendor.cdx.json") - report = {"version": config["version"], "upstreamVersion": config["upstreamVersion"], + with zipfile.ZipFile(wheel) as archive: + inventory = sorted([{"path": name.removeprefix("pip/_vendor/"), "sha256": hashlib.sha256(archive.read(name)).hexdigest()} + for name in archive.namelist() if name.startswith("pip/_vendor/") and not name.endswith("/")], + key=lambda item: item["path"]) + inventory_sha = hashlib.sha256(json.dumps(inventory, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + report = {"status": "EXACT_PINNED_BUILD", + "vendorInventoryCount": len(inventory), "vendorInventorySha256": inventory_sha, + "vendorInventory": inventory, "version": config["version"], "upstreamVersion": config["upstreamVersion"], "upstreamCommit": config["sourceCommit"], "wheel": wheel.name, "sha256": sha(wheel), "twoBuildsByteIdentical": True, "allRecordHashesVerified": True, "nativeExtensionsPresent": False, - "licenses": licenses, "onlyVendoredLibraryChanged": "urllib3", "urllib3": "2.8.0"} + "licenses": licenses, "onlyVendoredLibrariesChanged": {"urllib3": "2.8.0", "msgpack": "1.2.3"}, "urllib3": "2.8.0", "msgpack": "1.2.3"} (output / "build-evidence.json").write_text(json.dumps(report, indent=2) + "\n") shutil.copy2(requirements, output / "tools.lock") shutil.copy2(Path(__file__).with_name("inputs.json"), output / "inputs.json") diff --git a/scripts/pip-security/check-pip-vendor-slice.py b/scripts/pip-security/check-pip-vendor-slice.py index 571d3d4b..f7e9e44e 100644 --- a/scripts/pip-security/check-pip-vendor-slice.py +++ b/scripts/pip-security/check-pip-vendor-slice.py @@ -7,12 +7,10 @@ import json from pathlib import Path import zipfile -import pip -from pip._vendor import msgpack, urllib3 from vendor_source_inventory import inventory -EXPECTED_SHA = "be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a" -BOM_SHA = "3581cb8f0a6128c19ccec4e9aeab0d3ac8212fd19bd19d485b2e24fd4dc10f2a" +EXPECTED_SHA = "2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36" +BOM_SHA = "59163489fd72f0732db7ef5d532b4ea83565d2113c9179fdfbdf67e6fddd5f6b" FINDINGS = { "GHSA-6v7p-g79w-8964": ("msgpack", "1.1.2", "C/Cython unpacker is absent; runtime selects pure Python fallback"), "CVE-2026-57585": ("msgpack", "1.1.2", "C/Cython unpacker is absent; runtime selects pure Python fallback"), @@ -30,13 +28,40 @@ def require_absent_vulnerable_modules(names): assert not any(name.startswith("pip/_vendor/setuptools/") for name in names), "Full setuptools module present" +def require_pip_core_exact(archive, live): + """Match every installed pip core file and its complete set to the pinned wheel.""" + expected = {name.removeprefix("pip/"): archive.read(name) for name in archive.namelist() + if name.startswith("pip/") and not name.startswith("pip/_vendor/") and not name.endswith("/")} + assert expected, "Missing pip core source in wheel" + def live_core_files(directory, prefix=""): + for entry in directory.iterdir(): + if entry.name == "__pycache__" or (not prefix and entry.name == "_vendor"): + continue + relative = prefix + entry.name + if entry.is_dir(): + yield from live_core_files(entry, relative + "/") + else: + yield relative + assert set(live_core_files(live)) == set(expected), "Unexpected or missing live pip core files" + inventory = [] + for name, content in sorted(expected.items()): + assert live.joinpath(name).read_bytes() == content, "Installed pip core differs from wheel: " + name + inventory.append({"path": name, "sha256": hashlib.sha256(content).hexdigest()}) + return {"pipCoreFilesByteCompared": len(inventory), "pipCoreFileSetMatched": True, + "pipCoreInventorySha256": hashlib.sha256(json.dumps(inventory, sort_keys=True, separators=(",", ":")).encode()).hexdigest()} + + def verify(wheel): + import pip + from pip._vendor import msgpack, urllib3 assert hashlib.sha256(wheel.read_bytes()).hexdigest() == EXPECTED_SHA - assert pip.__version__ == "26.2.2+pasturestack.1" + assert pip.__version__ == "26.2.2+pasturestack.2" assert urllib3.__version__ == "2.8.0" + assert msgpack.__version__ == "1.2.3" assert msgpack.Unpacker.__module__ == "pip._vendor.msgpack.fallback" live = importlib.resources.files("pip") checked = 0 + vendor_inventory = [] with zipfile.ZipFile(wheel) as archive: names = archive.namelist() expected_files = set() @@ -45,9 +70,11 @@ def verify(wheel): continue assert live.joinpath(name.removeprefix("pip/")).read_bytes() == archive.read(name), name expected_files.add(name.removeprefix("pip/_vendor/")) + vendor_inventory.append({"path": name.removeprefix("pip/_vendor/"), "sha256": hashlib.sha256(archive.read(name)).hexdigest()}) checked += 1 assert not any(name.startswith("pip/_vendor/") and name.endswith((".so", ".pyd")) for name in names) require_absent_vulnerable_modules(names) + core_proof = require_pip_core_exact(archive, live) def live_files(directory, prefix=""): for entry in directory.iterdir(): if entry.name == "__pycache__": @@ -66,7 +93,9 @@ def live_files(directory, prefix=""): assert distribution.version != "70.3.0", "A full setuptools 70.3.0 distribution is installed" if distribution.metadata.get("Name", "").lower() == "msgpack": assert distribution.version != "1.1.2", "A separate msgpack 1.1.2 distribution is installed" - return {"verifiedWheelSha256": EXPECTED_SHA, "verifiedWheelPath": str(wheel.resolve()), "pip": pip.__version__, + vendor_inventory.sort(key=lambda item: item["path"]) + vendor_sha = hashlib.sha256(json.dumps(vendor_inventory, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + return {**core_proof, "vendorInventorySha256": vendor_sha, "verifiedWheelSha256": EXPECTED_SHA, "verifiedWheelPath": str(wheel.resolve()), "pip": pip.__version__, "urllib3": urllib3.__version__, "vendorFilesByteCompared": checked, "msgpackImplementation": msgpack.Unpacker.__module__, "setuptoolsPackageAbsent": True, "vulnerableModulesAbsent": ["msgpack._cmsgpack", "setuptools.wheel"], @@ -90,7 +119,7 @@ def live_files(directory, prefix=""): except ImportError: # compose's distro runtime intentionally has no ensurepip package. # Its build retains the verified input at this fixed, non-user path. - result = verify(Path("/opt/python-security/pip-26.2.2+pasturestack.1-py3-none-any.whl")) + result = verify(Path("/opt/python-security/pip-26.2.2+pasturestack.2-py3-none-any.whl")) else: with ensurepip._get_pip_whl_path_ctx() as wheel: result = verify(Path(wheel)) diff --git a/scripts/pip-security/filter-pip-vendor-findings.py b/scripts/pip-security/filter-pip-vendor-findings.py index 3af899fe..71ea2556 100644 --- a/scripts/pip-security/filter-pip-vendor-findings.py +++ b/scripts/pip-security/filter-pip-vendor-findings.py @@ -7,9 +7,9 @@ from pathlib import Path from vendor_source_inventory import SBOM_PATHS, WHEEL_PATHS -WHEEL_SHA = "be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a" -WHEEL_NAME = "pip-26.2.2+pasturestack.1-py3-none-any.whl" -BOM_SHA = "3581cb8f0a6128c19ccec4e9aeab0d3ac8212fd19bd19d485b2e24fd4dc10f2a" +WHEEL_SHA = "2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36" +WHEEL_NAME = "pip-26.2.2+pasturestack.2-py3-none-any.whl" +BOM_SHA = "59163489fd72f0732db7ef5d532b4ea83565d2113c9179fdfbdf67e6fddd5f6b" RULES = { "GHSA-6v7p-g79w-8964": ("msgpack", "1.1.2"), "CVE-2026-57585": ("msgpack", "1.1.2"), @@ -32,7 +32,7 @@ def apply(raw, proof, subject): for item in sources)) valid = (proof["verifiedWheelSha256"] == WHEEL_SHA and proof.get("verifiedWheelPath") in WHEEL_PATHS and - proof["pip"] == "26.2.2+pasturestack.1" and proof["urllib3"] == "2.8.0" and + proof["pip"] == "26.2.2+pasturestack.2" and proof["urllib3"] == "2.8.0" and proof["msgpackImplementation"] == "pip._vendor.msgpack.fallback" and proof["setuptoolsPackageAbsent"] is True and proof["vendorFilesByteCompared"] == 299 and proof.get("vulnerableModulesAbsent") == ["msgpack._cmsgpack", "setuptools.wheel"] and @@ -60,14 +60,31 @@ def apply(raw, proof, subject): (item.get("PkgIdentifier") or {}).get("PURL") == purl and all(not pkg.get("FilePath") and not pkg.get("PkgPath") for pkg in packages) and not item.get("PkgPath")) + if key == "CVE-2026-8643": + # PYSEC-2026-196 is fixed in pip 26.1.2. Distro seed metadata + # needs the complete installed core, not just a vendor proof. + purl = "pkg:deb/ubuntu/python3-pip-whl@25.1.1%2Bdfsg-1ubuntu2?arch=all&distro=ubuntu-26.04" + eligible = (actual == ("python3-pip-whl", "25.1.1+dfsg-1ubuntu2") + and section.get("Type") == "ubuntu" and section.get("Class") == "os-pkgs" + and packages and item.get("Severity") == "MEDIUM" + and item.get("FixedVersion") in (None, "", "26.1.2") + and (item.get("PkgIdentifier") or {}).get("PURL") == purl + and proof.get("vendorInventorySha256") == "6b9e911363afa748740d5a514de1ecf34974645d0fb01dac23546e66d4d0f94c" + and type(proof.get("pipCoreFilesByteCompared")) is int + and proof.get("pipCoreFilesByteCompared") == 157 + and proof.get("pipCoreFileSetMatched") is True + and proof.get("pipCoreInventorySha256") == "51be05e205130ecb1655f762f5933177269a9e665d1f4075a8921557998ddce5") if not eligible: retained.append(item) continue + detail = ("The distro seed has been replaced by the exact pip 26.2.2+pasturestack.2 wheel; " + "all 157 live core files and their full set match the patched wheel" + if key == "CVE-2026-8643" else reasons[key]["detail"]) statements.append({ "vulnerability": {"name": key}, "products": [{"@id": subject, "subcomponents": [{"@id": purl}]}], "status": "not_affected", "justification": "vulnerable_code_not_present", - "impact_statement": reasons[key]["detail"] + "; exact pip wheel SHA-256 " + WHEEL_SHA, + "impact_statement": detail + "; exact pip wheel SHA-256 " + WHEEL_SHA, }) section["Vulnerabilities"] = retained vex = {"@context": "https://openvex.dev/ns/v0.2.0", "@id": subject + "/pip-vendor-vex", diff --git a/scripts/pip-security/inputs.json b/scripts/pip-security/inputs.json index fc6b7de9..03bb108e 100644 --- a/scripts/pip-security/inputs.json +++ b/scripts/pip-security/inputs.json @@ -1,12 +1,13 @@ { "schemaVersion": 1, "upstreamVersion": "26.2.2", - "version": "26.2.2+pasturestack.1", - "expectedWheelSha256": "be5f63d537bbe611dc422fabb6740a44b5997888b592888df5091727f023802a", + "version": "26.2.2+pasturestack.2", + "expectedWheelSha256": "2aef7c341eef310645ab56455f5789de2819463b25fa70151954e1d208d2db36", "sourceCommit": "b3b696fe2122f2339d782517559bfade2cb6b879", "sourceDateEpoch": 1792509744, "updatedVendoredLibraries": { - "urllib3": "2.8.0" + "urllib3": "2.8.0", + "msgpack": "1.2.3" }, "artifacts": [ { @@ -183,6 +184,20 @@ "version": "26.2.2", "url": "https://files.pythonhosted.org/packages/3f/06/3e4420302363fbb71be3c7f35ce042f54bfca330e3e66b3a2e3c4cca579f/pip-26.2.2-py3-none-any.whl", "sha256": "fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70" + }, + { + "kind": "source", + "name": "msgpack-source", + "version": "1.2.3", + "url": "https://files.pythonhosted.org/packages/0a/e7/bb605a7bab2d8425a64b3fa762b39dc1bf1c7e3f11ba6fb5413d6db0ff8c/msgpack-1.2.3.tar.gz", + "sha256": "32edb81a2b5eb7cd7c9d941b2bfbbb082fd2cd09e0e725930316af6b708db186" + }, + { + "kind": "tool", + "name": "setuptools", + "version": "84.1.0", + "url": "https://files.pythonhosted.org/packages/18/02/b4bbb90f8f29e334898ff45c6d9b1fffaa6f378017052b3023a06262b5f7/setuptools-84.1.0-py3-none-any.whl", + "sha256": "5231689c6ac8156cd155cfb98c3fd6fb252c3e7e9bd3d78b64d3c55f132624c9" } ] } diff --git a/scripts/pip-security/test-pip-overlay.py b/scripts/pip-security/test-pip-overlay.py index a2c62651..637d5e0b 100644 --- a/scripts/pip-security/test-pip-overlay.py +++ b/scripts/pip-security/test-pip-overlay.py @@ -81,8 +81,9 @@ def main(): "streaming": boundary_tests(not args.expect_vulnerable)} if args.expect_vulnerable: print(json.dumps(result)); return - assert pip.__version__ == "26.2.2+pasturestack.1" + assert pip.__version__ == "26.2.2+pasturestack.2" assert urllib3.__version__ == "2.8.0" + assert msgpack.__version__ == "1.2.3" assert msgpack.Unpacker.__module__ == "pip._vendor.msgpack.fallback" import importlib.util assert importlib.util.find_spec("pip._vendor.msgpack._cmsgpack") is None diff --git a/scripts/pip-security/test-pip-vex.py b/scripts/pip-security/test-pip-vex.py index 256dd56b..1064f5df 100644 --- a/scripts/pip-security/test-pip-vex.py +++ b/scripts/pip-security/test-pip-vex.py @@ -20,7 +20,7 @@ class VexBoundary(unittest.TestCase): def setUp(self): self.proof = {"verifiedWheelSha256": vex.WHEEL_SHA, "verifiedWheelPath": "/usr/share/python-wheels/" + vex.WHEEL_NAME, - "pip": "26.2.2+pasturestack.1", + "pip": "26.2.2+pasturestack.2", "urllib3": "2.8.0", "msgpackImplementation": "pip._vendor.msgpack.fallback", "setuptoolsPackageAbsent": True, "vendorFilesByteCompared": 299, "vulnerableModulesAbsent": ["msgpack._cmsgpack", "setuptools.wheel"], @@ -157,6 +157,71 @@ def test_unrelated_or_versionless_sbom_components_do_not_match(self): primary = {"bomFormat": "CycloneDX", "metadata": {"component": {"name": "msgpack", "version": "1.1.2"}}} self.assertTrue(matching_sbom(json.dumps(primary).encode())) + def test_pip_core_proof_compares_complete_set_and_every_file(self): + spec = importlib.util.spec_from_file_location("core_proof", Path(__file__).with_name("check-pip-vendor-slice.py")) + checker = importlib.util.module_from_spec(spec) + spec.loader.exec_module(checker) + with tempfile.TemporaryDirectory() as directory: + live = Path(directory) / "pip" + live.mkdir() + (live / "__init__.py").write_bytes(b"core fixture\n") + selected = Path(directory) / "selected.whl" + with zipfile.ZipFile(selected, "w") as archive: + archive.writestr("pip/__init__.py", b"core fixture\n") + with zipfile.ZipFile(selected) as archive: + self.assertEqual(checker.require_pip_core_exact(archive, live)["pipCoreFilesByteCompared"], 1) + (live / "__init__.py").write_bytes(b"changed\n") + with self.assertRaises(AssertionError): checker.require_pip_core_exact(archive, live) + (live / "__init__.py").write_bytes(b"core fixture\n") + (live / "extra.py").write_bytes(b"unexpected\n") + with self.assertRaises(AssertionError): checker.require_pip_core_exact(archive, live) + (live / "extra.py").unlink() + (live / "__init__.py").unlink() + with self.assertRaises(AssertionError): checker.require_pip_core_exact(archive, live) + + def test_pip_8643_requires_exact_native_tuple_and_complete_patched_core(self): + purl = "pkg:deb/ubuntu/python3-pip-whl@25.1.1%2Bdfsg-1ubuntu2?arch=all&distro=ubuntu-26.04" + finding = {"VulnerabilityID": "CVE-2026-8643", "PkgName": "python3-pip-whl", + "InstalledVersion": "25.1.1+dfsg-1ubuntu2", "Severity": "MEDIUM", + "FixedVersion": "", "PkgIdentifier": {"PURL": purl}} + raw = {"Results": [{"Type": "ubuntu", "Class": "os-pkgs", + "Packages": [{"Name": "python3-pip-whl", "Version": "25.1.1+dfsg-1ubuntu2"}], + "Vulnerabilities": [finding]}]} + proof = dict(self.proof, vendorInventorySha256="6b9e911363afa748740d5a514de1ecf34974645d0fb01dac23546e66d4d0f94c", + pipCoreFilesByteCompared=157, pipCoreFileSetMatched=True, + pipCoreInventorySha256="51be05e205130ecb1655f762f5933177269a9e665d1f4075a8921557998ddce5") + original = deepcopy(raw) + for fixed in (None, "", "26.1.2"): + raw["Results"][0]["Vulnerabilities"][0]["FixedVersion"] = fixed + result, statements = vex.apply(raw, proof, "urn:test:fixture-image") + self.assertEqual(result["Results"][0]["Vulnerabilities"], []) + self.assertEqual(len(statements["statements"]), 1) + self.assertEqual(original["Results"][0]["Vulnerabilities"][0]["Severity"], "MEDIUM") + for key, value in [("pipCoreFilesByteCompared", 156), ("pipCoreFileSetMatched", False), + ("pipCoreInventorySha256", "0" * 64), ("vendorInventorySha256", "0" * 64), + ("pipCoreFilesByteCompared", None)]: + with self.subTest(proof=key): + result, statements = vex.apply(original, dict(proof, **{key: value}), "urn:test:fixture-image") + self.assertEqual(result, original) + self.assertEqual(statements["statements"], []) + for key, value in [("Severity", "HIGH"), ("FixedVersion", "26.1.3"), + ("VulnerabilityID", "CVE-UNKNOWN"), ("InstalledVersion", "25.1.2"), + ("PkgIdentifier", {"PURL": purl + "&changed=1"})]: + changed = deepcopy(original); changed["Results"][0]["Vulnerabilities"][0][key] = value + result, statements = vex.apply(changed, proof, "urn:test:fixture-image") + self.assertEqual(result, changed) + self.assertEqual(statements["statements"], []) + for key, value in [("Type", "python-pkg"), ("Class", "lang-pkgs"), ("Packages", [])]: + changed = deepcopy(original); changed["Results"][0][key] = value + result, statements = vex.apply(changed, proof, "urn:test:fixture-image") + self.assertEqual(result, changed) + self.assertEqual(statements["statements"], []) + for key in ("pipCoreFilesByteCompared", "pipCoreFileSetMatched", "pipCoreInventorySha256"): + proof.pop(key) + result, statements = vex.apply(original, proof, "urn:test:old-vendor-only-proof") + self.assertEqual(result, original) + self.assertEqual(statements["statements"], []) + def test_source_walk_error_cannot_produce_complete_inventory(self): def unreadable(*args, **kwargs): kwargs["onerror"](PermissionError("unreadable source path")) diff --git a/scripts/pip-security/vendor_source_inventory.py b/scripts/pip-security/vendor_source_inventory.py index 99ec38cb..3830f256 100644 --- a/scripts/pip-security/vendor_source_inventory.py +++ b/scripts/pip-security/vendor_source_inventory.py @@ -8,7 +8,7 @@ import zipfile -WHEEL_NAME = "pip-26.2.2+pasturestack.1-py3-none-any.whl" +WHEEL_NAME = "pip-26.2.2+pasturestack.2-py3-none-any.whl" WHEEL_PATHS = {"/usr/share/python-wheels/" + WHEEL_NAME, "/opt/python-security/" + WHEEL_NAME} SBOM_PATHS = {"/usr/local/lib/python3.14/dist-packages/pip/_vendor/bom.cdx.json", diff --git a/scripts/run-platform-compat b/scripts/run-platform-compat index fff9cff1..e8aa388c 100755 --- a/scripts/run-platform-compat +++ b/scripts/run-platform-compat @@ -17,7 +17,8 @@ if [ ! -s cattle.jar ]; then echo "PLATFORM_COMPAT_JAR_SHA256 is required for a downloaded compatibility server artifact" >&2 exit 1 fi - curl -fsSL "$URL" -o cattle.jar + curl -fsSL --retry 3 --retry-delay 2 --retry-max-time 90 \ + --connect-timeout 10 --max-time 30 "$URL" -o cattle.jar fi if [ -n "${EXPECTED_SHA256}" ]; then From b12c71b8b69bd219d9859595e3435f0a280f0043 Mon Sep 17 00:00:00 2001 From: chen21019 Date: Sun, 8 Nov 2026 17:55:59 +0800 Subject: [PATCH 4/5] fix: join exact native dpkg versions for pip byte evidence --- scripts/pip-security/filter-pip-vendor-findings.py | 10 +++++++++- scripts/pip-security/test-pip-vex.py | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/pip-security/filter-pip-vendor-findings.py b/scripts/pip-security/filter-pip-vendor-findings.py index 71ea2556..7b792f67 100644 --- a/scripts/pip-security/filter-pip-vendor-findings.py +++ b/scripts/pip-security/filter-pip-vendor-findings.py @@ -64,9 +64,17 @@ def apply(raw, proof, subject): # PYSEC-2026-196 is fixed in pip 26.1.2. Distro seed metadata # needs the complete installed core, not just a vendor proof. purl = "pkg:deb/ubuntu/python3-pip-whl@25.1.1%2Bdfsg-1ubuntu2?arch=all&distro=ubuntu-26.04" + package_id = "python3-pip-whl@25.1.1+dfsg-1ubuntu2" + native_packages = [pkg for pkg in section.get("Packages", []) if pkg.get("Name") == "python3-pip-whl"] + native_match = (len(native_packages) == 1 + and native_packages[0].get("ID") == package_id + and native_packages[0].get("Version") == "25.1.1+dfsg" + and native_packages[0].get("Release") == "1ubuntu2" + and native_packages[0].get("AnalyzedBy") == "dpkg" + and (native_packages[0].get("Identifier") or {}).get("PURL") == purl) eligible = (actual == ("python3-pip-whl", "25.1.1+dfsg-1ubuntu2") and section.get("Type") == "ubuntu" and section.get("Class") == "os-pkgs" - and packages and item.get("Severity") == "MEDIUM" + and native_match and item.get("PkgID") == package_id and item.get("Severity") == "MEDIUM" and item.get("FixedVersion") in (None, "", "26.1.2") and (item.get("PkgIdentifier") or {}).get("PURL") == purl and proof.get("vendorInventorySha256") == "6b9e911363afa748740d5a514de1ecf34974645d0fb01dac23546e66d4d0f94c" diff --git a/scripts/pip-security/test-pip-vex.py b/scripts/pip-security/test-pip-vex.py index 1064f5df..a125ab0c 100644 --- a/scripts/pip-security/test-pip-vex.py +++ b/scripts/pip-security/test-pip-vex.py @@ -182,10 +182,13 @@ def test_pip_core_proof_compares_complete_set_and_every_file(self): def test_pip_8643_requires_exact_native_tuple_and_complete_patched_core(self): purl = "pkg:deb/ubuntu/python3-pip-whl@25.1.1%2Bdfsg-1ubuntu2?arch=all&distro=ubuntu-26.04" finding = {"VulnerabilityID": "CVE-2026-8643", "PkgName": "python3-pip-whl", + "PkgID": "python3-pip-whl@25.1.1+dfsg-1ubuntu2", "InstalledVersion": "25.1.1+dfsg-1ubuntu2", "Severity": "MEDIUM", "FixedVersion": "", "PkgIdentifier": {"PURL": purl}} raw = {"Results": [{"Type": "ubuntu", "Class": "os-pkgs", - "Packages": [{"Name": "python3-pip-whl", "Version": "25.1.1+dfsg-1ubuntu2"}], + "Packages": [{"ID": "python3-pip-whl@25.1.1+dfsg-1ubuntu2", "Name": "python3-pip-whl", + "Version": "25.1.1+dfsg", "Release": "1ubuntu2", + "Identifier": {"PURL": purl}, "AnalyzedBy": "dpkg"}], "Vulnerabilities": [finding]}]} proof = dict(self.proof, vendorInventorySha256="6b9e911363afa748740d5a514de1ecf34974645d0fb01dac23546e66d4d0f94c", pipCoreFilesByteCompared=157, pipCoreFileSetMatched=True, @@ -205,7 +208,7 @@ def test_pip_8643_requires_exact_native_tuple_and_complete_patched_core(self): self.assertEqual(result, original) self.assertEqual(statements["statements"], []) for key, value in [("Severity", "HIGH"), ("FixedVersion", "26.1.3"), - ("VulnerabilityID", "CVE-UNKNOWN"), ("InstalledVersion", "25.1.2"), + ("VulnerabilityID", "CVE-UNKNOWN"), ("InstalledVersion", "25.1.2"), ("PkgID", "foreign"), ("PkgIdentifier", {"PURL": purl + "&changed=1"})]: changed = deepcopy(original); changed["Results"][0]["Vulnerabilities"][0][key] = value result, statements = vex.apply(changed, proof, "urn:test:fixture-image") @@ -216,6 +219,13 @@ def test_pip_8643_requires_exact_native_tuple_and_complete_patched_core(self): result, statements = vex.apply(changed, proof, "urn:test:fixture-image") self.assertEqual(result, changed) self.assertEqual(statements["statements"], []) + for key, value in [("Version", "25.1.1+dfsg-1ubuntu2"), ("Release", "1ubuntu3"), + ("ID", "foreign"), ("Identifier", {"PURL": purl + "&changed=1"}), + ("AnalyzedBy", "sbom")]: + changed = deepcopy(original); changed["Results"][0]["Packages"][0][key] = value + result, statements = vex.apply(changed, proof, "urn:test:fixture-image") + self.assertEqual(result, changed) + self.assertEqual(statements["statements"], []) for key in ("pipCoreFilesByteCompared", "pipCoreFileSetMatched", "pipCoreInventorySha256"): proof.pop(key) result, statements = vex.apply(original, proof, "urn:test:old-vendor-only-proof") From bc13be7de75fb064bdcd981846fbcfee9047964a Mon Sep 17 00:00:00 2001 From: chen21019 Date: Sun, 8 Nov 2026 19:13:54 +0800 Subject: [PATCH 5/5] build: fetch the unchanged compatibility JAR through the official asset API --- .github/workflows/security-release-gate.yml | 2 +- scripts/check-pasturestack-source | 3 ++- scripts/run-platform-compat | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/security-release-gate.yml b/.github/workflows/security-release-gate.yml index effb1277..909a017c 100644 --- a/.github/workflows/security-release-gate.yml +++ b/.github/workflows/security-release-gate.yml @@ -22,7 +22,7 @@ jobs: DAPPER_IMAGE: pasturestack/compose-cli-dapper:${{ github.sha }} TRIVY_IMAGE: aquasec/trivy:0.74.0@sha256:62b1e65e8869bc4b4c6aa4fa2b21595256c7c2f6018a9d9ad61caf87187c1969 VERSION_OVERRIDE: 0.14.44 - PLATFORM_COMPAT_JAR_URL: https://github.com/PastureStack/orchestration-engine/releases/download/v0.183.281/orchestration-engine-0.183.281.jar + PLATFORM_COMPAT_JAR_URL: https://api.github.com/repos/PastureStack/orchestration-engine/releases/assets/503322721 PLATFORM_COMPAT_JAR_SHA256: da2a8a51562ed16e296f7e29e99482bb44042ff0834cca679bbe01d951ba1682 steps: diff --git a/scripts/check-pasturestack-source b/scripts/check-pasturestack-source index 43791d3e..f05328b4 100755 --- a/scripts/check-pasturestack-source +++ b/scripts/check-pasturestack-source @@ -74,7 +74,8 @@ require_line Dockerfile.dapper ' openssl-provider-legacy="${UBUNTU_APT_OP require_line .python-version '3.14.9' require_line tests/integration/requirements.txt 'pytest==9.1.1' require_line tests/integration/requirements.txt 'setuptools==84.1.0' -require_line .github/workflows/security-release-gate.yml ' PLATFORM_COMPAT_JAR_URL: https://github.com/PastureStack/orchestration-engine/releases/download/v0.183.281/orchestration-engine-0.183.281.jar' +require_line .github/workflows/security-release-gate.yml ' PLATFORM_COMPAT_JAR_URL: https://api.github.com/repos/PastureStack/orchestration-engine/releases/assets/503322721' +require_line scripts/run-platform-compat ' curl -fsSL -H '\''Accept: application/octet-stream'\'' --retry 3 --retry-delay 2 --retry-max-time 90 \' require_line .github/workflows/security-release-gate.yml ' PLATFORM_COMPAT_JAR_SHA256: da2a8a51562ed16e296f7e29e99482bb44042ff0834cca679bbe01d951ba1682' require_line lookup/file.go $'\t\troot, err := os.OpenRoot(allowedRoot)' require_line lookup/file_test.go 'func TestConfiguredFileLookupRejectsEscapes(t *testing.T) {' diff --git a/scripts/run-platform-compat b/scripts/run-platform-compat index e8aa388c..070ad294 100755 --- a/scripts/run-platform-compat +++ b/scripts/run-platform-compat @@ -17,7 +17,7 @@ if [ ! -s cattle.jar ]; then echo "PLATFORM_COMPAT_JAR_SHA256 is required for a downloaded compatibility server artifact" >&2 exit 1 fi - curl -fsSL --retry 3 --retry-delay 2 --retry-max-time 90 \ + curl -fsSL -H 'Accept: application/octet-stream' --retry 3 --retry-delay 2 --retry-max-time 90 \ --connect-timeout 10 --max-time 30 "$URL" -o cattle.jar fi