@@ -5,6 +5,7 @@ FROM stackable/image/java-devel AS nifi-builder
55
66ARG  PRODUCT
77ARG  MAVEN_VERSION="3.9.8" 
8+ ARG  STACKABLE_USER_UID
89
910RUN  microdnf update && \
1011    microdnf clean all && \
@@ -22,10 +23,10 @@ RUN if [[ "${PRODUCT}" == 2.* ]] ; then \
2223        ln -sf /tmp/apache-maven-${MAVEN_VERSION}/bin/mvn /usr/bin/mvn ; \
2324    fi
2425
25- USER  stackable 
26+ USER  ${STACKABLE_USER_UID} 
2627WORKDIR  /stackable
2728
28- COPY  --chown=stackable:stackable  nifi/stackable/patches /stackable/patches
29+ COPY  --chown=${STACKABLE_USER_UID}:0  nifi/stackable/patches /stackable/patches
2930
3031#  NOTE: NiFi 1.21.0 source build does not work with the current arm64 git runners due to java heap issues:
3132# 
@@ -82,28 +83,11 @@ RUN if [[ "${PRODUCT}" == "1.21.0" ]] ; then \
8283        rm -rf /stackable/nifi-${PRODUCT}/docs ; \
8384    fi
8485
85- #  ===
86- #  For earlier versions this script removes the .class file that contains the
87- #  vulnerable code.
88- #  TODO: This can be restricted to target only versions which do not honor the environment
89- #    varible that has been set above but this has not currently been implemented
90- COPY  shared/log4shell.sh /bin
91- RUN  /bin/log4shell.sh /stackable/nifi-${PRODUCT}
92- 
93- #  Ensure no vulnerable files are left over
94- #  This will currently report vulnerable files being present, as it also alerts on
95- #  SocketNode.class, which we do not remove with our scripts.
96- #  Further investigation will be needed whether this should also be removed.
97- COPY  shared/log4shell_1.6.1-log4shell_Linux_x86_64 /bin/log4shell_scanner_x86_64
98- COPY  shared/log4shell_1.6.1-log4shell_Linux_aarch64 /bin/log4shell_scanner_aarch64
99- COPY  shared/log4shell_scanner /bin/log4shell_scanner
100- RUN  /bin/log4shell_scanner s /stackable/nifi-${PRODUCT}
101- #  ===
102- 
10386FROM  stackable/image/java-base AS final
10487
10588ARG  PRODUCT
10689ARG  RELEASE
90+ ARG  STACKABLE_USER_UID
10791
10892LABEL  name="Apache NiFi"  \
10993@@ -113,28 +97,39 @@ LABEL name="Apache NiFi" \
11397      summary="The Stackable image for Apache NiFi."  \
11498      description="This image is deployed by the Stackable Operator for Apache NiFi." 
11599
116- RUN  microdnf update && \
117-     microdnf install \
118-     #  Required to install nipyapi
119-     python-pip && \
120-     microdnf clean all && \
121-     rm -rf /var/cache/yum && \
122-     #  The nipyapi is required for the ReportingTaskJob
123-     pip install --no-cache-dir nipyapi==0.19.1 && \
124-     #  For backwards compatibility we create a softlink in /bin where the jar used to be as long as we are root
125-     #  This can be removed once older versions / operators using this are no longer supported
126-     ln -s /stackable/stackable-bcrypt.jar /bin/stackable-bcrypt.jar
100+ COPY  --chown=${STACKABLE_USER_UID}:0 --from=nifi-builder /stackable/nifi-${PRODUCT} /stackable/nifi-${PRODUCT}/
101+ COPY  --chown=${STACKABLE_USER_UID}:0 --from=nifi-builder /stackable/stackable-bcrypt.jar /stackable/stackable-bcrypt.jar
102+ 
103+ COPY  --chown=${STACKABLE_USER_UID}:0 nifi/stackable/bin /stackable/bin
104+ COPY  --chown=${STACKABLE_USER_UID}:0 nifi/licenses /licenses
105+ COPY  --chown=${STACKABLE_USER_UID}:0 nifi/python /stackable/python
106+ 
107+ RUN  <<EOF
108+ ln -s /stackable/nifi-${PRODUCT} /stackable/nifi
109+ 
110+ microdnf update
111+ 
112+ #  python-pip: Required to install nipyapi
113+ microdnf install \
114+   python-pip
115+ 
116+ microdnf clean all
117+ rm -rf /var/cache/yum
127118
128- USER  stackable
119+ #  The nipyapi is required for the ReportingTaskJob
120+ pip install --no-cache-dir nipyapi==0.19.1 && \
129121
130- COPY  --chown=stackable:stackable --from=nifi-builder /stackable/nifi-${PRODUCT} /stackable/nifi-${PRODUCT}/
131- COPY  --chown=stackable:stackable --from=nifi-builder /stackable/stackable-bcrypt.jar /stackable/stackable-bcrypt.jar
122+ #  For backwards compatibility we create a softlink in /bin where the jar used to be as long as we are root
123+ #  This can be removed once older versions / operators using this are no longer supported
124+ ln -s /stackable/stackable-bcrypt.jar /bin/stackable-bcrypt.jar
132125
133- COPY  --chown=stackable:stackable nifi/stackable/bin /stackable/bin
134- COPY  --chown=stackable:stackable nifi/licenses /licenses
135- COPY  --chown=stackable:stackable nifi/python /stackable/python
126+ #  All files and folders owned by root to support running as arbitrary users
127+ #  This is best practice as all container users will belong to the root group (0)
128+ chown -R ${STACKABLE_USER_UID}:0 /stackable
129+ chmod -R g=u /stackable
130+ EOF
136131
137- RUN  ln -s /stackable/nifi-${PRODUCT} /stackable/nifi 
132+ USER  ${STACKABLE_USER_UID} 
138133
139134ENV  HOME=/stackable
140135ENV  NIFI_HOME=/stackable/nifi
0 commit comments