Skip to content

Commit 5fec57b

Browse files
authored
Use sigstore for Python artifact verification (#303)
* Use sigstore for Python artifact verification * Fix dockerfile warning * Install cosign 2.4.1 or later
1 parent 9c06473 commit 5fec57b

File tree

6 files changed

+45
-36
lines changed

6 files changed

+45
-36
lines changed

python/3.11/Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ FROM $BUILD_FROM
44
ARG \
55
PYTHON_VERSION \
66
PIP_VERSION \
7-
GPG_KEY \
7+
CERT_IDENTITY \
8+
CERT_OIDC_ISSUER \
89
QEMU_CPU
910

1011
# ensure local python is preferred over distribution python
11-
ENV PATH /usr/local/bin:$PATH
12+
ENV PATH=/usr/local/bin:$PATH
1213

1314
# Set shell
1415
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
@@ -17,19 +18,20 @@ COPY *.patch /usr/src/
1718
RUN set -ex \
1819
&& export PYTHON_VERSION=${PYTHON_VERSION} \
1920
&& apk add --no-cache --virtual .fetch-deps \
20-
gnupg \
2121
openssl \
2222
tar \
2323
xz \
24+
&& apk add --no-cache --virtual .cosign cosign \
25+
--repository="https://dl-cdn.alpinelinux.org/alpine/v3.21/community" \
2426
\
2527
&& curl -L -o python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
26-
&& curl -L -o python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
27-
&& export GNUPGHOME="$(mktemp -d)" \
28-
&& echo "disable-ipv6" >> "$GNUPGHOME/dirmngr.conf" \
29-
&& gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "${GPG_KEY}" \
30-
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
31-
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
32-
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
28+
&& curl -L -o python.tar.xz.sigstore "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.sigstore" \
29+
&& cosign verify-blob \
30+
--new-bundle-format \
31+
--certificate-identity "${CERT_IDENTITY}" \
32+
--certificate-oidc-issuer "${CERT_OIDC_ISSUER}" \
33+
--bundle python.tar.xz.sigstore \
34+
python.tar.xz \
3335
&& mkdir -p /usr/src/python \
3436
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
3537
&& rm python.tar.xz \
@@ -63,7 +65,7 @@ RUN set -ex \
6365
zlib-dev \
6466
bluez-dev \
6567
# add build deps before removing fetch deps in case there's overlap
66-
&& apk del .fetch-deps \
68+
&& apk del .fetch-deps .cosign \
6769
\
6870
&& for i in /usr/src/*.patch; do \
6971
patch -d /usr/src/python -p 1 < "${i}"; done \

python/3.11/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ cosign:
1111
args:
1212
PYTHON_VERSION: 3.11.13
1313
PIP_VERSION: 25.1.1
14-
GPG_KEY: A035C8C19219BA821ECEA86B64E628F8D684696D
14+
CERT_IDENTITY: [email protected]
15+
CERT_OIDC_ISSUER: https://accounts.google.com
1516
labels:
1617
io.hass.base.name: python
1718
org.opencontainers.image.source: https://github.com/home-assistant/docker-base

python/3.12/Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ FROM $BUILD_FROM
44
ARG \
55
PYTHON_VERSION \
66
PIP_VERSION \
7-
GPG_KEY \
7+
CERT_IDENTITY \
8+
CERT_OIDC_ISSUER \
89
QEMU_CPU
910

1011
# ensure local python is preferred over distribution python
11-
ENV PATH /usr/local/bin:$PATH
12+
ENV PATH=/usr/local/bin:$PATH
1213

1314
# Set shell
1415
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
@@ -17,19 +18,20 @@ COPY *.patch /usr/src/
1718
RUN set -ex \
1819
&& export PYTHON_VERSION=${PYTHON_VERSION} \
1920
&& apk add --no-cache --virtual .fetch-deps \
20-
gnupg \
2121
openssl \
2222
tar \
2323
xz \
24+
&& apk add --no-cache --virtual .cosign cosign \
25+
--repository="https://dl-cdn.alpinelinux.org/alpine/v3.21/community" \
2426
\
2527
&& curl -L -o python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
26-
&& curl -L -o python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
27-
&& export GNUPGHOME="$(mktemp -d)" \
28-
&& echo "disable-ipv6" >> "$GNUPGHOME/dirmngr.conf" \
29-
&& gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "${GPG_KEY}" \
30-
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
31-
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
32-
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
28+
&& curl -L -o python.tar.xz.sigstore "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.sigstore" \
29+
&& cosign verify-blob \
30+
--new-bundle-format \
31+
--certificate-identity "${CERT_IDENTITY}" \
32+
--certificate-oidc-issuer "${CERT_OIDC_ISSUER}" \
33+
--bundle python.tar.xz.sigstore \
34+
python.tar.xz \
3335
&& mkdir -p /usr/src/python \
3436
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
3537
&& rm python.tar.xz \
@@ -63,7 +65,7 @@ RUN set -ex \
6365
zlib-dev \
6466
bluez-dev \
6567
# add build deps before removing fetch deps in case there's overlap
66-
&& apk del .fetch-deps \
68+
&& apk del .fetch-deps .cosign \
6769
\
6870
&& for i in /usr/src/*.patch; do \
6971
patch -d /usr/src/python -p 1 < "${i}"; done \

python/3.12/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ cosign:
1111
args:
1212
PYTHON_VERSION: 3.12.11
1313
PIP_VERSION: 25.1.1
14-
GPG_KEY: 7169605F62C751356D054A26A821E680E5FA6305
14+
CERT_IDENTITY: [email protected]
15+
CERT_OIDC_ISSUER: https://accounts.google.com
1516
labels:
1617
io.hass.base.name: python
1718
org.opencontainers.image.source: https://github.com/home-assistant/docker-base

python/3.13/Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ FROM $BUILD_FROM
44
ARG \
55
PYTHON_VERSION \
66
PIP_VERSION \
7-
GPG_KEY \
7+
CERT_IDENTITY \
8+
CERT_OIDC_ISSUER \
89
QEMU_CPU
910

1011
# ensure local python is preferred over distribution python
11-
ENV PATH /usr/local/bin:$PATH
12+
ENV PATH=/usr/local/bin:$PATH
1213

1314
# Set shell
1415
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
@@ -17,19 +18,20 @@ COPY *.patch /usr/src/
1718
RUN set -ex \
1819
&& export PYTHON_VERSION=${PYTHON_VERSION} \
1920
&& apk add --no-cache --virtual .fetch-deps \
20-
gnupg \
2121
openssl \
2222
tar \
2323
xz \
24+
&& apk add --no-cache --virtual .cosign cosign \
25+
--repository="https://dl-cdn.alpinelinux.org/alpine/v3.21/community" \
2426
\
2527
&& curl -L -o python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
26-
&& curl -L -o python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
27-
&& export GNUPGHOME="$(mktemp -d)" \
28-
&& echo "disable-ipv6" >> "$GNUPGHOME/dirmngr.conf" \
29-
&& gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "${GPG_KEY}" \
30-
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
31-
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
32-
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
28+
&& curl -L -o python.tar.xz.sigstore "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.sigstore" \
29+
&& cosign verify-blob \
30+
--new-bundle-format \
31+
--certificate-identity "${CERT_IDENTITY}" \
32+
--certificate-oidc-issuer "${CERT_OIDC_ISSUER}" \
33+
--bundle python.tar.xz.sigstore \
34+
python.tar.xz \
3335
&& mkdir -p /usr/src/python \
3436
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
3537
&& rm python.tar.xz \
@@ -63,7 +65,7 @@ RUN set -ex \
6365
zlib-dev \
6466
bluez-dev \
6567
# add build deps before removing fetch deps in case there's overlap
66-
&& apk del .fetch-deps \
68+
&& apk del .fetch-deps .cosign \
6769
\
6870
&& for i in /usr/src/*.patch; do \
6971
patch -d /usr/src/python -p 1 < "${i}"; done \

python/3.13/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ cosign:
1111
args:
1212
PYTHON_VERSION: 3.13.4
1313
PIP_VERSION: 25.1.1
14-
GPG_KEY: 7169605F62C751356D054A26A821E680E5FA6305
14+
CERT_IDENTITY: [email protected]
15+
CERT_OIDC_ISSUER: https://accounts.google.com
1516
labels:
1617
io.hass.base.name: python
1718
org.opencontainers.image.source: https://github.com/home-assistant/docker-base

0 commit comments

Comments
 (0)