@@ -27,30 +27,35 @@ WORKDIR /stackable
2727
2828COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/apply_patches.sh /stackable/kafka-${PRODUCT}-src/patches/apply_patches.sh
2929COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/${PRODUCT} /stackable/kafka-${PRODUCT}-src/patches/${PRODUCT}
30+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
3031
31- RUN curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}-src.tgz" | tar -xzC . && \
32- cd kafka-${PRODUCT}-src && \
33- ./patches/apply_patches.sh ${PRODUCT} && \
34- # TODO: Try to install gradle via package manager (if possible) instead of fetching it from the internet
35- # We don't specify "-x test" to skip the tests, as we might bump some Kafka internal dependencies in the future and
36- # it's a good idea to run the tests in this case.
37- ./gradlew clean releaseTarGz && \
38- ./gradlew cyclonedxBom && \
39- tar -xf core/build/distributions/kafka_${SCALA}-${PRODUCT}.tgz -C /stackable && \
40- cp build/reports/bom.json /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json && \
41- rm -rf /stackable/kafka_${SCALA}-${PRODUCT}/site-docs/ && \
42- rm -rf /stackable/kafka-${PRODUCT}-src
32+ RUN <<EOF
33+ curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}-src.tgz" | tar -xzC .
34+ cd kafka-${PRODUCT}-src
35+ ./patches/apply_patches.sh ${PRODUCT}
36+ # TODO: Try to install gradle via package manager (if possible) instead of fetching it from the internet
37+ # We don't specify "-x test" to skip the tests, as we might bump some Kafka internal dependencies in the future and
38+ # it's a good idea to run the tests in this case.
39+ ./gradlew clean releaseTarGz
40+ ./gradlew cyclonedxBom
41+ tar -xf core/build/distributions/kafka_${SCALA}-${PRODUCT}.tgz -C /stackable
42+ cp build/reports/bom.json /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json
43+ rm -rf /stackable/kafka_${SCALA}-${PRODUCT}/site-docs/
44+ rm -rf /stackable/kafka-${PRODUCT}-src
4345
4446# TODO (@NickLarsenNZ): Compile from source: https://github.com/StyraInc/opa-kafka-plugin
45- RUN curl https://repo.stackable.tech/repository/packages/kafka-opa-authorizer/opa-authorizer-${OPA_AUTHORIZER}-all.jar \
46- -o /stackable/kafka_${SCALA}-${PRODUCT}/libs/opa-authorizer-${OPA_AUTHORIZER}-all.jar
47+ curl https://repo.stackable.tech/repository/packages/kafka-opa-authorizer/opa-authorizer-${OPA_AUTHORIZER}-all.jar \
48+ -o /stackable/kafka_${SCALA}-${PRODUCT}/libs/opa-authorizer-${OPA_AUTHORIZER}-all.jar
4749
48- COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
49- RUN curl https://repo.stackable.tech/repository/packages/jmx-exporter/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar \
50- -o /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
51- chmod +x /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
52- ln -s /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar /stackable/jmx/jmx_prometheus_javaagent.jar
50+ # JMX exporter
51+ curl https://repo.stackable.tech/repository/packages/jmx-exporter/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar \
52+ -o /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar
53+ chmod +x /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar
54+ ln -s /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar /stackable/jmx/jmx_prometheus_javaagent.jar
5355
56+ # change groups
57+ chmod -R g=u /stackable
58+ EOF
5459
5560FROM stackable/image/java-base AS final
5661
@@ -60,21 +65,23 @@ ARG SCALA
6065ARG KCAT
6166ARG STACKABLE_USER_UID
6267
63- LABEL name="Apache Kafka" \
64- 65- vendor="Stackable GmbH" \
66- version="${PRODUCT}" \
67- release="${RELEASE}" \
68- summary="The Stackable image for Apache Kafka." \
69- description="This image is deployed by the Stackable Operator for Apache Kafka."
68+ LABEL \
69+ name="Apache Kafka" \
70+ 71+ vendor="Stackable GmbH" \
72+ version="${PRODUCT}" \
73+ release="${RELEASE}" \
74+ summary="The Stackable image for Apache Kafka." \
75+ description="This image is deployed by the Stackable Operator for Apache Kafka."
7076
71- COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
7277COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka_${SCALA}-${PRODUCT}
7378COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json /stackable/kafka_${SCALA}-${PRODUCT}/kafka_${SCALA}-${PRODUCT}.cdx.json
7479COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/jmx/ /stackable/jmx/
7580COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /stackable/kcat-${KCAT}/kcat /stackable/bin/kcat-${KCAT}
7681COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /licenses /licenses
7782
83+ COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
84+
7885WORKDIR /stackable
7986
8087RUN <<EOF
@@ -85,24 +92,39 @@ microdnf install \
8592
8693microdnf clean all
8794rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n " | sort > /stackable/package_manifest.txt
95+ chown ${STACKABLE_USER_UID}:0 /stackable/package_manifest.txt
96+ chmod g=u /stackable/package_manifest.txt
8897rm -rf /var/cache/yum
8998
9099ln -s /stackable/bin/kcat-${KCAT} /stackable/bin/kcat
100+ chown -h ${STACKABLE_USER_UID}:0 /stackable/bin/kcat
91101# kcat was located in /stackable/kcat - legacy
92102ln -s /stackable/bin/kcat /stackable/kcat
103+ chown -h ${STACKABLE_USER_UID}:0 /stackable/kcat
93104ln -s /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka
105+ chown -h ${STACKABLE_USER_UID}:0 /stackable/kafka
94106
95- # All files and folders owned by root group to support running as arbitrary users.
96- # This is best practice as all container users will belong to the root group (0).
97- chown -R ${STACKABLE_USER_UID}:0 /stackable
98- chmod -R g=u /stackable
107+ # fix missing permissions
108+ chmod g=u /stackable/bin
109+ chmod g=u /stackable/jmx
110+ chmod g=u /stackable/kafka_${SCALA}-${PRODUCT}
111+ EOF
112+
113+ # ----------------------------------------
114+ # Checks
115+ # This section is to run final checks to ensure the created final images
116+ # adhere to several minimal requirements like:
117+ # - check file permissions and ownerships
118+ # ----------------------------------------
119+
120+ # Check that permissions and ownership in /stackable are set correctly
121+ # This will fail and stop the build if any mismatches are found.
122+ RUN <<EOF
123+ /bin/check-permissions-ownership.sh /stackable ${STACKABLE_USER_UID} 0
99124EOF
100125
101126# ----------------------------------------
102- # Attention: We are changing the group of all files in /stackable directly above
103- # If you do any file based actions (copying / creating etc.) below this comment you
104- # absolutely need to make sure that the correct permissions are applied!
105- # chown ${STACKABLE_USER_UID}:0
127+ # Attention: Do not perform any file based actions (copying/creating etc.) below this comment because the permissions would not be checked.
106128# ----------------------------------------
107129
108130USER ${STACKABLE_USER_UID}
0 commit comments