Skip to content

Commit d5c28aa

Browse files
committed
Improve docker security
1 parent 27096a6 commit d5c28aa

File tree

11 files changed

+416
-333
lines changed

11 files changed

+416
-333
lines changed

Dockerfile

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ FROM debian:bullseye
22

33
LABEL maintainer="[email protected]"
44

5+
# Default (run-time) environment variables
6+
# Used during initial setup
7+
ENV USERNAME=user
8+
ENV USER_ID=1000
9+
ENV ALLOW_APT=yes
10+
ENV ENTER_PASS=no
11+
ENV ALLOW_SUDO=yes
12+
13+
# Build arguments, _only_ used during Docker build
514
ARG DEBIAN_FRONTEND=noninteractive
615
ARG APT_PROXY
716

817
WORKDIR /app
918

1019
# Enable APT proxy (if APT_PROXY is set)
1120
COPY ./configs/apt.conf ./
12-
COPY ./apt_proxy.sh ./
21+
COPY ./scripts/apt_proxy.sh ./
1322
RUN ./apt_proxy.sh
1423

1524
## First install basic required packages
@@ -28,20 +37,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2837
## Add additional repositories/components (software-properties-common is required to be installed)
2938
# Add contrib and non-free distro components (deb822-style format)
3039
RUN apt-add-repository -y contrib && apt-add-repository -y non-free
31-
# Add Debian backports repo for XFCE thunar-font-manager
40+
# Add Debian backports repo for XFCE thunar-font-manager
3241
RUN add-apt-repository -y "deb http://deb.debian.org/debian bullseye-backports main contrib non-free"
3342

3443
# Retrieve third party GPG keys from keyserver
3544
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys 302F0738F465C1535761F965A6616109451BBBF2 972FD88FA0BAFB578D0476DFE1F958385BFE2B6E
3645

3746
# Add Linux Mint GPG keyring file (for the Mint-Y-Dark theme)
38-
RUN gpg --export 302F0738F465C1535761F965A6616109451BBBF2 | tee /etc/apt/trusted.gpg.d/linuxmint-archive-keyring.gpg > /dev/null
47+
RUN gpg --export 302F0738F465C1535761F965A6616109451BBBF2 | tee /etc/apt/trusted.gpg.d/linuxmint-archive-keyring.gpg >/dev/null
3948

4049
# Add Linux Mint Debbie repo source file
4150
COPY ./configs/linuxmint-debbie.list /etc/apt/sources.list.d/linuxmint-debbie.list
4251

4352
# Add X2Go GPG keyring file
44-
RUN gpg --export 972FD88FA0BAFB578D0476DFE1F958385BFE2B6E | tee /etc/apt/trusted.gpg.d/x2go-archive-keyring.gpg > /dev/null
53+
RUN gpg --export 972FD88FA0BAFB578D0476DFE1F958385BFE2B6E | tee /etc/apt/trusted.gpg.d/x2go-archive-keyring.gpg >/dev/null
4554

4655
# Add X2Go repo source file
4756
COPY ./configs/x2go.list /etc/apt/sources.list.d/x2go.list
@@ -85,10 +94,10 @@ RUN apt-get install -y --no-install-recommends fonts-ubuntu breeze-gtk-theme min
8594
# Add LibreOffice
8695
RUN apt install -y libreoffice-base libreoffice-base-core libreoffice-common libreoffice-core libreoffice-base-drivers \
8796
libreoffice-nlpsolver libreoffice-script-provider-bsh libreoffice-script-provider-js libreoffice-script-provider-python libreoffice-style-colibre \
88-
libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw libreoffice-math
97+
libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw libreoffice-math
8998

9099
## Install XFCE4
91-
# Install XFCE4, including XFCE panels, terminal, screenshooter, task manager, notify daemon, dbus, locker and plugins.
100+
# Install XFCE4, including XFCE panels, terminal, screenshooter, task manager, notify daemon, dbus, locker and plugins.
92101
# ! But we do NOT install xfce4-goodies; since this will install xfburn (not needed) and xfce4-statusnotifier-plugin (deprecated) !
93102
RUN apt-get upgrade -y && apt-get install -y --no-install-recommends \
94103
xfwm4 xfce4-session default-dbus-session-bus xfdesktop4 light-locker \
@@ -110,12 +119,11 @@ RUN apt-get install -y --no-install-recommends \
110119

111120
# Update locales, generate new SSH host keys and clean-up (keep manpages)
112121
RUN update-locale
113-
RUN rm -rf /etc/ssh/ssh_host_* \
114-
&& ssh-keygen -A
122+
RUN rm -rf /etc/ssh/ssh_host_* && ssh-keygen -A
115123
RUN apt-get clean -y && rm -rf /usr/share/doc/* /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apk/*
116124

117125
# Update timezone to The Netherlands
118-
RUN echo 'Europe/Amsterdam' > /etc/timezone
126+
RUN echo 'Europe/Amsterdam' >/etc/timezone
119127
RUN unlink /etc/localtime && ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
120128

121129
# Start default XFCE4 panels (don't ask for it)
@@ -128,12 +136,25 @@ COPY ./configs/xfce4-settings.desktop /etc/xdg/autostart/
128136
RUN sed -i "s/Hidden=.*/Hidden=false/" /etc/xdg/autostart/xfce4-clipman-plugin-autostart.desktop
129137
# Remove unnecessary existing start-up apps
130138
RUN rm -rf /etc/xdg/autostart/light-locker.desktop /etc/xdg/autostart/xscreensaver.desktop
131-
COPY ./setup.sh ./
139+
140+
# Disable root shell
141+
RUN usermod -s /usr/sbin/nologin root
142+
143+
# Create worker user (instead of root user)
144+
RUN useradd -G sudo -ms /bin/bash -u 1001 worker
145+
RUN echo "Defaults!/app/setup.sh setenv" >>/etc/sudoers
146+
# Limit the execute of the following commands of the worker user
147+
RUN echo "worker ALL=(root) NOPASSWD:/usr/sbin/service ssh start, /usr/sbin/service dbus start, /usr/sbin/service rsyslog start, /app/setup.sh" >>/etc/sudoers
148+
# Copy worker scripts
149+
COPY ./scripts/setup.sh ./
132150
COPY ./configs/terminalrc ./
133151
COPY ./configs/whiskermenu-1.rc ./
134-
COPY ./xfce_settings.sh ./
135-
COPY ./run.sh ./
152+
COPY ./scripts/xfce_settings.sh ./
153+
COPY ./scripts/run.sh ./
154+
155+
# Run as worker
156+
USER worker
136157

137158
EXPOSE 22
138159

139-
CMD ./run.sh
160+
CMD ["/bin/bash", "./run.sh"]

0 commit comments

Comments
 (0)