Skip to content

Commit 7af89cb

Browse files
Setup user on docker image to run it as no root by using gcr.io/distroless/static:nonroot and the targetPort 9843 for webhoocks
1 parent 76963b3 commit 7af89cb

File tree

7 files changed

+9
-5
lines changed

7 files changed

+9
-5
lines changed

pkg/scaffold/v2/dockerfile.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager
5757
5858
# Use distroless as minimal base image to package the manager binary
5959
# Refer to https://github.com/GoogleContainerTools/distroless for more details
60-
FROM gcr.io/distroless/static:latest
60+
FROM gcr.io/distroless/static:nonroot
6161
WORKDIR /
6262
COPY --from=builder /workspace/manager .
63+
USER nonroot:nonroot
64+
6365
ENTRYPOINT ["/manager"]
6466
`

pkg/scaffold/v2/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func main() {
166166
Scheme: scheme,
167167
MetricsBindAddress: metricsAddr,
168168
LeaderElection: enableLeaderElection,
169+
Port: 9443,
169170
})
170171
if err != nil {
171172
setupLog.Error(err, "unable to start manager")

pkg/scaffold/v2/webhook/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ metadata:
4848
spec:
4949
ports:
5050
- port: 443
51-
targetPort: 443
51+
targetPort: 9443
5252
selector:
5353
control-plane: controller-manager
5454
`

pkg/scaffold/v2/webhook_manager_patch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ spec:
4747
containers:
4848
- name: manager
4949
ports:
50-
- containerPort: 443
50+
- containerPort: 9443
5151
name: webhook-server
5252
protocol: TCP
5353
volumeMounts:

testdata/project-v2/config/default/manager_webhook_patch.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
containers:
1010
- name: manager
1111
ports:
12-
- containerPort: 443
12+
- containerPort: 9443
1313
name: webhook-server
1414
protocol: TCP
1515
volumeMounts:

testdata/project-v2/config/webhook/service.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ metadata:
77
spec:
88
ports:
99
- port: 443
10-
targetPort: 443
10+
targetPort: 9443
1111
selector:
1212
control-plane: controller-manager

testdata/project-v2/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func main() {
5858
Scheme: scheme,
5959
MetricsBindAddress: metricsAddr,
6060
LeaderElection: enableLeaderElection,
61+
Port: 9843,
6162
})
6263
if err != nil {
6364
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)