Skip to content

Commit e7e3283

Browse files
committed
Make uid/gid configurable & change group of files
This is a follow-up for #849 and includes: - The missing bits for Hive - Kafka
1 parent be5f7b5 commit e7e3283

File tree

2 files changed

+56
-57
lines changed

2 files changed

+56
-57
lines changed

hive/Dockerfile

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,47 @@ LABEL io.openshift.tags="ubi9,stackable,hive,sdp"
103103
LABEL io.k8s.description="${DESCRIPTION}"
104104
LABEL io.k8s.display-name="${NAME}"
105105

106-
RUN <<EOF
107-
microdnf update
108-
microdnf clean all
109-
rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n" | sort > /stackable/package_manifest.txt
110-
rm -rf /var/cache/yum
111-
EOF
112-
113-
USER ${STACKABLE_USER_UID}
114106
WORKDIR /stackable
115107

116108
COPY --chown=${STACKABLE_USER_UID}:0 --from=hive-builder /stackable/apache-hive-metastore-${PRODUCT}-bin /stackable/apache-hive-metastore-${PRODUCT}-bin
117-
RUN ln -s /stackable/apache-hive-metastore-${PRODUCT}-bin /stackable/hive-metastore
118109

119110
# It is useful to see which version of Hadoop is used at a glance
120111
# Therefore the use of the full name here
121112
# TODO: Do we really need all of Hadoop in here?
122113
COPY --chown=${STACKABLE_USER_UID}:0 --from=hadoop-builder /stackable/hadoop /stackable/hadoop-${HADOOP}
123-
RUN ln -s /stackable/hadoop-${HADOOP} /stackable/hadoop
114+
115+
RUN <<EOF
116+
microdnf update
117+
microdnf clean all
118+
rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n" | sort > /stackable/package_manifest.txt
119+
rm -rf /var/cache/yum
120+
121+
ln -s /stackable/apache-hive-metastore-${PRODUCT}-bin /stackable/hive-metastore
122+
ln -s /stackable/hadoop-${HADOOP} /stackable/hadoop
124123

125124
# The next two sections for S3 and Azure use hardcoded version numbers on purpose instead of wildcards
126125
# This way the build will fail should one of the files not be available anymore in a later Hadoop version!
127126

128127
# Add S3 Support for Hive (support for s3a://)
129-
RUN cp /stackable/hadoop/share/hadoop/tools/lib/hadoop-aws-${HADOOP}.jar /stackable/hive-metastore/lib/
130-
RUN cp /stackable/hadoop/share/hadoop/tools/lib/aws-java-sdk-bundle-${AWS_JAVA_SDK_BUNDLE}.jar /stackable/hive-metastore/lib/
128+
cp /stackable/hadoop/share/hadoop/tools/lib/hadoop-aws-${HADOOP}.jar /stackable/hive-metastore/lib/
129+
cp /stackable/hadoop/share/hadoop/tools/lib/aws-java-sdk-bundle-${AWS_JAVA_SDK_BUNDLE}.jar /stackable/hive-metastore/lib/
131130

132131
# Add Azure ABFS support (support for abfs://)
133-
RUN cp /stackable/hadoop/share/hadoop/tools/lib/hadoop-azure-${HADOOP}.jar /stackable/hive-metastore/lib/
134-
RUN cp /stackable/hadoop/share/hadoop/tools/lib/azure-storage-${AZURE_STORAGE}.jar /stackable/hive-metastore/lib/
135-
RUN cp /stackable/hadoop/share/hadoop/tools/lib/azure-keyvault-core-${AZURE_KEYVAULT_CORE}.jar /stackable/hive-metastore/lib/
132+
cp /stackable/hadoop/share/hadoop/tools/lib/hadoop-azure-${HADOOP}.jar /stackable/hive-metastore/lib/
133+
cp /stackable/hadoop/share/hadoop/tools/lib/azure-storage-${AZURE_STORAGE}.jar /stackable/hive-metastore/lib/
134+
cp /stackable/hadoop/share/hadoop/tools/lib/azure-keyvault-core-${AZURE_KEYVAULT_CORE}.jar /stackable/hive-metastore/lib/
135+
136+
# All files and folders owned by root to support running as arbitrary users
137+
# This is best practice as all container users will belong to the root group (0)
138+
chown -R ${STACKABLE_USER_UID}:0 /stackable
139+
chmod -R g=u /stackable
140+
EOF
136141

137142
COPY --chown=${STACKABLE_USER_UID}:0 --from=hive-builder /stackable/jmx /stackable/jmx
138143
COPY hive/licenses /licenses
139144

145+
USER ${STACKABLE_USER_UID}
146+
140147
ENV HADOOP_HOME=/stackable/hadoop
141148
ENV HIVE_HOME=/stackable/hive-metastore
142149
ENV PATH="${PATH}":/stackable/hadoop/bin:/stackable/hive-metastore/bin

kafka/Dockerfile

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ ARG PRODUCT
99
ARG SCALA
1010
ARG OPA_AUTHORIZER
1111
ARG JMX_EXPORTER
12+
ARG STACKABLE_USER_UID
1213

13-
USER stackable
14+
USER ${STACKABLE_USER_UID}
1415
WORKDIR /stackable
1516

1617
RUN 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}
2728
RUN 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/
3132
RUN 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

5338
FROM stackable/image/java-base AS final
5439

5540
ARG RELEASE
5641
ARG PRODUCT
5742
ARG SCALA
5843
ARG KCAT
44+
ARG STACKABLE_USER_UID
5945

6046
LABEL name="Apache Kafka" \
6147
maintainer="info@stackable.tech" \
@@ -67,32 +53,38 @@ LABEL name="Apache Kafka" \
6753

6854
# This is needed for kubectl
6955
COPY 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 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

9789
ENV PATH="${PATH}:/stackable/bin:/stackable/kafka/bin"
9890

0 commit comments

Comments
 (0)