Skip to content

Commit 2685913

Browse files
authored
Use check permissions script and consolidation (#1054)
* consolidate docker image with fix image size PRs * adapted changelog * fix comment * fix intendation * improve check permissions script performance (@Siggi)
1 parent a894f24 commit 2685913

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
66

77
### Added
88

9+
- airflow: check for correct permissions and ownerships in /stackable folder via
10+
`check-permissions-ownership.sh` provided in stackable-base image ([#1054]).
911
- hadoop: check for correct permissions and ownerships in /stackable folder via
1012
`check-permissions-ownership.sh` provided in stackable-base image ([#1029]).
1113
- hbase: check for correct permissions and ownerships in /stackable folder via
@@ -46,6 +48,7 @@ All notable changes to this project will be documented in this file.
4648
[#1042]: https://github.com/stackabletech/docker-images/pull/1042
4749
[#1044]: https://github.com/stackabletech/docker-images/pull/1044
4850
[#1050]: https://github.com/stackabletech/docker-images/pull/1050
51+
[#1054]: https://github.com/stackabletech/docker-images/pull/1054
4952

5053
## [25.3.0] - 2025-03-21
5154

airflow/Dockerfile

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ARG PRODUCT
2828
ARG STATSD_EXPORTER
2929
ARG PYTHON
3030
ARG TARGETARCH
31+
ARG STACKABLE_USER_UID
3132

3233
COPY airflow/constraints-${PRODUCT}-python${PYTHON}.txt /tmp/constraints.txt
3334
COPY --from=opa-auth-manager-builder /tmp/opa-auth-manager/dist/opa_auth_manager-0.1.0-py3-none-any.whl /tmp/
@@ -85,9 +86,17 @@ else
8586
end)' /tmp/sbom.json > /stackable/app/airflow-${PRODUCT}.cdx.json
8687
EOF
8788

88-
WORKDIR /stackable
8989
COPY --from=statsd_exporter-builder /statsd_exporter/statsd_exporter /stackable/statsd_exporter
9090
COPY --from=statsd_exporter-builder /statsd_exporter/statsd_exporter-${STATSD_EXPORTER}.cdx.json /stackable/statsd_exporter-${STATSD_EXPORTER}.cdx.json
91+
COPY --from=gitsync-image --chown=${STACKABLE_USER_UID}:0 /git-sync /stackable/git-sync
92+
93+
RUN <<EOF
94+
mkdir -pv /stackable/airflow
95+
mkdir -pv /stackable/airflow/dags
96+
mkdir -pv /stackable/airflow/logs
97+
chmod --recursive g=u /stackable
98+
EOF
99+
91100

92101
FROM stackable/image/vector AS airflow-main-image
93102

@@ -99,22 +108,26 @@ ARG TARGETARCH
99108
ARG STACKABLE_USER_UID
100109

101110
LABEL name="Apache Airflow" \
102-
maintainer="[email protected]" \
103-
vendor="Stackable GmbH" \
104-
version="${PRODUCT}" \
105-
release="${RELEASE}" \
106-
summary="The Stackable image for Apache Airflow." \
107-
description="This image is deployed by the Stackable Operator for Apache Airflow."
108-
109-
COPY airflow/licenses /licenses
110-
COPY --chown=${STACKABLE_USER_UID}:0 airflow/stackable/utils/entrypoint.sh /entrypoint.sh
111-
COPY --chown=${STACKABLE_USER_UID}:0 airflow/stackable/utils/run-airflow.sh /run-airflow.sh
111+
maintainer="[email protected]" \
112+
vendor="Stackable GmbH" \
113+
version="${PRODUCT}" \
114+
release="${RELEASE}" \
115+
summary="The Stackable image for Apache Airflow." \
116+
description="This image is deployed by the Stackable Operator for Apache Airflow."
112117

113118
ENV HOME=/stackable
114119
ENV AIRFLOW_USER_HOME_DIR=/stackable
115120
ENV PATH=$PATH:/bin:$HOME/app/bin
116121
ENV AIRFLOW_HOME=$HOME/airflow
117122

123+
COPY --from=airflow-build-image --chown=${STACKABLE_USER_UID}:0 /stackable/ ${HOME}/
124+
COPY --from=airflow-build-image --chown=${STACKABLE_USER_UID}:0 /stackable/git-sync ${HOME}/git-sync
125+
126+
COPY --chown=${STACKABLE_USER_UID}:0 airflow/stackable/utils/entrypoint.sh /entrypoint.sh
127+
COPY --chown=${STACKABLE_USER_UID}:0 airflow/stackable/utils/run-airflow.sh /run-airflow.sh
128+
129+
COPY airflow/licenses /licenses
130+
118131
# Update image and install needed packages
119132
RUN <<EOF
120133
microdnf update
@@ -142,33 +155,33 @@ rm -rf /var/cache/yum
142155
# Get the correct `tini` binary for our architecture.
143156
# It is used as an init alternative in the entrypoint
144157
curl -o /usr/bin/tini "https://repo.stackable.tech/repository/packages/tini/tini-${TINI}-${TARGETARCH}"
158+
159+
# fix missing permissions
145160
chmod a+x /entrypoint.sh
146161
chmod a+x /run-airflow.sh
147162
chmod +x /usr/bin/tini
163+
EOF
148164

149-
mkdir -pv ${AIRFLOW_HOME}
150-
mkdir -pv ${AIRFLOW_HOME}/dags
151-
mkdir -pv ${AIRFLOW_HOME}/logs
165+
# ----------------------------------------
166+
# Checks
167+
# This section is to run final checks to ensure the created final images
168+
# adhere to several minimal requirements like:
169+
# - check file permissions and ownerships
170+
# ----------------------------------------
152171

153-
# All files and folders owned by root to support running as arbitrary users
154-
# This is best practice as all container users will belong to the root group (0)
155-
chown -R ${STACKABLE_USER_UID}:0 /stackable
156-
chmod -R g=u /stackable
172+
# Check that permissions and ownership in ${HOME} are set correctly
173+
# This will fail and stop the build if any mismatches are found.
174+
RUN <<EOF
175+
/bin/check-permissions-ownership.sh ${HOME} ${STACKABLE_USER_UID} 0
157176
EOF
158177

159178
# ----------------------------------------
160-
# Attention: We are changing the group of all files in /stackable directly above
161-
# If you do any file based actions (copying / creating etc.) below this comment you
162-
# absolutely need to make sure that the correct permissions are applied!
163-
# chown ${STACKABLE_USER_UID}:0
179+
# Attention: Do not perform any file based actions (copying/creating etc.) below this comment because the permissions would not be checked.
164180
# ----------------------------------------
165181

166182
USER ${STACKABLE_USER_UID}
167183
WORKDIR /stackable
168184

169-
COPY --from=airflow-build-image --chown=${STACKABLE_USER_UID}:0 /stackable/ ${HOME}/
170-
COPY --from=gitsync-image --chown=${STACKABLE_USER_UID}:0 /git-sync /stackable/git-sync
171-
172185
ENTRYPOINT ["/usr/bin/tini", "--", "/run-airflow.sh"]
173186
CMD []
174187

shared/checks/check-permissions-ownership.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,29 @@ EXPECTED_GID=$3
2929
error_flag=0
3030

3131
# Check ownership
32-
while IFS= read -r -d '' file; do
33-
uid=$(stat -c "%u" "$file")
34-
gid=$(stat -c "%g" "$file")
32+
while IFS= read -r -d '' entry; do
33+
uid=${entry%% *}
34+
remainder=${entry#* }
35+
gid=${remainder%% *}
3536

3637
if [[ "$uid" -ne "$EXPECTED_UID" || "$gid" -ne "$EXPECTED_GID" ]]; then
38+
file=${remainder#* }
3739
echo "Ownership mismatch: $file (Expected: $EXPECTED_UID:$EXPECTED_GID, Found: $uid:$gid)"
3840
error_flag=1
3941
fi
40-
done < <(find "$DIRECTORY" -print0)
42+
done < <(find "$DIRECTORY" -printf "%U %G %p\0")
4143

4244
# Check permissions
43-
while IFS= read -r -d '' file; do
44-
perms=$(stat -c "%A" "$file")
45-
owner_perms="${perms:1:3}"
46-
group_perms="${perms:4:3}"
45+
while IFS= read -r -d '' entry; do
46+
owner_perms="${entry:1:3}"
47+
group_perms="${entry:4:3}"
4748

4849
if [[ "$owner_perms" != "$group_perms" ]]; then
50+
file="${entry:11}"
4951
echo "Permission mismatch: $file (Owner: $owner_perms, Group: $group_perms)"
5052
error_flag=1
5153
fi
52-
done < <(find "$DIRECTORY" -print0)
54+
done < <(find "$DIRECTORY" -printf "%M %p\0")
5355

5456
if [[ $error_flag -ne 0 ]]; then
5557
echo "Permission and Ownership checks failed for $DIRECTORY!"

0 commit comments

Comments
 (0)