From 43746e2106f5dead9f5c029676cdab19e265f9b2 Mon Sep 17 00:00:00 2001 From: Sanskar Jaiswal Date: Wed, 19 Jan 2022 23:16:16 +0530 Subject: [PATCH] drop capabilities, enable seccomp and enforce runAsNonRoot Further restricts the SecurityContext that the controller runs under, by enabling the default seccomp profile and dropping all linux capabilities. This was set at container-level to ensure backwards compatibility with use cases in which sidecars are injected into the source-controller pod without setting less restrictive settings. Add a uid and gid for the container to enforce runAsNonRoot and ensure the use of non root users. BREAKING CHANGES: 1) The use of new seccomp API requires Kubernetes 1.19. 2) the controller container is now executed under 65534:65534 (userid:groupid). This change may break deployments that hard-coded the user name 'controller' in their PodSecurityPolicy. Signed-off-by: Sanskar Jaiswal Co-authored-by: Paulo Gomes --- Dockerfile | 4 +--- config/manager/deployment.yaml | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3ed682f1..4768a6e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,8 +45,6 @@ RUN apk add --no-cache ca-certificates tini COPY --from=builder /workspace/image-reflector-controller /usr/local/bin/ -RUN addgroup -S controller && adduser -S controller -G controller - -USER controller +USER 65534:65534 ENTRYPOINT [ "/sbin/tini", "--", "image-reflector-controller" ] diff --git a/config/manager/deployment.yaml b/config/manager/deployment.yaml index 7264a07e..dae55623 100644 --- a/config/manager/deployment.yaml +++ b/config/manager/deployment.yaml @@ -29,6 +29,11 @@ spec: securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true + runAsNonRoot: true + capabilities: + drop: [ "ALL" ] + seccompProfile: + type: RuntimeDefault ports: - containerPort: 8080 name: http-prom