Skip to content

Commit

Permalink
start kruise-manager as a non-root user (#1491)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg authored Jan 24, 2024
1 parent 19854e8 commit 9913b92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
24 changes: 21 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@ ARG BASE_IMAGE
ARG BASE_IMAGE_VERSION
FROM ${BASE_IMAGE}:${BASE_IMAGE_VERSION}

RUN apk add --no-cache ca-certificates bash expat \
&& rm -rf /var/cache/apk/*

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/daemon ./kruise-daemon

RUN set -eux; \
mkdir -p /log /tmp && \
chown -R nobody:nobody /log && \
chown -R nobody:nobody /tmp && \
chown -R nobody:nobody /manager && \
apk --no-cache --update upgrade && \
apk --no-cache add ca-certificates && \
apk --no-cache add tzdata && \
rm -rf /var/cache/apk/* && \
update-ca-certificates && \
echo "only include root and nobody user" && \
echo -e "root:x:0:0:root:/root:/bin/ash\nnobody:x:65534:65534:nobody:/:/sbin/nologin" | tee /etc/passwd && \
echo -e "root:x:0:root\nnobody:x:65534:" | tee /etc/group && \
rm -rf /usr/local/sbin/* && \
rm -rf /usr/local/bin/* && \
rm -rf /usr/sbin/* && \
rm -rf /usr/bin/* && \
rm -rf /sbin/* && \
rm -rf /bin/*

ENTRYPOINT ["/manager"]
11 changes: 8 additions & 3 deletions Dockerfile_multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ ARG BASE_IMAGE
ARG BASE_IMAGE_VERSION
FROM ${BASE_IMAGE}:${BASE_IMAGE_VERSION}

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/daemon ./kruise-daemon

RUN set -eux; \
mkdir -p /log /tmp && \
chown -R nobody:nobody /log && \
chown -R nobody:nobody /tmp && \
chown -R nobody:nobody /manager && \
apk --no-cache --update upgrade && \
apk --no-cache add ca-certificates && \
apk --no-cache add tzdata && \
Expand All @@ -42,7 +50,4 @@ RUN set -eux; \
rm -rf /sbin/* && \
rm -rf /bin/*

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/daemon ./kruise-daemon
ENTRYPOINT ["/manager"]
14 changes: 14 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ spec:
- --feature-gates=AllAlpha=true
image: controller:latest
imagePullPolicy: Always
securityContext:
capabilities:
drop:
- all
add: [ 'NET_BIND_SERVICE' ]
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 65534
name: manager
env:
- name: KUBE_CACHE_MUTATION_DETECTOR
Expand Down Expand Up @@ -97,6 +105,12 @@ spec:
- --feature-gates=AllAlpha=true
image: controller:latest
imagePullPolicy: Always
securityContext:
capabilities:
drop:
- all
add: [ 'NET_BIND_SERVICE' ]
allowPrivilegeEscalation: false
name: daemon
env:
- name: KUBE_CACHE_MUTATION_DETECTOR
Expand Down

0 comments on commit 9913b92

Please sign in to comment.