Skip to content

Commit 116007f

Browse files
authored
Merge pull request #1037 from xiaojiey/release-1.8-fix-user
CMP-3563: Modernize user setup
2 parents d491d09 + 41bcbc3 commit 116007f

File tree

7 files changed

+16
-41
lines changed

7 files changed

+16
-41
lines changed

.tekton/compliance-operator-release-1-8-pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
build.appstudio.redhat.com/target_branch: '{{target_branch}}'
99
pipelinesascode.tekton.dev/cancel-in-progress: "true"
1010
pipelinesascode.tekton.dev/max-keep-runs: "3"
11-
pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch == "release-1.8" && ( ".tekton/compliance-operator-release-1-8-*.yaml".pathChanged() || "images/operator/***".pathChanged() || "main.go".pathChanged() || "tools.go".pathChanged() || "pkg/**/*.go".pathChanged() || "cmd/**/*.go".pathChanged() || "version/***".pathChanged() || "config/***".pathChanged() || "*Makefile*".pathChanged() || "vendor/***".pathChanged() || "tests/***".pathChanged() || "LICENSE".pathChanged() )
11+
pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch == "release-1.8" && ( ".tekton/compliance-operator-release-1-8-*.yaml".pathChanged() || "images/operator/***".pathChanged() || "main.go".pathChanged() || "tools.go".pathChanged() || "images/operator/Dockerfile".pathChanged() || "build/bin/*".pathChanged() || "pkg/**/*.go".pathChanged() || "cmd/**/*.go".pathChanged() || "version/***".pathChanged() || "config/***".pathChanged() || "*Makefile*".pathChanged() || "vendor/***".pathChanged() || "tests/***".pathChanged() || "LICENSE".pathChanged() )
1212
creationTimestamp:
1313
labels:
1414
appstudio.openshift.io/application: compliance-operator-release-1-8

.tekton/compliance-operator-release-1-8-push.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
build.appstudio.redhat.com/target_branch: '{{target_branch}}'
99
pipelinesascode.tekton.dev/cancel-in-progress: "false"
1010
pipelinesascode.tekton.dev/max-keep-runs: "3"
11-
pipelinesascode.tekton.dev/on-cel-expression: event == "push" && target_branch == "release-1.8" && ( ".tekton/compliance-operator-release-1-8-*.yaml".pathChanged() || "images/operator/***".pathChanged() || "main.go".pathChanged() || "tools.go".pathChanged() || "pkg/**/*.go".pathChanged() || "cmd/**/*.go".pathChanged() || "version/***".pathChanged() || "config/***".pathChanged() || "*Makefile*".pathChanged() || "vendor/***".pathChanged() || "tests/***".pathChanged() || "LICENSE".pathChanged() )
11+
pipelinesascode.tekton.dev/on-cel-expression: event == "push" && target_branch == "release-1.8" && ( ".tekton/compliance-operator-release-1-8-*.yaml".pathChanged() || "images/operator/***".pathChanged() || "main.go".pathChanged() || "tools.go".pathChanged() || "images/operator/Dockerfile".pathChanged() || "build/bin/*".pathChanged() || "pkg/**/*.go".pathChanged() || "cmd/**/*.go".pathChanged() || "version/***".pathChanged() || "config/***".pathChanged() || "*Makefile*".pathChanged() || "vendor/***".pathChanged() || "tests/***".pathChanged() || "LICENSE".pathChanged() )
1212
creationTimestamp:
1313
labels:
1414
appstudio.openshift.io/application: compliance-operator-release-1-8

Dockerfile.ci

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ RUN make manager
1212
# Step two: containerize compliance-operator
1313
FROM registry.access.redhat.com/ubi9/ubi-micro:latest
1414

15-
ENV OPERATOR=/usr/local/bin/compliance-operator \
16-
USER_UID=1001 \
17-
USER_NAME=compliance-operator
15+
ENV OPERATOR=/usr/local/bin/compliance-operator
1816

1917
# install operator binary
2018
COPY --from=builder /go/src/github.com/openshift/compliance-operator/build/_output/bin/compliance-operator ${OPERATOR}
2119

22-
COPY build/bin /usr/local/bin
23-
RUN /usr/local/bin/user_setup
20+
COPY build/bin/entrypoint /usr/local/bin/entrypoint
2421

2522
ENTRYPOINT ["/usr/local/bin/entrypoint"]
2623

27-
USER ${USER_UID}
24+
USER 1001

build/Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ RUN make manager
1111
# Step two: containerize compliance-operator
1212
FROM registry.access.redhat.com/ubi9/ubi-micro:latest
1313

14-
ENV OPERATOR=/usr/local/bin/compliance-operator \
15-
USER_UID=1001 \
16-
USER_NAME=compliance-operator
14+
ENV OPERATOR=/usr/local/bin/compliance-operator
1715

1816
# install operator binary
1917
COPY --from=builder /go/src/github.com/openshift/compliance-operator/build/_output/bin/compliance-operator ${OPERATOR}
2018

21-
COPY build/bin /usr/local/bin
22-
RUN /usr/local/bin/user_setup
19+
COPY build/bin/entrypoint /usr/local/bin/entrypoint
2320

2421
ENTRYPOINT ["/usr/local/bin/entrypoint"]
2522

26-
USER ${USER_UID}
23+
USER 1001

build/bin/entrypoint

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/bin/sh -e
22

33
# This is documented here:
4-
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines
4+
# https://docs.redhat.com/en/documentation/openshift_container_platform/latest/html/images/creating-images#use-uid_create-images
55

6-
if ! whoami &>/dev/null; then
7-
if [ -w /etc/passwd ]; then
8-
echo "${USER_NAME:-compliance-operator}:x:$(id -u):$(id -g):${USER_NAME:-compliance-operator} user:${HOME}:/sbin/nologin" >> /etc/passwd
9-
fi
10-
fi
6+
# Since version 4.1 OCP supports arbitrary UIDs without requiring /etc/passwd entries
7+
# https://docs.redhat.com/en/documentation/openshift_container_platform/4.1/html/images/creating_images
8+
# The container runs with the UID assigned by the platform, with group 0 (root) membership
9+
# File permissions are managed through group ownership, not username lookups
1110

1211
exec ${OPERATOR} $@

build/bin/user_setup

Lines changed: 0 additions & 13 deletions
This file was deleted.

images/operator/Dockerfile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,14 @@ LABEL \
3131

3232
WORKDIR /
3333

34-
# Needed by the user_setup and entrypoint scripts
35-
ENV OPERATOR_BIN=/usr/local/bin/compliance-operator \
36-
USER_NAME=compliance-operator \
37-
USER_UID=1001
34+
ENV OPERATOR_BIN=/usr/local/bin/compliance-operator
3835

3936
COPY --from=builder /go/src/github.com/ComplianceAsCode/compliance-operator/LICENSE /licenses/LICENSE
4037
COPY --from=builder /go/src/github.com/ComplianceAsCode/compliance-operator/build/_output/bin/compliance-operator ${OPERATOR_BIN}
41-
COPY --from=builder /go/src/github.com/ComplianceAsCode/compliance-operator/build/bin/* /usr/local/bin
38+
COPY --from=builder /go/src/github.com/ComplianceAsCode/compliance-operator/build/bin/entrypoint /usr/local/bin/entrypoint
4239
# This is required for the bundle build.
4340
COPY --from=builder /go/src/github.com/ComplianceAsCode/compliance-operator/bundle /bundle
4441

45-
RUN /usr/local/bin/user_setup
46-
4742
ENTRYPOINT ["/usr/local/bin/entrypoint"]
4843

49-
USER ${USER_UID}
44+
USER 1001

0 commit comments

Comments
 (0)