Skip to content

Commit dbf958b

Browse files
committed
fix: add rootless support for Ubuntu container image
Add the same rootless patches as the Alpine image: - Patch openvoxserver-ca symlink_to_old_cadir and FileUtils.chown - Patch foreground script restartcounter (touch+chmod instead of install --owner) - Patch puppetserver USER check for non-root execution - Add OpenShift random UID pattern (chgrp 0, chmod g=u, SGID) - Set HOME explicitly for random UIDs - Run as non-root user (USER 999:0)
1 parent 8af527d commit dbf958b

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

openvoxserver/Containerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,41 @@ COPY conf.d/puppetserver.conf \
115115

116116
COPY puppetdb.conf /var/tmp/puppet/
117117

118+
# explicitly set HOME: random UIDs will cause HOME to be "/" generally
119+
ENV HOME=/opt/puppetlabs/server/data/puppetserver
120+
121+
# Patch openvoxserver-ca to skip cadir symlink and chown (fails rootless)
122+
RUN find / -path '*/openvoxserver-ca-*/lib/puppetserver/ca/action/setup.rb' \
123+
-exec sed -i '/Puppetserver::Ca::Utils::Config\.symlink_to_old_cadir/ s/^/# /' {} + 2>/dev/null \
124+
; find / -path '*/openvoxserver-ca-*/lib/puppetserver/ca/utils/file_system.rb' \
125+
-exec sed -i 's/FileUtils\.chown/# FileUtils.chown/' {} + 2>/dev/null \
126+
; true
127+
128+
# `install --owner/--group` in the foreground script requires CAP_CHOWN which
129+
# is not available in rootless containers. Replace with a simple touch + chmod.
130+
RUN sed -i 's|printf.*install -D --owner.*restartfile.*|touch "$restartfile" \&\& chmod 0644 "$restartfile"|' \
131+
/opt/puppetlabs/server/apps/puppetserver/cli/apps/foreground
132+
133+
# the foreground starting script has this check before running the server:
134+
# [ "$EUID" = "$(id -u ${USER})" ]
135+
# simply calling `id -u` results in the UID of the current user and the check will pass
136+
RUN sed -i 's/^ *USER="puppet"/USER=""/' /etc/default/puppetserver
137+
138+
# mirror user permissions to group, set group to root, and set gid bit on dirs
139+
RUN for d in \
140+
/etc/puppetlabs \
141+
/var/log/puppetlabs \
142+
/var/run/puppetlabs \
143+
/opt/puppetlabs \
144+
; do \
145+
mkdir -p "$d"; \
146+
chgrp -R 0 "$d"; \
147+
chmod -R g=u "$d"; \
148+
find "$d" -type d -exec chmod g+s {} +; \
149+
done
150+
151+
USER ${OPENVOX_USER_UID}:0
152+
118153
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
119154
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]
120155

0 commit comments

Comments
 (0)