Skip to content

Commit 0057599

Browse files
authored
Non root controller image (#262)
Description of changes: #### Before * OpenShift enforces `nonRoot` security posture by running container images using random UID and does not allow specifying `runAsUser` field in deployment spec. * Before this change, ACK generated artifacts enforced `nonRoot` security posture using `SecurityContext`'s `runAsUser` and `runAsNonRoot` field, while the container image ran as `root` by default ----- #### Now * With this change, ACK controller images now run by default with `non-root` User(1000) * Removed `runAsUser` field from deployment templates. This change keeps the existing functionality because K8s pod inherit UserId from Image metadata and ACK controller still runs with non-root user(1000) [Tested and Validated] > runAsUser: "The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. " - Official Documentation * Removing `runAsUser` unblock OpenShift installation and allows OpenShift to run container using random UserId * Keeping `runAsNonRoot` field, keeps the validation in place that ACK controller does not run as `root`. This validation helps security posture for both OpenShift and helm/kustomize installation. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b24c062 commit 0057599

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Base image to use for the final stage
22
ARG base_image=public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:2021-12-01-1638322424
33
# Build the manager binary
4+
# TODO(vijtrip2) move this builder image to public.ecr.aws/eks-distro-build-tooling/builder-base, when builder-base
5+
# supports golang 1.17
46
FROM public.ecr.aws/bitnami/golang:1.17.5 as builder
57

68
ARG service_alias
@@ -46,4 +48,6 @@ ARG service_alias
4648
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
4749
WORKDIR /
4850
COPY --from=builder $work_dir/bin/controller $work_dir/LICENSE $work_dir/ATTRIBUTION.md /bin/
51+
# Make this image non-root by default
52+
USER 1000
4953
ENTRYPOINT ["/bin/controller"]

Dockerfile.local

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Base image to use at runtime
22
ARG base_image=public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:2021-12-01-1638322424
33
# Build the manager binary
4+
# TODO(vijtrip2) move this builder image to public.ecr.aws/eks-distro-build-tooling/builder-base, when builder-base
5+
# supports golang 1.17
46
FROM public.ecr.aws/bitnami/golang:1.17.5 as builder
57

68
ARG service_alias
@@ -58,4 +60,5 @@ ARG service_alias
5860
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
5961
WORKDIR /
6062
COPY --from=builder $work_dir/bin/controller $work_dir/LICENSE $work_dir/ATTRIBUTION.md /bin/
63+
USER 1000
6164
ENTRYPOINT ["/bin/controller"]

templates/config/controller/deployment.yaml.tpl

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ spec:
5757
allowPrivilegeEscalation: false
5858
privileged: false
5959
runAsNonRoot: true
60-
runAsUser: 1000
6160
capabilities:
6261
drop:
6362
- ALL

templates/helm/templates/deployment.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ spec:
7777
allowPrivilegeEscalation: false
7878
privileged: false
7979
runAsNonRoot: true
80-
runAsUser: 1000
8180
capabilities:
8281
drop:
8382
- ALL

0 commit comments

Comments
 (0)