Skip to content

Commit 4c983b5

Browse files
authored
Limit pip install dependencies to match requested features (#163)
* Toggle most pip installed dependencies based on the corresponding `ENABLE_X` values to limit image footprint and adhere to the secure by default principle of not enabling optional components unless requested. * Expose the arg values used to decide on optional pip installation. * Add missing `ENABLE_DAVS` arg access in the last stage now using it.
1 parent 14fd512 commit 4c983b5

1 file changed

Lines changed: 24 additions & 31 deletions

File tree

Dockerfile.rocky9

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ ARG UPGRADE_OIDC_AUTH_MOD_SRC=""
148148
ARG UPGRADE_PARAMIKO=False
149149
ARG PUBKEY_FROM_DNS=False
150150
# NOTE: python2 support is gone on rocky9+
151+
# TODO: eliminate WITH_PY3 arg completely
151152
ARG WITH_PY3=True
152153
ARG PREFER_PYTHON3=True
153154
ARG SIGNUP_METHODS=migoid
@@ -453,7 +454,7 @@ RUN if [ "${ENABLE_GDP}" = "True" ]; then \
453454
&& dnf install -y \
454455
# NOTE: python2 support is gone on rocky9+
455456
xorg-x11-server-Xvfb \
456-
# NOTE: wkhtmltopdf not yet build for Rocky9
457+
# NOTE: wkhtmltopdf not yet built for Rocky9
457458
https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.x86_64.rpm \
458459
# NOTE: compat-openssl11.x86_64 is needed by Rocky8 version of wkhtmltopdf
459460
compat-openssl11.x86_64 \
@@ -708,11 +709,6 @@ RUN if [ ! -e "${CERT_DIR}/.persistent" ]; then \
708709
[ -L "$domain" ] || ln -s MiG/${WILDCARD_DOMAIN} $domain; \
709710
done ; fi
710711

711-
# Upgrade pip3 is only required for cryptography from pip - irrelevant here
712-
#RUN if [ "${WITH_PY3}" = "True" ]; then \
713-
# python3 -m pip install --no-cache-dir -U 'pip'; \
714-
# fi;
715-
716712
# NOTE: make certs as mig user
717713
WORKDIR $MIG_ROOT
718714
USER $USER
@@ -741,11 +737,18 @@ USER $USER
741737
#------------------------- next stage -----------------------------#
742738
FROM --platform=linux/$ARCH setup_security AS mig_dependencies
743739
ARG DOMAIN
744-
ARG WITH_PY3
745740
ARG MODERN_WSGIDAV
746741
ARG UPGRADE_PARAMIKO
742+
ARG ENABLE_SFTP
743+
ARG ENABLE_SFTP_SUBSYS
747744
ARG ENABLE_CLOUD
745+
ARG ENABLE_CRONTAB
746+
ARG ENABLE_EVENTS
747+
ARG ENABLE_DAVS
748+
ARG ENABLE_FTPS
749+
ARG ENABLE_CRACKLIB
748750
ARG ENABLE_PYTEST
751+
ARG ENABLE_TWOFACTOR
749752
ARG ENABLE_WORKFLOWS
750753
ARG OPENSTACKSDK_VERSION_OVERRIDE
751754
ARG TRAC_ADMIN_PATH
@@ -756,13 +759,12 @@ USER root
756759
# Prepare py dependencies not in dnf or just outdated there
757760

758761
# NOTE: use jsonrpclib and pysendfile from pip for py3 here
759-
RUN if [ "${WITH_PY3}" = "True" ]; then \
760-
pip3 install --no-cache-dir 'jsonrpclib<0.2' pysendfile; \
761-
fi;
762+
# and iso3166 for smart country selection
763+
RUN pip3 install --no-cache-dir 'jsonrpclib<0.2' pysendfile iso3166
762764

763765
# NOTE: recent paramiko is required for modern host key algo
764-
RUN if [ "${UPGRADE_PARAMIKO}" = "True" ]; then \
765-
if [ "${WITH_PY3}" = "True" ]; then \
766+
RUN if [ "${ENABLE_SFTP}" = "True" -o "${ENABLE_SFTP_SUBSYS}" = "True" ]; then \
767+
if [ "${UPGRADE_PARAMIKO}" = "True" ]; then \
766768
# NOTE: a newer setuptools MAY be needed and setuptools_rust MUST be
767769
# installed separately here for whatever reason.
768770
# IMPORTANT: sftp_subsys.py is explicitly called with 'python -s' to
@@ -793,9 +795,6 @@ RUN if [ "${UPGRADE_PARAMIKO}" = "True" ]; then \
793795
# NOTE: openstackclient is available in dnf here, but sdk may be requested
794796
# e.g. to work around version 1.0.0 breaking floating IP assignment
795797
RUN if [ "${ENABLE_CLOUD}" = "True" ]; then \
796-
#if [ "${WITH_PY3}" = "True" ]; then \
797-
# pip3 install --no-cache-dir python-openstackclient; \
798-
#fi; \
799798
if [ -n "${OPENSTACKSDK_VERSION_OVERRIDE}" ]; then \
800799
pip3 install --no-cache-dir "openstacksdk==${OPENSTACKSDK_VERSION_OVERRIDE}" ; \
801800
fi; \
@@ -804,36 +803,35 @@ RUN if [ "${ENABLE_CLOUD}" = "True" ]; then \
804803
# OpenID support in python (python-openid2 for py3) - use alternative from dnf
805804
#RUN pip3 install --no-cache-dir python-openid2;
806805

807-
# Modules required by grid_events.py
808-
RUN if [ "${WITH_PY3}" = "True" ]; then \
806+
# Modules required by grid_events.py and grid_cron.py
807+
# TODO: eliminate scandir now that it is built into os.scandir
808+
RUN if [ "${ENABLE_CRONTAB}" = "True" -o "${ENABLE_EVENTS}" = "True" ]; then \
809809
pip3 install --no-cache-dir watchdog scandir; \
810810
fi;
811811

812812
# Modules required by grid_webdavs
813-
RUN if [ "${WITH_PY3}" = "True" ]; then \
813+
RUN if [ "${ENABLE_DAVS}" = "True" ]; then \
814814
# IMPORTANT: use at least 4.1 here to avoid a potential security issue
815815
# https://github.com/mar10/wsgidav/security/advisories/GHSA-xx6g-jj35-pxjv
816816
# IMPORTANT: use cheroot before 10.0.1 as it currently crashes webdavs
817817
# One can trigger the crash with a simple testssl.sh run
818818
# TODO: investigate if the problem is in cheroot, wsgidav or migrid.
819+
# Prefer sslkeylog as session tracking helper in webdavs daemon.
819820
pip3 install --no-cache-dir 'cheroot<10.0.1' 'wsgidav>=4.1.0'; \
820-
fi;
821-
# Prefer sslkeylog as session tracking helper in webdavs daemon.
822-
RUN if [ "${WITH_PY3}" = "True" ]; then \
823821
pip3 install --no-cache-dir sslkeylog ; \
824822
fi;
825823

826824
# Modules required by grid_ftps
827825
# NOTE: relies on pyOpenSSL and Cryptography from yum/dnf for now
828-
RUN if [ "${WITH_PY3}" = "True" ]; then \
826+
RUN if [ "${ENABLE_FTPS}" = "True" ]; then \
829827
pip3 install --no-cache-dir pyftpdlib; \
830828
fi;
831829

832830
# Modules required by grid_X IO daemons (not available in yum/dnf for python3)
833831
# IMPORTANT: install in main python site-packages to work with 'python -s'
834832
# Otherwise sftpsubsys will fail to import it because the /usr/local
835833
# dir used as prefix by default in pip is outside sys.path
836-
RUN if [ "${WITH_PY3}" = "True" ]; then \
834+
RUN if [ "${ENABLE_CRACKLIB}" = "True" ]; then \
837835
pip3 install --no-cache-dir --prefix=$(python3-config --prefix) cracklib; \
838836
fi;
839837

@@ -847,15 +845,10 @@ RUN if [ "${ENABLE_PYTEST}" = "True" ]; then \
847845
fi;
848846

849847
# Modules required by 2FA
850-
RUN if [ "${WITH_PY3}" = "True" ]; then \
848+
RUN if [ "${ENABLE_TWOFACTOR}" = "True" ]; then \
851849
pip3 install --no-cache-dir pyotp; \
852850
fi;
853851

854-
# Modules required for smart country selection
855-
RUN if [ "${WITH_PY3}" = "True" ]; then \
856-
pip3 install --no-cache-dir iso3166; \
857-
fi;
858-
859852
# Modules required for email validation (already available in yum/dnf for python3)
860853
# IMPORTANT: install in main python site-packages to work with 'python -s'
861854
# Otherwise sftpsubsys will fail to import it because the /usr/local
@@ -1353,7 +1346,7 @@ ARG EMULATE_FLAVOR
13531346
ARG EMULATE_FQDN
13541347
ARG ENABLE_SELF_SIGNED_CERTS
13551348
ARG ENABLE_OPENID
1356-
ARG WITH_PY3
1349+
ARG ENABLE_DAVS
13571350
ARG PREFER_PYTHON3
13581351
ARG ENABLE_LOGROTATE
13591352
ARG LOGROTATE_MIGRID
@@ -1381,7 +1374,7 @@ RUN cd $MIG_ROOT/mig/src/libnss-mig \
13811374
# NOTE: both require openssl-devel to build and sslkeylog is only supported
13821375
# on python 2.7.9+ and 3. The sslsession module generally builds but fails at
13831376
# runtime when used with OpenSSL-1.1+, however.
1384-
RUN if [ "${WITH_PY3}" = "True" ]; then \
1377+
RUN if [ "${ENABLE_DAVS}" = "True" ]; then \
13851378
cd $MIG_ROOT/mig/src/sslsession \
13861379
&& pip3 install --no-cache-dir . ; \
13871380
fi;

0 commit comments

Comments
 (0)