Skip to content

Commit

Permalink
Run app as unprivileged user
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfr committed Jan 11, 2018
1 parent 1303bbd commit 9458f7f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ script:
- test -f "$DOCKER_DIR/image.tar" && docker load -i "$DOCKER_DIR/image.tar" || true
- docker build -t core:build --target build .
- docker build -t core:dist --target dist --build-arg VCS_BRANCH="$TRAVIS_BRANCH" --build-arg VCS_COMMIT="$TRAVIS_COMMIT" .
- docker build -t core:testing --target testing .
- docker build -t core:testing --target dev .
- docker save -o "$DOCKER_DIR/image.tar" $(docker history -q core:build | grep -v '<missing>') $(docker history -q core:dist | grep -v '<missing>')
- ./tests/bin/run-tests-docker.sh --image core:testing

Expand Down
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ RUN apk add --no-cache git
COPY --from=build /usr/local/sbin/unitd /usr/local/sbin/unitd
COPY --from=build /usr/local/lib/python.unit.so /usr/local/lib/python.unit.so

EXPOSE 80 8080 27017
EXPOSE 80 8080
VOLUME /data/db
VOLUME /data/persistent

WORKDIR /src/core
ENV SCITRAN_PERSISTENT_DATA_PATH=/data/persistent

COPY docker/unit.json /var/local/unit/conf.json
COPY requirements.txt requirements.txt
Expand All @@ -28,14 +31,17 @@ RUN pip install -r requirements.txt
COPY . .
RUN pip install -e .

CMD ["unitd", "--control", "*:8080", "--no-daemon", "--log", "/dev/stdout"]

ARG VCS_BRANCH=NULL
ARG VCS_COMMIT=NULL
RUN docker/build_info.sh $VCS_BRANCH $VCS_COMMIT | tee /version.json

ENTRYPOINT ["./entrypoint.sh"]
CMD ["unitd", "--control", "*:8080", "--no-daemon", "--log", "/dev/stdout"]


FROM dist as dev

FROM dist as testing
EXPOSE 27017

RUN apk add --no-cache mongodb

Expand Down
4 changes: 3 additions & 1 deletion docker/dev+mongo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
mongod &
MONGOD_PID=$!

exec unitd --control "*:8888" --no-daemon --log /dev/stdout
chown nobody:nobody -R $SCITRAN_PERSISTENT_DATA_PATH

exec unitd --control "*:8080" --no-daemon --log /dev/stdout
3 changes: 1 addition & 2 deletions docker/unit.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"scitran-core": {
"type": "python",
"workers": 2,
"user": "root",
"group": "root",
"user": "nobody",
"path": "/src/core",
"module": "api.app"
}
Expand Down
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

set -e

# If running unitd and started as root, update file ownership
if [ "$1" == "unitd" -a "$(id -u)" == "0" ]; then
chown nobody:nobody -R $SCITRAN_PERSISTENT_DATA_PATH
fi

exec "$@"

0 comments on commit 9458f7f

Please sign in to comment.