Skip to content

Commit 3dd4b6f

Browse files
authored
fix: drop privileges during docker build (#773)
Until now, the WDQS image started as root. In the entrypoint priveleges were dropped and we switched to the "blazegraph" user. With this patch, we switch to the "blazegraph" user already during build. So the container always uses this user and does not start as root anymore. This fixes some issues when running an interactive bash inside the container and simplifies the updater reset workaround. https://phabricator.wikimedia.org/T362963
1 parent 4c2909d commit 3dd4b6f

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

build/wdqs/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ RUN apt-get update && \
5454
COPY --from=fetcher --chown=blazegraph:blazegraph /tmp/wdqs-service /wdqs
5555

5656
RUN mkdir /var/log/wdqs && chown blazegraph /var/log/wdqs
57+
RUN mkdir /wdqs/data && chown blazegraph /wdqs/data
5758

5859
# Don't set a memory limit otherwise bad things happen (OOMs)
5960
ENV MEMORY=""\
@@ -77,4 +78,6 @@ COPY --chown=blazegraph:blazegraph RWStore.properties allowlist.txt logback.xml
7778
# TODO this shouldn't be needed, but CI currently doesnt check for the +x bit, which is why this line is here
7879
RUN chmod +x /wdqs/runUpdate.sh
7980

81+
USER blazegraph
82+
8083
ENTRYPOINT ["/entrypoint.sh"]

build/wdqs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ In the Docker Compose example provided above, you might use the commands and ins
213213
docker compose stop wdqs-updater
214214
215215
# Start an updater with force sync settings
216-
docker compose run --rm wdqs-updater bash '/wdqs/runUpdate.sh -h http://"$WDQS_HOST":"$WDQS_PORT" -- --wikibaseUrl "$WIKIBASE_SCHEME"://"$WIKIBASE_HOST" --conceptUri "$WIKIBASE_SCHEME"://"$WIKIBASE_HOST" --entityNamespaces "$WDQS_ENTITY_NAMESPACES" --init --start $(date +%Y%m%d000000)'
216+
docker compose run --rm wdqs-updater /wdqs/runUpdate.sh -h http://\$WDQS_HOST:\$WDQS_PORT -- --wikibaseUrl \$WIKIBASE_SCHEME://\$WIKIBASE_HOST --conceptUri \$WIKIBASE_SCHEME://\$WIKIBASE_HOST --entityNamespaces \$WDQS_ENTITY_NAMESPACES --init --start $(date +%Y%m%d000000)
217217
218218
# As soon as you see "Sleeping for 10 secs" in the logs, press CTRL-C to stop it again
219219

build/wdqs/entrypoint.sh

+4-14
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# Test if required environment variables have been set
55
REQUIRED_VARIABLES=(WIKIBASE_HOST WDQS_HOST WDQS_PORT)
66
for i in "${REQUIRED_VARIABLES[@]}"; do
7-
eval THISSHOULDBESET=\$"$i"
8-
if [ -z "$THISSHOULDBESET" ]; then
7+
eval THISSHOULDBESET=\$"$i"
8+
if [ -z "$THISSHOULDBESET" ]; then
99
echo "$i is required but isn't set. You should pass it to docker. See: https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file";
1010
exit 1;
11-
fi
11+
fi
1212
done
1313

1414
set -eu
@@ -17,15 +17,5 @@ export BLAZEGRAPH_OPTS="${BLAZEGRAPH_EXTRA_OPTS} -DwikibaseHost=${WIKIBASE_HOST}
1717
export UPDATER_OPTS="-DwikibaseHost=${WIKIBASE_HOST} -DwikibaseMaxDaysBack=${WIKIBASE_MAX_DAYS_BACK}"
1818

1919
envsubst < /templates/mwservices.json > /wdqs/mwservices.json
20-
chown blazegraph:blazegraph /wdqs/mwservices.json
2120

22-
# The data directory should always be owned by the blazegraph user
23-
# This used to be owned by root (https://phabricator.wikimedia.org/T237248)
24-
if [ -d /wdqs/data/ ]; then
25-
chown blazegraph:blazegraph -R /wdqs/data/
26-
fi
27-
28-
# Start as the blazegraph user.
29-
# --preserve-environment does not preserve PATH, so we manually
30-
# set the PATH again. Java cannot be found otherwise.
31-
su --preserve-environment --command "export PATH=$PATH; $*" blazegraph
21+
exec $(echo "$@"| envsubst)

0 commit comments

Comments
 (0)