Skip to content

Commit 9c09737

Browse files
committed
Dockerfile updates
- Also uses OpenContainer annotations as in our product images - Switches to a different user id for security reasons
1 parent c128978 commit 9c09737

File tree

1 file changed

+71
-18
lines changed

1 file changed

+71
-18
lines changed

template/docker/Dockerfile.j2

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,78 @@ FROM registry.access.redhat.com/ubi9/ubi-minimal AS operator
99
ARG VERSION
1010
ARG RELEASE="1"
1111

12-
LABEL name="Stackable Operator for {[ operator.pretty_string }]" \
13-
maintainer="[email protected]" \
14-
vendor="Stackable GmbH" \
15-
version="${VERSION}" \
16-
release="${RELEASE}" \
17-
summary="Deploy and manage {[ operator.pretty_string }] clusters." \
18-
description="Deploy and manage {[ operator.pretty_string }] clusters."
12+
# These are chosen at random and are this high on purpose to have very little chance to clash with an existing user or group on the host system
13+
ARG STACKABLE_USER_GID="574654813"
14+
ARG STACKABLE_USER_UID="782252253"
15+
16+
# These labels have mostly been superseded by the OpenContainer spec annotations below but it doesn't hurt to include them
17+
# http://label-schema.org/rc1/
18+
LABEL name="Stackable Operator for {[ operator.pretty_string }]"
19+
LABEL maintainer="[email protected]"
20+
LABEL vendor="Stackable GmbH"
21+
LABEL version="${VERSION}"
22+
LABEL release="${RELEASE}"
23+
LABEL summary="Deploy and manage {[ operator.pretty_string }] clusters."
24+
LABEL description="Deploy and manage {[ operator.pretty_string }] clusters."
25+
26+
# Overwriting/Pinning UBI labels
27+
# https://github.com/projectatomic/ContainerApplicationGenericLabels
28+
LABEL vcs-ref=""
29+
LABEL distribution-scope="public"
30+
LABEL url="https://stackable.tech"
31+
ARG TARGETARCH
32+
LABEL architecture="${TARGETARCH}"
33+
LABEL com.redhat.component=""
34+
# It complains about it being an invalid label but RedHat uses it and we want to override it and it works....
35+
# hadolint ignore=DL3048
36+
LABEL com.redhat.license_terms=""
37+
LABEL io.buildah.version=""
38+
LABEL io.openshift.expose-services=""
39+
40+
# https://github.com/opencontainers/image-spec/blob/036563a4a268d7c08b51a08f05a02a0fe74c7268/annotations.md#annotations
41+
LABEL org.opencontainers.image.authors="[email protected]"
42+
LABEL org.opencontainers.image.url="https://stackable.tech"
43+
LABEL org.opencontainers.image.vendor="Stackable GmbH"
44+
LABEL org.opencontainers.image.licenses="OSL-3.0"
45+
LABEL org.opencontainers.image.documentation="https://docs.stackable.tech/home/stable/{{ operator.product_string }}/"
46+
LABEL org.opencontainers.image.version="${VERSION}"
47+
LABEL org.opencontainers.image.revision="${RELEASE}"
48+
LABEL org.opencontainers.image.title="Stackable Operator for {[ operator.pretty_string }]"
49+
LABEL org.opencontainers.image.description="Deploy and manage {[ operator.pretty_string }] clusters."
50+
51+
# https://docs.openshift.com/container-platform/4.16/openshift_images/create-images.html#defining-image-metadata
52+
# https://github.com/projectatomic/ContainerApplicationGenericLabels/blob/master/vendor/redhat/labels.md
53+
LABEL io.openshift.tags="ubi9,stackable,sdp,{{ operator.product_string }}"
54+
LABEL io.k8s.description="Deploy and manage {[ operator.pretty_string }] clusters."
55+
LABEL io.k8s.display-name="Stackable Operator for {[ operator.pretty_string }]"
1956

2057
# Update image and install kerberos client libraries
21-
# install_weak_deps in microdnf does not support the literal "False" as dnf does
22-
# https://github.com/rpm-software-management/microdnf/blob/a600c62f29262d71a6259b70dc220df65a2ab9b5/dnf/dnf-main.c#L176-L189
23-
RUN microdnf update -y --setopt=install_weak_deps=0 \
24-
&& microdnf install -y --setopt=install_weak_deps=0 \
25-
krb5-libs \
26-
libkadm5 \
27-
&& microdnf clean all \
28-
&& rm -rf /var/cache/yum
58+
RUN <<EOF
59+
microdnf update
60+
microdnf install -y \
61+
krb5-libs \
62+
libkadm5 \
63+
shadow-utils
64+
65+
groupadd --gid ${STACKABLE_USER_GID} --system ${STACKABLE_USER_NAME}
66+
# The --no-log-init is required to work around a bug/problem in Go/Docker when very large UIDs are used
67+
# See https://github.com/moby/moby/issues/5419#issuecomment-41478290 for more context
68+
# Making this a system user prevents a mail dir from being created, expiry of passwords etc. but it will warn:
69+
# useradd warning: stackable's uid 1000 is greater than SYS_UID_MAX 999
70+
# We can safely ignore this warning, to get rid of the warning we could change /etc/login.defs but that does not seem worth it
71+
# We'll leave the home directory hardcoded to /stackable because I don't want to deal with which chars might be valid and which might not in user name vs. directory
72+
useradd \
73+
--no-log-init \
74+
--gid ${STACKABLE_USER_GID} \
75+
--uid ${STACKABLE_USER_UID} \
76+
--system \
77+
--create-home \
78+
--home-dir /stackable \
79+
stackable
80+
microdnf remove shadow-utils
81+
microdnf clean all
82+
rm -rf /var/cache/yum
83+
EOF
2984
3085
COPY LICENSE /licenses/LICENSE
3186
@@ -34,9 +89,7 @@ COPY --from=builder /app/* /usr/local/bin/
3489
COPY deploy/config-spec/properties.yaml /etc/stackable/{[ operator.name }]/config-spec/properties.yaml
3590
{[% endif %}]
3691
37-
RUN groupadd -g 1000 stackable && adduser -u 1000 -g stackable -c 'Stackable Operator' stackable
38-
39-
USER stackable:stackable
92+
USER ${STACKABLE_USER_UID}
4093
4194
ENTRYPOINT ["stackable-{[ operator.name }]"]
4295
CMD ["run"]

0 commit comments

Comments
 (0)