@@ -9,53 +9,56 @@ ARG PRODUCT
99ARG SCALA
1010ARG OPA_AUTHORIZER
1111ARG JMX_EXPORTER
12+ ARG STACKABLE_USER_UID
1213
13- USER stackable
14+ RUN <<EOF
15+ microdnf update
16+
17+ # patch: Required for the apply-patches.sh script
18+ microdnf install \
19+ patch
20+
21+ microdnf clean all
22+ rm -rf /var/cache/yum
23+ EOF
24+
25+ USER ${STACKABLE_USER_UID}
1426WORKDIR /stackable
1527
28+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/apply_patches.sh /stackable/kafka-${PRODUCT}-src/patches/apply_patches.sh
29+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/${PRODUCT} /stackable/kafka-${PRODUCT}-src/patches/${PRODUCT}
30+
1631RUN curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}-src.tgz" | tar -xzC . && \
1732 cd kafka-${PRODUCT}-src && \
33+ ./patches/apply_patches.sh ${PRODUCT} && \
1834 # TODO: Try to install gradle via package manager (if possible) instead of fetching it from the internet
1935 # We don't specify "-x test" to skip the tests, as we might bump some Kafka internal dependencies in the future and
2036 # it's a good idea to run the tests in this case.
2137 ./gradlew clean releaseTarGz && \
38+ ./gradlew cyclonedxBom && \
2239 tar -xf core/build/distributions/kafka_${SCALA}-${PRODUCT}.tgz -C /stackable && \
40+ cp build/reports/bom.json /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json && \
2341 rm -rf /stackable/kafka_${SCALA}-${PRODUCT}/site-docs/ && \
2442 rm -rf /stackable/kafka-${PRODUCT}-src
2543
2644# TODO (@NickLarsenNZ): Compile from source: https://github.com/StyraInc/opa-kafka-plugin
2745RUN curl https://repo.stackable.tech/repository/packages/kafka-opa-authorizer/opa-authorizer-${OPA_AUTHORIZER}-all.jar \
2846 -o /stackable/kafka_${SCALA}-${PRODUCT}/libs/opa-authorizer-${OPA_AUTHORIZER}-all.jar
2947
30- COPY --chown=stackable:stackable kafka/stackable/jmx/ /stackable/jmx/
48+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
3149RUN curl https://repo.stackable.tech/repository/packages/jmx-exporter/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar \
3250 -o /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
3351 chmod +x /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
3452 ln -s /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar /stackable/jmx/jmx_prometheus_javaagent.jar
3553
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- # ===
5254
5355FROM stackable/image/java-base AS final
5456
5557ARG RELEASE
5658ARG PRODUCT
5759ARG SCALA
5860ARG KCAT
61+ ARG STACKABLE_USER_UID
5962
6063LABEL name="Apache Kafka" \
6164@@ -67,32 +70,39 @@ LABEL name="Apache Kafka" \
6770
6871# This is needed for kubectl
6972COPY 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
73+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
74+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka_${SCALA}-${PRODUCT}
75+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json /stackable/kafka_${SCALA}-${PRODUCT}/kafka_${SCALA}-${PRODUCT}.cdx.json
76+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/jmx/ /stackable/jmx/
77+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /stackable/kcat-${KCAT}/kcat /stackable/bin/kcat-${KCAT}
78+ COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /licenses /licenses
8479
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
80+ WORKDIR /stackable
9181
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
82+ RUN <<EOF
83+ microdnf update
84+ # cyrus-sasl-gssapi: needed by kcat for kerberos
85+ # kubectl: Can be removed once listener-operator integration is used
86+ microdnf install \
87+ cyrus-sasl-gssapi \
88+ kubectl
89+
90+ microdnf clean all
91+ rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n " | sort > /stackable/package_manifest.txt
92+ rm -rf /var/cache/yum
93+
94+ ln -s /stackable/bin/kcat-${KCAT} /stackable/bin/kcat
95+ # kcat was located in /stackable/kcat - legacy
96+ ln -s /stackable/bin/kcat /stackable/kcat
97+ ln -s /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka
98+
99+ # All files and folders owned by root group to support running as arbitrary users.
100+ # This is best practice as all container users will belong to the root group (0).
101+ chown -R ${STACKABLE_USER_UID}:0 /stackable
102+ chmod -R g=u /stackable
103+ EOF
104+
105+ USER ${STACKABLE_USER_UID}
96106
97107ENV PATH="${PATH}:/stackable/bin:/stackable/kafka/bin"
98108
0 commit comments