Skip to content

Commit aac3c6e

Browse files
authored
Update ensurepip to avoid vulnerabilities in wheels (#35856)
* Update Dockerfile * Use python version * Readd arg which gets stripped after FROM * Use semicolons
1 parent 0cbfee3 commit aac3c6e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sdks/python/container/Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ENV CLOUDSDK_CORE_DISABLE_PROMPTS yes
3030
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
3131

3232
# Use one RUN command to reduce the number of layers.
33+
ARG py_version
3334
RUN \
3435
# Install native bindings required for dependencies.
3536
apt-get update && \
@@ -80,7 +81,15 @@ RUN \
8081
pip freeze --all && \
8182

8283
# Remove pip cache.
83-
rm -rf /root/.cache/pip
84+
rm -rf /root/.cache/pip && \
85+
86+
# Update ensurepip to use most recent versions of setuptools and pip. This avoids some vulnerabilities which won't be fixed on older versions of python.
87+
pip install upgrade_ensurepip; \
88+
python3 -m upgrade_ensurepip; \
89+
find /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-*-py3-none-any.whl | tail -n 1)) -delete; \
90+
find /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-*-py3-none-any.whl | tail -n 1)) -delete; \
91+
pip uninstall upgrade_ensurepip -y; \
92+
python3 -m ensurepip;
8493

8594
ENTRYPOINT ["/opt/apache/beam/boot"]
8695

0 commit comments

Comments
 (0)