Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: named volume permissions in docker #3518

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tools/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ set -e
# first arg is `-some-option`
if [ "${1#-}" != "$1" ]; then
# override arguments by prepending "dragonfly --logtostderr" to them.
set -- dragonfly --logtostderr "$@"
set -- dragonfly --logtostderr "$@"
fi

# allow the docker container to be started with `--user`
if [ "$1" = 'dragonfly' -a "$(id -u)" = '0' ]; then
exec su-exec dfly "$0" "$@" # runs this script under user dfly
# find all the files in the WORKDIR including the dir itself that do not
# have dfly user on them and chmod them to dfly.
find . \! -user dfly -exec chown dfly '{}' +
# runs this script under user dfly
exec setpriv --reuid=dfly --regid=dfly --clear-groups -- "$0" "$@"
fi

um="$(umask)"
if [ "$um" = '0022' ]; then
umask 0077 # restrict access permissions only to the owner
fi

exec "$@"
4 changes: 1 addition & 3 deletions tools/packaging/Dockerfile.alpine-dev
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPY tools/docker/healthcheck.sh /usr/local/bin/healthcheck.sh
COPY --from=builder /build/build-release/dragonfly /usr/local/bin/

RUN apk --no-cache add libgcc libstdc++ \
su-exec netcat-openbsd boost-context && ldd /usr/local/bin/dragonfly
setpriv netcat-openbsd boost-context && ldd /usr/local/bin/dragonfly

RUN addgroup -S -g 1000 dfly && adduser -S -G dfly -u 999 dfly
RUN mkdir /data && chown dfly:dfly /data
Expand All @@ -43,6 +43,4 @@ ENTRYPOINT ["entrypoint.sh"]

EXPOSE 6379

USER dfly

CMD ["dragonfly", "--logtostderr"]
8 changes: 1 addition & 7 deletions tools/packaging/Dockerfile.ubuntu-dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ RUN make release

RUN build-release/dragonfly --version

RUN curl -O https://raw.githubusercontent.com/ncopa/su-exec/212b75144bbc06722fbd7661f651390dc47a43d1/su-exec.c && \
gcc -Wall -O2 su-exec.c -o su-exec

FROM debian:12-slim
FROM ubuntu:22.04

RUN --mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/var/lib/apt/lists \
Expand All @@ -30,7 +27,6 @@ WORKDIR /data

COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY tools/docker/healthcheck.sh /usr/local/bin/healthcheck.sh
COPY --from=builder /build/su-exec /usr/local/bin/
COPY --from=builder /build/build-release/dragonfly /usr/local/bin/

HEALTHCHECK CMD /usr/local/bin/healthcheck.sh
Expand All @@ -39,6 +35,4 @@ ENTRYPOINT ["entrypoint.sh"]
# For inter-container communication.
EXPOSE 6379

USER dfly

CMD ["dragonfly", "--logtostderr"]
8 changes: 0 additions & 8 deletions tools/packaging/Dockerfile.ubuntu-prod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ WORKDIR /build
COPY tools/docker/fetch_release.sh /tmp/
COPY releases/dragonfly-* /tmp/

ARG SUEXEC_HASH=d6c40440609a23483f12eb6295b5191e94baf08298a856bab6e15b10c3b82891
RUN curl -O https://raw.githubusercontent.com/ncopa/su-exec/212b75144bbc06722fbd7661f651390dc47a43d1/su-exec.c && \
if [ "$SUEXEC_HASH" != $(sha256sum su-exec.c | awk '{print $1}') ]; then echo "Wrong hash!" && exit 1; fi && \
gcc -Wall -O2 su-exec.c -o su-exec

RUN /tmp/fetch_release.sh ${TARGETPLATFORM}

# Now prod image
Expand All @@ -35,7 +30,6 @@ WORKDIR /data

COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY tools/docker/healthcheck.sh /usr/local/bin/healthcheck.sh
COPY --from=builder /build/su-exec /usr/local/bin/
COPY --from=builder /build/dragonfly /usr/local/bin/

HEALTHCHECK CMD /usr/local/bin/healthcheck.sh
Expand All @@ -44,6 +38,4 @@ ENTRYPOINT ["entrypoint.sh"]
# For inter-container communication.
EXPOSE 6379

USER dfly

CMD ["dragonfly", "--logtostderr"]
Loading