-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This pull request adds the some new environment variables for Malcolm to address #137 * `PUID` and `PGID` * Docker runs all of its containers as the privileged `root` user by default. For better security, Malcolm immediately drops to non-privileged user accounts for executing internal processes wherever possible. The `PUID` (**p**rocess **u**ser **ID**) and `PGID` (**p**rocess **g**roup **ID**) environment variables allow Malcolm to map internal non-privileged user accounts to a corresponding [user account](https://en.wikipedia.org/wiki/User_identifier) on the host. Additionally, this pull request additionally moves all remaining process that can be run non-privileged to run as non-privileged. Each docker container now has the following in its Dockerfile (this example is from the zeek container, they're all similar but may have different specific values): ``` ARG DEFAULT_UID=1000 ARG DEFAULT_GID=1000 ENV DEFAULT_UID $DEFAULT_UID ENV DEFAULT_GID $DEFAULT_GID ENV PUSER "zeek" ENV PGROUP "zeek" ENV PUSER_PRIV_DROP true ``` The entrypoint of each docker comtainer is now [docker-uid-gid-setup.sh](https://github.com/idaholab/Malcolm/blob/master/shared/bin/docker-uid-gid-setup.sh), which does the following: 1. changes the UID and GID of the default (1000:1000) user to match the PUID:PGID provided 2. finds any files *inside* the docker image owned by those IDs and chown them 3. if required, execs the container command by dropping privileges to the unprivileged user Additionally, control.py (used for start, restart, etc.) will now error out it run as root rather than just running with a bunch of errors. Malcolm should not be run as a root user.
- Loading branch information
Showing
56 changed files
with
904 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM docker.elastic.co/elasticsearch/elasticsearch-oss:7.6.2 | ||
|
||
# Copyright (c) 2020 Battelle Energy Alliance, LLC. All rights reserved. | ||
LABEL maintainer="[email protected]" | ||
LABEL org.opencontainers.image.authors='[email protected]' | ||
LABEL org.opencontainers.image.url='https://github.com/idaholab/Malcolm' | ||
LABEL org.opencontainers.image.documentation='https://github.com/idaholab/Malcolm/blob/master/README.md' | ||
LABEL org.opencontainers.image.source='https://github.com/idaholab/Malcolm' | ||
LABEL org.opencontainers.image.vendor='Idaho National Laboratory' | ||
LABEL org.opencontainers.image.title='malcolmnetsec/elasticsearch-oss' | ||
LABEL org.opencontainers.image.description='Malcolm container providing Elasticsearch (the Apache-licensed variant)' | ||
|
||
ARG DEFAULT_UID=1000 | ||
ARG DEFAULT_GID=1000 | ||
ENV DEFAULT_UID $DEFAULT_UID | ||
ENV DEFAULT_GID $DEFAULT_GID | ||
ENV PUSER "elasticsearch" | ||
ENV PGROUP "elasticsearch" | ||
ENV PUSER_PRIV_DROP true | ||
|
||
ENV TERM xterm | ||
|
||
ADD shared/bin/docker-uid-gid-setup.sh /usr/local/bin/ | ||
|
||
ENTRYPOINT ["/usr/local/bin/docker-uid-gid-setup.sh", "/usr/local/bin/docker-entrypoint.sh"] | ||
|
||
|
||
# to be populated at build-time: | ||
ARG BUILD_DATE | ||
ARG MALCOLM_VERSION | ||
ARG VCS_REVISION | ||
|
||
LABEL org.opencontainers.image.created=$BUILD_DATE | ||
LABEL org.opencontainers.image.version=$MALCOLM_VERSION | ||
LABEL org.opencontainers.image.revision=$VCS_REVISION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,8 @@ | ||
FROM debian:buster-slim AS build | ||
|
||
# Copyright (c) 2020 Battelle Energy Alliance, LLC. All rights reserved. | ||
LABEL maintainer="[email protected]" | ||
LABEL org.opencontainers.image.authors='[email protected]' | ||
LABEL org.opencontainers.image.url='https://github.com/idaholab/Malcolm' | ||
LABEL org.opencontainers.image.documentation='https://github.com/idaholab/Malcolm/blob/master/README.md' | ||
LABEL org.opencontainers.image.source='https://github.com/idaholab/Malcolm' | ||
LABEL org.opencontainers.image.vendor='Idaho National Laboratory' | ||
LABEL org.opencontainers.image.title='malcolmnetsec/file-upload' | ||
LABEL org.opencontainers.image.description='Malcolm container providing an interface for uploading PCAP files and Zeek logs for processing' | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
ARG SITE_NAME="Capture File and Log Archive Upload" | ||
|
||
|
@@ -32,11 +25,31 @@ RUN apt-get update && \ | |
|
||
FROM debian:buster-slim AS runtime | ||
|
||
COPY --from=build /jQuery-File-Upload/ /var/www/upload/ | ||
LABEL maintainer="[email protected]" | ||
LABEL org.opencontainers.image.authors='[email protected]' | ||
LABEL org.opencontainers.image.url='https://github.com/idaholab/Malcolm' | ||
LABEL org.opencontainers.image.documentation='https://github.com/idaholab/Malcolm/blob/master/README.md' | ||
LABEL org.opencontainers.image.source='https://github.com/idaholab/Malcolm' | ||
LABEL org.opencontainers.image.vendor='Idaho National Laboratory' | ||
LABEL org.opencontainers.image.title='malcolmnetsec/file-upload' | ||
LABEL org.opencontainers.image.description='Malcolm container providing an interface for uploading PCAP files and Zeek logs for processing' | ||
|
||
ARG DEFAULT_UID=33 | ||
ARG DEFAULT_GID=33 | ||
ENV DEFAULT_UID $DEFAULT_UID | ||
ENV DEFAULT_GID $DEFAULT_GID | ||
ENV PUSER "www-data" | ||
ENV PGROUP "www-data" | ||
# not dropping privileges globally in this container as required to run SFTP server. this can | ||
# be handled by supervisord instead on an as-needed basis, and/or php-fpm/nginx itself | ||
# will drop privileges to www-data as well. | ||
ENV PUSER_PRIV_DROP false | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
ENV TERM xterm | ||
|
||
COPY --from=build /jQuery-File-Upload/ /var/www/upload/ | ||
|
||
RUN apt-get update && \ | ||
apt-get -y -q --allow-downgrades --allow-remove-essential --allow-change-held-packages install --no-install-recommends \ | ||
wget \ | ||
|
@@ -52,6 +65,7 @@ RUN apt-get update && \ | |
apt-get clean -y -q && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ADD shared/bin/docker-uid-gid-setup.sh /usr/local/bin/ | ||
ADD docs/images/logo/Malcolm_banner.png /var/www/upload/Malcolm_banner.png | ||
ADD file-upload/docker-entrypoint.sh /docker-entrypoint.sh | ||
ADD file-upload/jquery-file-upload/bootstrap.min.css /var/www/upload/bower_components/bootstrap/dist/css/bootstrap.min.css | ||
|
@@ -73,14 +87,15 @@ RUN mkdir -p /var/run/sshd /var/www/upload/server/php/chroot /run/php && \ | |
chmod 775 /var/www/upload/server/php/chroot/files && \ | ||
chmod 755 /var /var/www /var/www/upload /var/www/upload/server /var/www/upload/server/php \ | ||
/var/www/upload/server/php/chroot && \ | ||
echo "Put your files into /files. Don't use subdirectories.\nThey cannot be accessed via the web user interface!" \ | ||
echo "Put your files into /files. Don't use subdirectories." \ | ||
>/var/www/upload/server/php/chroot/README.txt && \ | ||
rm -rf /var/lib/apt/lists/* /var/cache/* /tmp/* /var/tmp/* /var/www/upload/server/php/chroot/files/.gitignore /tmp/sshd_config | ||
|
||
VOLUME [ "/var/www/upload/server/php/chroot/files" ] | ||
EXPOSE 22 80 | ||
|
||
ENTRYPOINT [ "/docker-entrypoint.sh" ] | ||
ENTRYPOINT ["/usr/local/bin/docker-uid-gid-setup.sh", "/docker-entrypoint.sh"] | ||
|
||
CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf", "-u", "root", "-n"] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.