Skip to content

Commit 718f310

Browse files
committed
Dropped privileges on CLI
1 parent 8aaae27 commit 718f310

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

php/7.4/cli/Dockerfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ FROM serversideup/docker-baseimage-s6-overlay-ubuntu:20.04
77
LABEL maintainer="Jay Rogers (@jaydrogers)"
88

99
# Make sure we keep apt silent during installs
10-
ENV DEBIAN_FRONTEND=noninteractive
10+
ENV DEBIAN_FRONTEND=noninteractive \
11+
WEBUSER_HOME="/var/www/html" \
12+
PUID=9999 \
13+
PGID=9999
1114

1215
# Install Ondrej repos for Ubuntu focal, PHP7.4, composer and selected extensions
1316
RUN apt-get update \
17+
&& echo "Add the default, non-privileged user..." \
18+
&& groupadd -r webgroup -g $PGID \
19+
&& useradd --no-log-init -r -d $WEBUSER_HOME -u $PUID -g $PGID webuser \
20+
&& echo "Install the basic software dependencies..." \
1421
&& apt-get install -y --no-install-recommends gnupg \
1522
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ondrej-php.list \
1623
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C \
@@ -37,5 +44,11 @@ RUN apt-get update \
3744
# Pull the official composer 2 image, and copy the composer executable from there
3845
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
3946

47+
# Set the default work directory to our web user
48+
WORKDIR /var/www/html
49+
50+
#Configure S6 to drop priveleges
51+
ENTRYPOINT ["/init", "/bin/execlineb", "-s0", "-c", "export HOME $WEBUSER_HOME s6-setuidgid webuser $@"]
52+
4053
# Run PHP
4154
CMD ["php", "-a"]

0 commit comments

Comments
 (0)