diff --git a/.docker/Dockerfile-alpine b/.docker/Dockerfile-alpine index 075a1a75328..1cc14658cac 100644 --- a/.docker/Dockerfile-alpine +++ b/.docker/Dockerfile-alpine @@ -1,22 +1,29 @@ FROM alpine:3.20 -RUN addgroup -S ory; \ - adduser -S ory -G ory -D -H -s /bin/nologin && \ - apk upgrade --no-cache && \ +RUN < /etc/nsswitch.conf + # Add a user/group for Ory with a stable UID + GID: + # NOTE: This only appears relevant for supporting hydra as non-root, otherwise unnecessary. + addgroup --system --gid 500 ory + adduser --system --uid 500 \ + --gecos "Ory User" \ + --home /home/ory \ + --ingroup ory \ + --shell /sbin/nologin \ + ory -# By creating the sqlite folder as the ory user, the mounted volume will be owned by ory:ory, which -# is required for read/write of SQLite. -RUN mkdir -p /var/lib/sqlite && \ - chown ory:ory /var/lib/sqlite + # Create the sqlite directory with ownership to that user and group: + # NOTE: This is required for read/write by SQLite. + # - Path may be a default value somewhere, or only explicitly provided via DSN? + # - Owner/Group is only relevant to permissions allowing the hydra process to read/write to the location. + # - Bind mount volumes will replace the ownership with that of the host directory, requiring correction. + install --owner ory --group ory --directory /var/lib/sqlite +HEREDOC -USER ory +COPY hydra /usr/bin/hydra ENTRYPOINT ["hydra"] CMD ["serve", "all"] +USER ory diff --git a/.docker/Dockerfile-build b/.docker/Dockerfile-build index 18cc454fba9..0c858feaeb3 100644 --- a/.docker/Dockerfile-build +++ b/.docker/Dockerfile-build @@ -23,8 +23,6 @@ FROM gcr.io/distroless/static-debian12:nonroot AS runner COPY --from=builder --chown=nonroot:nonroot /var/lib/sqlite /var/lib/sqlite COPY --from=builder /usr/bin/hydra /usr/bin/hydra -VOLUME /var/lib/sqlite - # Declare the standard ports used by hydra (4444 for public service endpoint, 4445 for admin service endpoint) EXPOSE 4444 4445 diff --git a/.docker/Dockerfile-hsm b/.docker/Dockerfile-hsm index c4199fe87e4..8c51e3fcdac 100644 --- a/.docker/Dockerfile-hsm +++ b/.docker/Dockerfile-hsm @@ -53,30 +53,36 @@ ENV HSM_LIBRARY=/usr/lib/softhsm/libsofthsm2.so ENV HSM_TOKEN_LABEL=hydra ENV HSM_PIN=1234 +# NOTE: This is broken already. Even though this image provides a shell, you'd need to configure it with +# `SHELL ["/busybox/sh", "-c"]`, however `apt-get` does not exist either in a distroless image. +# This was original an Alpine image, the refactoring was not verified properly in this commit: +# https://github.com/ory/hydra/commit/c1e1a569621d88365dceee7372ca49ecd119f939#diff-ae54bef08e3587b28ad8e93eb253a9a5cd9ea6f4251977e35b88dc6b42329e25L31 RUN apt-get -y install softhsm opensc &&\ pkcs11-tool --module "$HSM_LIBRARY" --slot 0 --init-token --so-pin 0000 --init-pin --pin "$HSM_PIN" --label "$HSM_TOKEN_LABEL" -RUN addgroup -S ory; \ - adduser -S ory -G ory -D -h /home/ory -s /bin/nologin; \ - chown -R ory:ory /home/ory; \ +RUN < /etc/nsswitch.conf +FROM alpine:3.20 AS base-files -RUN addgroup -S ory; \ - adduser -S ory -G ory -D -h /home/ory -s /bin/nologin; +RUN <