Skip to content

Commit 922f420

Browse files
committed
Adjust HBase
1 parent 42476b2 commit 922f420

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

hbase/Dockerfile

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ ARG JMX_EXPORTER
1414
ARG HADOOP
1515
ARG TARGETARCH
1616
ARG TARGETOS
17+
ARG STACKABLE_USER_UID
1718

1819
# Setting this to anything other than "true" will keep the cache folders around (e.g. for Maven, NPM etc.)
1920
# This can be used to speed up builds when disk space is of no concern.
2021
ARG DELETE_CACHES="true"
2122

2223
COPY hbase/licenses /licenses
2324

24-
USER stackable
25+
USER ${STACKABLE_USER_UID}
2526
WORKDIR /stackable
2627

27-
COPY --chown=stackable:stackable hbase/stackable/patches /stackable/patches
28-
COPY --chown=stackable:stackable hbase/stackable/jmx/config${JMX_EXPORTER} /stackable/jmx
28+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/patches /stackable/patches
29+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/jmx/config${JMX_EXPORTER} /stackable/jmx
2930

3031
# Cache mounts are owned by root by default
31-
# We need to explicitly give the uid to use which is hardcoded to "1000" in stackable-base
32+
# We need to explicitly give the uid to use
3233
# And every cache needs its own id, we can't share them between stages because we might delete the caches
3334
# at the end of a run while other stages are still using it.
3435
# While this might work in theory it didn't in practice (FileNotFound exceptions etc.)
@@ -38,7 +39,7 @@ COPY --chown=stackable:stackable hbase/stackable/jmx/config${JMX_EXPORTER} /stac
3839
# builder containers will share the same cache and the `rm -rf` commands will fail
3940
# with a "directory not empty" error on the first builder to finish, as other builders
4041
# are still working in the cache directory.
41-
RUN --mount=type=cache,id=maven-hbase-${PRODUCT},uid=1000,target=/stackable/.m2/repository <<EOF
42+
RUN --mount=type=cache,id=maven-hbase-${PRODUCT},uid=${STACKABLE_USER_UID},target=/stackable/.m2/repository <<EOF
4243
###
4344
### HBase
4445
###
@@ -91,11 +92,12 @@ FROM stackable/image/java-devel AS opa-authorizer-builder
9192

9293
ARG OPA_AUTHORIZER
9394
ARG DELETE_CACHES
95+
ARG STACKABLE_USER_UID
9496

95-
USER stackable
97+
USER ${STACKABLE_USER_UID}
9698
WORKDIR /stackable
9799

98-
RUN --mount=type=cache,id=maven-opa,uid=1000,target=/stackable/.m2/repository <<EOF
100+
RUN --mount=type=cache,id=maven-opa,uid=${STACKABLE_USER_UID},target=/stackable/.m2/repository <<EOF
99101

100102
###
101103
### OPA Authorizer (only for 2.6 upwards)
@@ -125,6 +127,7 @@ FROM stackable/image/java-devel AS hbase-operator-tools-builder
125127
ARG HBASE_OPERATOR_TOOLS
126128
ARG HBASE_THIRDPARTY
127129
ARG PRODUCT
130+
ARG STACKABLE_USER_UID
128131

129132
# Setting this to anything other than "true" will keep the cache folders around (e.g. for Maven, NPM etc.)
130133
# This can be used to speed up builds when disk space is of no concern.
@@ -134,15 +137,15 @@ ARG DELETE_CACHES="true"
134137
# The variable names are intentionally passed to envsubst in single-quotes,
135138
# so that they are not expanded. Disabling ShellCheck rules in a Dockerfile
136139
# does not work, so please ignore the according warning (SC2016).
137-
COPY --chown=stackable:stackable hbase/stackable/bin/hbck2.env /stackable/bin/
138-
COPY --chown=stackable:stackable hbase/stackable/patches /stackable/patches
140+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/bin/hbck2.env /stackable/bin/
141+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/patches /stackable/patches
139142

140-
USER stackable
143+
USER ${STACKABLE_USER_UID}
141144
WORKDIR /stackable
142145

143146
# Cache mounts are owned by root by default
144-
# We need to explicitly give the uid to use which is hardcoded to "1000" in stackable-base
145-
RUN --mount=type=cache,id=maven-hbase-operator-tools,uid=1000,target=/stackable/.m2/repository <<EOF
147+
# We need to explicitly give the uid to use
148+
RUN --mount=type=cache,id=maven-hbase-operator-tools,uid=${STACKABLE_USER_UID},target=/stackable/.m2/repository <<EOF
146149

147150
curl --fail -L "https://repo.stackable.tech/repository/packages/hbase-operator-tools/hbase-operator-tools-${HBASE_OPERATOR_TOOLS}-src.tar.gz" | tar -xzC .
148151
mv hbase-operator-tools-${HBASE_OPERATOR_TOOLS} hbase-operator-tools-${HBASE_OPERATOR_TOOLS}-src
@@ -190,16 +193,17 @@ FROM stackable/image/java-devel AS hadoop-s3-builder
190193

191194
ARG PRODUCT
192195
ARG HADOOP
196+
ARG STACKABLE_USER_UID
193197

194-
USER stackable
198+
USER ${STACKABLE_USER_UID}
195199
WORKDIR /stackable
196200

197-
COPY --from=hadoop-builder --chown=stackable:stackable \
201+
COPY --from=hadoop-builder --chown=${STACKABLE_USER_UID}:0 \
198202
/stackable/hadoop/share/hadoop/tools/lib/aws-java-sdk-bundle-*.jar \
199203
/stackable/hadoop/share/hadoop/tools/lib/hadoop-aws-${HADOOP}.jar \
200204
/stackable/hadoop/share/hadoop/tools/lib/
201205

202-
COPY --chown=stackable:stackable hbase/stackable/bin/export-snapshot-to-s3.env /stackable/bin/
206+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/bin/export-snapshot-to-s3.env /stackable/bin/
203207

204208
RUN <<EOF
205209
# Resolve paths in bin/export-snapshot-to-s3
@@ -220,16 +224,17 @@ ARG ASYNC_PROFILER
220224
ARG PHOENIX
221225
ARG HBASE_PROFILE
222226
ARG HADOOP
227+
ARG STACKABLE_USER_UID
223228

224229
# Setting this to anything other than "true" will keep the cache folders around (e.g. for Maven, NPM etc.)
225230
# This can be used to speed up builds when disk space is of no concern.
226231
ARG DELETE_CACHES="true"
227232

228-
COPY --chown=stackable:stackable hbase/stackable/patches /stackable/patches
229-
USER stackable
233+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/patches /stackable/patches
234+
USER ${STACKABLE_USER_UID}
230235
WORKDIR /stackable
231236

232-
RUN --mount=type=cache,id=maven-phoenix,uid=1000,target=/stackable/.m2/repository <<EOF
237+
RUN --mount=type=cache,id=maven-phoenix,uid=${STACKABLE_USER_UID},target=/stackable/.m2/repository <<EOF
233238
cd /stackable
234239
curl --fail -L "https://repo.stackable.tech/repository/packages/phoenix/phoenix-${PHOENIX}-src.tar.gz" | tar -xzC .
235240
mv phoenix-${PHOENIX} phoenix-${PHOENIX}-src
@@ -305,27 +310,27 @@ LABEL io.openshift.tags="ubi9,stackable,hbase,sdp,nosql"
305310
LABEL io.k8s.description="${DESCRIPTION}"
306311
LABEL io.k8s.display-name="${NAME}"
307312

308-
COPY --chown=stackable:stackable --from=hbase-builder /stackable/hbase-${PRODUCT} /stackable/hbase-${PRODUCT}/
309-
COPY --chown=stackable:stackable --from=hbase-builder /stackable/async-profiler /stackable/async-profiler/
310-
COPY --chown=stackable:stackable --from=hbase-builder /stackable/jmx /stackable/jmx/
313+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-builder /stackable/hbase-${PRODUCT} /stackable/hbase-${PRODUCT}/
314+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-builder /stackable/async-profiler /stackable/async-profiler/
315+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-builder /stackable/jmx /stackable/jmx/
311316

312-
COPY --chown=stackable:stackable --from=hbase-operator-tools-builder /stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS} /stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS}/
313-
COPY --chown=stackable:stackable --from=hbase-operator-tools-builder /stackable/bin/hbck2 /stackable/bin/hbck2
317+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS} /stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS}/
318+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/bin/hbck2 /stackable/bin/hbck2
314319

315-
COPY --chown=stackable:stackable --from=phoenix-builder /stackable/phoenix /stackable/phoenix/
320+
COPY --chown=${STACKABLE_USER_UID}:0 --from=phoenix-builder /stackable/phoenix /stackable/phoenix/
316321

317-
COPY --chown=stackable:stackable --from=hadoop-s3-builder /stackable/bin/export-snapshot-to-s3 /stackable/bin/export-snapshot-to-s3
318-
COPY --chown=stackable:stackable --from=hadoop-s3-builder /stackable/hadoop/share/hadoop/tools/lib/ /stackable/hadoop/share/hadoop/tools/lib/
322+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hadoop-s3-builder /stackable/bin/export-snapshot-to-s3 /stackable/bin/export-snapshot-to-s3
323+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hadoop-s3-builder /stackable/hadoop/share/hadoop/tools/lib/ /stackable/hadoop/share/hadoop/tools/lib/
319324

320325
# Copy the dependencies from Hadoop which are required for the Azure Data Lake
321326
# Storage (ADLS) to /stackable/hbase-${PRODUCT}/lib which is on the classpath.
322327
# hadoop-azure-${HADOOP}.jar contains the AzureBlobFileSystem which is required
323328
# by hadoop-common-${HADOOP}.jar if the scheme of a file system is "abfs://".
324-
COPY --chown=stackable:stackable --from=hadoop-builder \
329+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hadoop-builder \
325330
/stackable/hadoop/share/hadoop/tools/lib/hadoop-azure-${HADOOP}.jar \
326331
/stackable/hbase-${PRODUCT}/lib/
327332

328-
COPY --chown=stackable:stackable --from=opa-authorizer-builder /stackable/hbase-opa-authorizer/target/hbase-opa-authorizer*.jar /stackable/hbase-${PRODUCT}/lib
333+
COPY --chown=${STACKABLE_USER_UID}:0 --from=opa-authorizer-builder /stackable/hbase-opa-authorizer/target/hbase-opa-authorizer*.jar /stackable/hbase-${PRODUCT}/lib
329334

330335
RUN <<EOF
331336
microdnf update
@@ -346,9 +351,14 @@ rm -rf /var/cache/yum
346351
ln --symbolic --logical --verbose "/stackable/hbase-${PRODUCT}" /stackable/hbase
347352
ln --symbolic --logical --verbose "/stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS}" /stackable/hbase-operator-tools
348353
ln --symbolic --logical --verbose "/stackable/phoenix/phoenix-server-hbase-${HBASE_PROFILE}.jar" "/stackable/hbase/lib/phoenix-server-hbase-${HBASE_PROFILE}.jar"
354+
355+
# All files and folders owned by root to support running as arbitrary users
356+
# This is best practice as all container users will belong to the root group (0)
357+
chown -R ${STACKABLE_USER_UID}:0 /stackable
358+
chmod -R g=u /stackable
349359
EOF
350360

351-
USER stackable
361+
USER ${STACKABLE_USER_UID}
352362
ENV HBASE_CONF_DIR=/stackable/hbase/conf
353363
ENV HOME=/stackable
354364
ENV PATH="${PATH}:/stackable/bin:/stackable/hbase/bin"

0 commit comments

Comments
 (0)