Skip to content

Commit a148c94

Browse files
committed
Running applications as non-root user.
1 parent d502a0d commit a148c94

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

cog/Dockerfile

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FROM esgfhub/centos67_python27:latest
66
MAINTAINER Luca Cinquini <luca.cinquini@jpl.nasa.gov>
77

88
# choose CoG version
9-
ENV COG_TAG=v3.6.0
9+
ENV COG_TAG=v3.6.1
1010

1111
# setup CoG environment
1212
ENV COG_DIR=/usr/local/cog
@@ -48,3 +48,21 @@ RUN cd $COG_DIR && \
4848
cd mkproxy && \
4949
make && \
5050
cp mkproxy $COG_DIR/venv/lib/python2.7/site-packages/globusonline_transfer_api_client-0.10.16-py2.7.egg/globusonline/transfer/api_client/x509_proxy/.
51+
52+
# expose default django port
53+
EXPOSE 8000
54+
55+
# create non-privileged user to run django
56+
RUN groupadd -r cogadmin && \
57+
useradd -r -g cogadmin cogadmin && \
58+
mkdir -p ~cogadmin && \
59+
chown cogadmin:cogadmin ~cogadmin
60+
61+
# change user prompt
62+
RUN echo 'export PS1="[\u@\h]\$ "' >> ~cogadmin/.bashrc
63+
64+
# change ownership of application directories
65+
RUN chown -R cogadmin:cogadmin $COG_DIR
66+
67+
# expose application data (must do this AFTER chown)
68+
VOLUME $COG_DIR

cog_postgres/Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CoG image configured for ESGF node
2-
FROM esgfhub/cog
2+
FROM esgfhub/cog:v3.6.1
33

44
MAINTAINER Luca Cinquini <luca.cinquini@jpl.nasa.gov>
55

@@ -47,6 +47,9 @@ RUN echo 'db.host=localhost' >> /esg/config/esgf.properties
4747
RUN echo 'db.port=5432' >> /esg/config/esgf.properties
4848
RUN echo 'changeit' >> /esg/config/.esgf_pass
4949

50+
# default working directory
51+
WORKDIR $COG_INSTALL_DIR
52+
5053
# start up django+CoG with correct host IP
5154
COPY ./docker-entrypoint.sh /
5255
ENTRYPOINT ["/docker-entrypoint.sh"]

cog_postgres/docker-entrypoint.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
source $COG_DIR/venv/bin/activate
55

66
# start postgres
7+
# must issue this command as user 'root' becoming user 'postgres'
78
su -c 'pg_ctl start -D /var/lib/pgsql/data' postgres
89

910
# upgrade CoG
@@ -18,6 +19,9 @@ sed -i 's/ALLOWED_HOSTS = .*/ALLOWED_HOSTS = '"${DOCKER_IP}"'/g' $COG_CONFIG_DIR
1819
# PRODUCTION_SERVER = True would require use of SSL to transmit any cookie
1920
sed -i 's/PRODUCTION_SERVER = True/PRODUCTION_SERVER = False/g' $COG_CONFIG_DIR/cog_settings.cfg
2021

22+
# change ownerksip of directory
23+
chown -R cogadmin:cogadmin $COG_DIR
24+
2125
# Start CoG in virtual environment
2226
cd $COG_INSTALL_DIR
23-
python ./manage.py runserver 0.0.0.0:8000
27+
su -c 'python ./manage.py runserver 0.0.0.0:8000' cogadmin

cog_sqllite/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
# All setup and configuration is executed by the docker entrypoint
33
# when the container starts up.
44

5-
FROM esgfhub/cog
5+
FROM esgfhub/cog:v3.6.1
66

77
MAINTAINER Luca Cinquini <luca.cinquini@jpl.nasa.gov>
88

9+
# default user
10+
USER cogadmin
11+
12+
# default working directory
13+
WORKDIR $COG_INSTALL_DIR
14+
915
# start up django+CoG with correct host IP
1016
COPY ./docker-entrypoint.sh /
1117
ENTRYPOINT ["/docker-entrypoint.sh"]

0 commit comments

Comments
 (0)