@@ -6,18 +6,20 @@ FROM stackable/image/stackable-base AS opa-bundle-builder
66ARG BUNDLE_BUILDER_VERSION
77
88# Update image and install everything needed for Rustup & Rust
9- RUN microdnf update \
10- && microdnf install \
11- cmake \
12- gcc \
13- gcc-c++ \
14- git \
15- make \
16- openssl-devel \
17- pkg-config \
18- systemd-devel \
19- unzip \
20- && rm -rf /var/cache/yum
9+ RUN <<EOF
10+ microdnf update
11+ microdnf install \
12+ cmake \
13+ gcc \
14+ gcc-c++ \
15+ git \
16+ make \
17+ openssl-devel \
18+ pkg-config \
19+ systemd-devel \
20+ unzip
21+ rm -rf /var/cache/yum
22+ EOF
2123
2224WORKDIR /
2325
@@ -29,6 +31,8 @@ cd ./opa-bundle-builder
2931. "$HOME/.cargo/env"
3032rustup toolchain install
3133cargo --quiet build --release
34+ # set correct groups
35+ chmod -R g=u /opa-bundle-builder/target/release/
3236EOF
3337
3438FROM stackable/image/stackable-base AS multilog-builder
@@ -37,33 +41,38 @@ ARG DAEMONTOOLS_VERSION=0.76
3741
3842COPY opa/daemontools /daemontools
3943
40- RUN microdnf update && \
41- microdnf install \
42- gcc \
43- gzip \
44- make \
45- patch \
46- tar && \
47- microdnf clean all \
48- && rm -rf /var/cache/yum
49-
50- WORKDIR /daemontools
51-
52- RUN tar xzf daemontools-${DAEMONTOOLS_VERSION}.tar.gz
44+ RUN <<EOF
45+ microdnf update
46+ microdnf install \
47+ gcc \
48+ gzip \
49+ make \
50+ patch \
51+ tar
52+ microdnf clean all
53+ rm -rf /var/cache/yum
54+ EOF
5355
54- WORKDIR /daemontools/admin/daemontools-${DAEMONTOOLS_VERSION}/src
56+ RUN <<EOF
57+ cd /daemontools
58+ tar xzf daemontools-${DAEMONTOOLS_VERSION}.tar.gz
5559
56- RUN patch < /daemontools/conf-cc.patch && \
57- patch multilog.c < /daemontools/multilog_max_file_size.patch
60+ cd /daemontools/admin/daemontools-${DAEMONTOOLS_VERSION}/src
61+ patch < /daemontools/conf-cc.patch
62+ patch multilog.c < /daemontools/multilog_max_file_size.patch
5863
59- WORKDIR /daemontools/admin/daemontools-${DAEMONTOOLS_VERSION}
64+ cd /daemontools/admin/daemontools-${DAEMONTOOLS_VERSION}
65+ package/install
6066
61- RUN package/install
67+ # set correct groups
68+ chmod g=u /daemontools/admin/daemontools/command/multilog
69+ EOF
6270
6371FROM stackable/image/stackable-base AS opa-builder
6472
6573ARG PRODUCT
6674ARG RELEASE
75+ ARG STACKABLE_USER_UID
6776ARG TARGETARCH
6877ARG TARGETOS
6978
@@ -73,19 +82,25 @@ ENV GOOS=$TARGETOS
7382# gzip, tar - used to unpack the OPA source
7483# git - needed by the cyclonedx-gomod tool to determine the version of OPA
7584# golang - used to build OPA
76- RUN microdnf update && \
77- microdnf install \
78- git \
79- golang \
80- gzip \
81- tar && \
82- microdnf clean all
85+ RUN <<EOF
86+ microdnf update
87+ microdnf install \
88+ git \
89+ golang \
90+ gzip \
91+ tar
92+ microdnf clean all
93+ EOF
8394
95+ COPY --chown=${STACKABLE_USER_UID}:0 opa/stackable/bin /stackable/opa/bin
96+
97+ RUN <<EOF
8498# We use version 1.7.0, since a newer version of cyclonedx-gomod is not compatible with the version of Golang (>= 1.23.1)
85- RUN go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.7.0
86- RUN curl "https://repo.stackable.tech/repository/packages/opa/opa_${PRODUCT}.tar.gz" -o opa.tar.gz && \
87- tar -zxvf opa.tar.gz && \
88- mv "opa-${PRODUCT}" opa
99+ go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.7.0
100+ curl "https://repo.stackable.tech/repository/packages/opa/opa_${PRODUCT}.tar.gz" -o opa.tar.gz
101+ tar -zxvf opa.tar.gz
102+ mv "opa-${PRODUCT}" opa
103+ EOF
89104
90105WORKDIR /opa
91106
@@ -97,7 +112,12 @@ git config user.name "Fake commiter"
97112git commit --allow-empty --message "Fake commit, so that we can create a tag"
98113git tag "v${PRODUCT}"
99114go build -o opa -buildmode=exe
100- ~/go/bin/cyclonedx-gomod app -json -output-version 1.5 -output "opa_${PRODUCT}.cdx.json" -packages -files
115+ # move artifact to /stackable/*/ to copy in final image
116+ ~/go/bin/cyclonedx-gomod app -json -output-version 1.5 -output /stackable/opa/"opa_${PRODUCT}.cdx.json" -packages -files
117+ # move artifact to /stackable/* to copy in final image
118+ mv /opa/opa /stackable/opa/
119+ # set correct groups
120+ chmod -R g=u /stackable/opa
101121EOF
102122
103123FROM stackable/image/vector
@@ -107,43 +127,46 @@ ARG RELEASE
107127ARG STACKABLE_USER_UID
108128
109129LABEL name="Open Policy Agent" \
110- maintainer="info@stackable.tech" \
111- vendor="Stackable GmbH" \
112- version="${PRODUCT}" \
113- release="${RELEASE}" \
114- summary="The Stackable image for Open Policy Agent (OPA)." \
115- description="This image is deployed by the Stackable Operator for OPA."
130+ maintainer="info@stackable.tech" \
131+ vendor="Stackable GmbH" \
132+ version="${PRODUCT}" \
133+ release="${RELEASE}" \
134+ summary="The Stackable image for Open Policy Agent (OPA)." \
135+ description="This image is deployed by the Stackable Operator for OPA."
116136
117- COPY opa/licenses /licenses
137+ COPY --chown=${STACKABLE_USER_UID}:0 opa/licenses /licenses
118138
119- COPY --from=opa-builder --chown=${STACKABLE_USER_UID}:0 /opa/opa /stackable/opa/opa
120- COPY --from=opa-builder --chown=${STACKABLE_USER_UID}:0 /opa/opa_${PRODUCT}.cdx.json /stackable/opa/
139+ COPY --from=opa-builder --chown=${STACKABLE_USER_UID}:0 /stackable/opa /stackable/opa
121140COPY --from=opa-bundle-builder --chown=${STACKABLE_USER_UID}:0 /opa-bundle-builder/target/release/stackable-opa-bundle-builder /stackable/opa-bundle-builder
122141COPY --from=multilog-builder --chown=${STACKABLE_USER_UID}:0 /daemontools/admin/daemontools/command/multilog /stackable/multilog
123142
124- COPY --chown=${STACKABLE_USER_UID}:0 opa/stackable/bin /stackable/opa/bin
125-
126143RUN <<EOF
127144microdnf update
128-
129145# jq: Required for filtering logs
130146microdnf install \
131147 jq
132148microdnf clean all
133149rm -rf /var/cache/yum
134150
135- # All files and folders owned by root group to support running as arbitrary users.
136- # This is best practice as all container users will belong to the root group (0).
137- chown -R ${STACKABLE_USER_UID}:0 /stackable
138- chmod -R g=u /stackable
151+ # fix missing permissions
152+ chmod g=u /stackable/opa
139153EOF
140154
141155# ----------------------------------------
142- # Attention: We are changing the group of all files in /stackable directly above
143- # If you do any file based actions (copying / creating etc.) below this comment you
144- # absolutely need to make sure that the correct permissions are applied!
145- # chown ${STACKABLE_USER_UID}:0
156+ # Checks
157+ # This section is to run final checks to ensure the created final images
158+ # adhere to several minimal requirements like:
159+ # - check file permissions and ownerships
160+ # ----------------------------------------
161+
162+ # Check that permissions and ownership in /stackable are set correctly
163+ # This will fail and stop the build if any mismatches are found.
164+ RUN <<EOF
165+ /bin/check-permissions-ownership.sh /stackable ${STACKABLE_USER_UID} 0
166+ EOF
167+
146168# ----------------------------------------
169+ # Attention: Do not perform any file based actions (copying/creating etc.) below this comment because the permissions would not be checked.
147170
148171USER ${STACKABLE_USER_UID}
149172WORKDIR /stackable/opa
0 commit comments