Replies: 4 comments 13 replies
-
We would probably want to think of way to generate it, so that it wouldn't have to be separately maintained. For example have the build command create one. Or are you thinking that the Keycloak project should provide both shell and shell-free base image? |
Beta Was this translation helpful? Give feedback.
-
|
Wouldn't this make it impossible to then provide CLI args to the KC instance? So I could not do something like: |
Beta Was this translation helpful? Give feedback.
-
|
I'll note that the current ubi-micro setup is already well hardened. Perhaps more hardened than many users would like. We chose back then to retain a minimal shell for keycloak's startup and also debugging ubi-micro is capable of going fully distroless while maintaining relevant metadata that is important for supply chain control and provenance. I would disagree with any move to vendored parent images like |
Beta Was this translation helpful? Give feedback.
-
|
I very much like the idea of having Keycloak run "distroless". As an IdP it needs to be accessible from basically everywhere in our org and our security people would very much appreciate the fact that there is no shell for executing arbitrary stuff in such containers. Personally, I never needed a shell in the Keycloak container, so far. For debugging, I could still add ephemeral containers with shell to the pods. I like @alkersan's initial approach. While I am aware of the image's limited configuration override capabilities, I'd personally say the extra image build step for reconfiguration is worth it. Of course, that this is not an image which is useful to be publicly released. I managed to populate the FROM quay.io/keycloak/keycloak:26.6.1 AS builder
ENV KC_DB=dev-file \
KC_HEALTH_ENABLED=true \
KC_METRICS_ENABLED=true
WORKDIR /opt/keycloak
RUN <<EOF
bin/kc.sh build && bin/kc.sh show-config
kc_default_arg_str=" $(JAVA=echo bin/kc.sh)"
IFS="|" read -ra args <<< "${kc_default_arg_str// -/|}"
for arg in "${args[@]:1}"; do echo "-$arg"; done | tee conf/default.args
EOF
FROM gcr.io/distroless/java25-debian13:nonroot
COPY --from=builder --chown=65472:65472 /opt/keycloak /opt/keycloak
ENV LANG=en_US.UTF-8 \
KC_RUN_IN_CONTAINER=true \
KC_HOSTNAME="http://localhost:8080" \
KC_HTTP_ENABLED="true"
WORKDIR /opt/keycloak
USER 65472:65472
ENTRYPOINT ["java", "@conf/default.args"]
CMD ["start", "--optimized"]In a nutshell, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I think it's fair to say that there is general tendency toward more and more hardened and minimal runtime images. These intentionally avoid including components such as a shell, package manager, or other tools that are not required at runtime. Docker Hardened Images (DHI), for example, distinguish between runtime-focused and -dev variants for exactly this reason (btw, there is a variant of keycloak).
After studying how the current docker image is composed and wondering what it would take to run it on an even slimmer java runtime container - the current
kc.shentrypoint implies that a shell interpreter must be supplied. Essentially it prepears the final java command with required options. But I've also learned that since java 9 it's possible to supply those via an@argfilesyntax. And here is an example how the optimized image could be structured:and the
default.argsis basically a compilation of everything that kc.sh collects:Starting JVM this way technically saves ~100MB from the unpacked image, minus a few bash dependencies which otherwise would be a subject for vulnerability scanners.
Could it useful to bundle such args file into default keycloak builds?
Beta Was this translation helpful? Give feedback.
All reactions