@@ -9,8 +9,9 @@ ARG PRODUCT
99ARG SCALA
1010ARG OPA_AUTHORIZER
1111ARG JMX_EXPORTER
12+ ARG STACKABLE_USER_UID
1213
13- USER stackable
14+ USER ${STACKABLE_USER_UID}
1415WORKDIR /stackable
1516
1617RUN curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}-src.tgz" | tar -xzC . && \
@@ -27,35 +28,20 @@ RUN curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}
2728RUN curl https://repo.stackable.tech/repository/packages/kafka-opa-authorizer/opa-authorizer-${OPA_AUTHORIZER}-all.jar \
2829 -o /stackable/kafka_${SCALA}-${PRODUCT}/libs/opa-authorizer-${OPA_AUTHORIZER}-all.jar
2930
30- COPY --chown=stackable:stackable kafka/stackable/jmx/ /stackable/jmx/
31+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
3132RUN curl https://repo.stackable.tech/repository/packages/jmx-exporter/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar \
3233 -o /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
3334 chmod +x /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
3435 ln -s /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar /stackable/jmx/jmx_prometheus_javaagent.jar
3536
36- # For earlier versions this script removes the .class file that contains the
37- # vulnerable code.
38- # TODO: This can be restricted to target only versions which do not honor the environment
39- # varible that has been set above but this has not currently been implemented
40- COPY shared/log4shell.sh /bin
41- RUN /bin/log4shell.sh /stackable/kafka_${SCALA}-${PRODUCT}
42-
43- # Ensure no vulnerable files are left over
44- # This will currently report vulnerable files being present, as it also alerts on
45- # SocketNode.class, which we do not remove with our scripts.
46- # Further investigation will be needed whether this should also be removed.
47- COPY shared/log4shell_1.6.1-log4shell_Linux_x86_64 /bin/log4shell_scanner_x86_64
48- COPY shared/log4shell_1.6.1-log4shell_Linux_aarch64 /bin/log4shell_scanner_aarch64
49- COPY shared/log4shell_scanner /bin/log4shell_scanner
50- RUN /bin/log4shell_scanner s /stackable/kafka_${SCALA}-${PRODUCT}
51- # ===
5237
5338FROM stackable/image/java-base AS final
5439
5540ARG RELEASE
5641ARG PRODUCT
5742ARG SCALA
5843ARG KCAT
44+ ARG STACKABLE_USER_UID
5945
6046LABEL name="Apache Kafka" \
6147 maintainer="info@stackable.tech" \
@@ -67,32 +53,38 @@ LABEL name="Apache Kafka" \
6753
6854# This is needed for kubectl
6955COPY kafka/kubernetes.repo /etc/yum.repos.d/kubernetes.repo
70- RUN microdnf update && \
71- microdnf install \
72- # needed by kcat for kerberos
73- cyrus-sasl-gssapi \
74- # Can be removed once listener-operator integration is used
75- kubectl && \
76- microdnf clean all && \
77- rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n " | sort > /stackable/package_manifest.txt && \
78- rm -rf /var/cache/yum
79-
80- USER stackable
81- WORKDIR /stackable
82-
83- COPY --chown=stackable:stackable kafka/licenses /licenses
56+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
57+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka_${SCALA}-${PRODUCT}
58+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/jmx/ /stackable/jmx/
59+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /stackable/kcat-${KCAT}/kcat /stackable/bin/kcat-${KCAT}
60+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /licenses /licenses
8461
85- # We copy opa-authorizer.jar and jmx-exporter through the builder image to have an absolutely minimal final image
86- # (e.g. we don't even need curl in it).
87- COPY --chown=stackable:stackable --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka_${SCALA}-${PRODUCT}
88- COPY --chown=stackable:stackable --from=kafka-builder /stackable/jmx/ /stackable/jmx/
89- COPY --chown=stackable:stackable --from=kcat /stackable/kcat-${KCAT}/kcat /stackable/bin/kcat-${KCAT}
90- COPY --chown=stackable:stackable --from=kcat /licenses /licenses
62+ WORKDIR /stackable
9163
92- RUN ln -s /stackable/bin/kcat-${KCAT} /stackable/bin/kcat && \
93- # kcat was located in /stackable/kcat - legacy
94- ln -s /stackable/bin/kcat /stackable/kcat && \
95- ln -s /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka
64+ RUN <<EOF
65+ microdnf update
66+ # cyrus-sasl-gssapi: needed by kcat for kerberos
67+ # kubectl: Can be removed once listener-operator integration is used
68+ microdnf install \
69+ cyrus-sasl-gssapi \
70+ kubectl
71+
72+ microdnf clean all
73+ rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n " | sort > /stackable/package_manifest.txt
74+ rm -rf /var/cache/yum
75+
76+ ln -s /stackable/bin/kcat-${KCAT} /stackable/bin/kcat
77+ # kcat was located in /stackable/kcat - legacy
78+ ln -s /stackable/bin/kcat /stackable/kcat
79+ ln -s /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka
80+
81+ # All files and folders owned by root group to support running as arbitrary users.
82+ # This is best practice as all container users will belong to the root group (0).
83+ chown -R ${STACKABLE_USER_UID}:0 /stackable
84+ chmod -R g=u /stackable
85+ EOF
86+
87+ USER ${STACKABLE_USER_UID}
9688
9789ENV PATH="${PATH}:/stackable/bin:/stackable/kafka/bin"
9890
0 commit comments