Skip to content

Commit 5f8ddb6

Browse files
authored
Switch from GPG to Sigstore for Python source verification (#1924)
The build scripts that download and compile the Python source archives (for upload to S3, where they are then consumed by the buildpack during customer builds) currently use GPG to verify the Python source archive downloads. However, use of PGP signatures for Python artifact verification was deprecated previously in PEP 761, in favour of Sigstore: https://peps.python.org/pep-0761/ https://www.python.org/downloads/metadata/sigstore/ Until now the PGP signatures have still been available for all stable releases, however, as of Python 3.14 (due to be released this week), Sigstore will be the only supported verification mechanism: https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-no-more-pgp As such, we must now switch over to Sigstore. We use the `cosign` CLI for verification since it's a standalone binary available via a Docker image, rather than the Python `sigstore` CLI which requires a Python environment (and so would need pip, venv etc, and more setup to ensure it stays isolated from the Python we're trying to build). See: - https://www.python.org/downloads/metadata/sigstore/ - https://docs.sigstore.dev/cosign/system_config/installation/#container-images - https://docs.sigstore.dev/cosign/verifying/verify/ - https://github.com/sigstore/cosign/blob/main/doc/cosign_verify-blob.md GUS-W-18244071.
1 parent a361dfa commit 5f8ddb6

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ updates:
1313
update-types:
1414
- "minor"
1515
- "patch"
16+
- package-ecosystem: "docker"
17+
directory: "/"
18+
schedule:
19+
interval: "monthly"
20+
labels:
21+
- "dependencies"
22+
- "docker"
23+
- "skip changelog"
1624
- package-ecosystem: "github-actions"
1725
directory: "/"
1826
schedule:

builds/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ARG STACK_VERSION="24"
2+
FROM ghcr.io/sigstore/cosign/cosign:v2.6.1@sha256:68839b7f13dac5a6744a5d8818e984dd39183374e37855c19e14d623d9bc9037 AS cosign
23
FROM heroku/heroku:${STACK_VERSION}-build
34

45
ARG STACK_VERSION
@@ -13,6 +14,7 @@ RUN apt-get update --error-on=any \
1314
libreadline-dev \
1415
libsqlite3-dev \
1516
&& rm -rf /var/lib/apt/lists/*
17+
COPY --from=cosign /ko-app/cosign /usr/local/bin/cosign
1618

1719
WORKDIR /tmp
1820
COPY build_python_runtime.sh python-3.13-ubuntu-22.04-libexpat-workaround.patch .

builds/build_python_runtime.sh

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,19 @@ if [[ " ${SUPPORTED_PYTHON_VERSIONS[*]} " != *" ${PYTHON_MAJOR_VERSION} "* ]]; t
4343
abort "Python ${PYTHON_MAJOR_VERSION} isn't supported on ${STACK}!"
4444
fi
4545

46-
# The release keys can be found on https://www.python.org/downloads/ -> "OpenPGP Public Keys".
46+
# Sigstore identities taken from: https://www.python.org/downloads/metadata/sigstore/
4747
case "${PYTHON_MAJOR_VERSION}" in
48-
3.13)
49-
# https://github.com/Yhg1s.gpg
50-
GPG_KEY_FINGERPRINT='7169605F62C751356D054A26A821E680E5FA6305'
51-
;;
52-
3.12)
53-
# https://github.com/Yhg1s.gpg
54-
GPG_KEY_FINGERPRINT='7169605F62C751356D054A26A821E680E5FA6305'
48+
3.12 | 3.13)
49+
SIGSTORE_IDENTITY='[email protected]'
50+
SIGSTORE_ISSUER='https://accounts.google.com'
5551
;;
5652
3.10 | 3.11)
57-
# https://keybase.io/pablogsal/
58-
GPG_KEY_FINGERPRINT='A035C8C19219BA821ECEA86B64E628F8D684696D'
53+
SIGSTORE_IDENTITY='pablogsal@python.org'
54+
SIGSTORE_ISSUER='https://accounts.google.com'
5955
;;
6056
3.9)
61-
# https://keybase.io/ambv/
62-
GPG_KEY_FINGERPRINT='E3FF2839C048B25C084DEBE9B26995E310250568'
57+
SIGSTORE_IDENTITY='[email protected]'
58+
SIGSTORE_ISSUER='https://github.com/login/oauth'
6359
;;
6460
*)
6561
abort "Unsupported Python version '${PYTHON_MAJOR_VERSION}'!"
@@ -69,17 +65,20 @@ esac
6965
echo "Building Python ${PYTHON_VERSION} for ${STACK} (${ARCH})..."
7066

7167
SOURCE_URL="https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz"
72-
SIGNATURE_URL="${SOURCE_URL}.asc"
68+
SIGSTORE_BUNDLE_URL="${SOURCE_URL}.sigstore"
7369

7470
set -o xtrace
7571

7672
mkdir -p "${SRC_DIR}" "${INSTALL_DIR}" "${UPLOAD_DIR}"
7773

7874
curl --fail --retry 5 --retry-connrefused --connect-timeout 3 --max-time 30 -o python.tgz "${SOURCE_URL}"
79-
curl --fail --retry 5 --retry-connrefused --connect-timeout 3 --max-time 30 -o python.tgz.asc "${SIGNATURE_URL}"
75+
curl --fail --retry 5 --retry-connrefused --connect-timeout 3 --max-time 30 -o python.tgz.sigstore "${SIGSTORE_BUNDLE_URL}"
8076

81-
gpg --batch --verbose --recv-keys "${GPG_KEY_FINGERPRINT}"
82-
gpg --batch --verify python.tgz.asc python.tgz
77+
cosign verify-blob \
78+
--bundle python.tgz.sigstore \
79+
--certificate-identity "${SIGSTORE_IDENTITY}" \
80+
--certificate-oidc-issuer "${SIGSTORE_ISSUER}" \
81+
python.tgz
8382

8483
tar --extract --file python.tgz --strip-components=1 --directory "${SRC_DIR}"
8584
cd "${SRC_DIR}"

0 commit comments

Comments
 (0)