Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(k8s): add read-only root FS to sidecar #6681

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/plugins/runtime/k8s/webhooks/injector/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/kumahq/kuma/pkg/plugins/runtime/k8s/metadata"
k8s_util "github.com/kumahq/kuma/pkg/plugins/runtime/k8s/util"
tp_k8s "github.com/kumahq/kuma/pkg/transparentproxy/kubernetes"
"github.com/kumahq/kuma/pkg/util/pointer"
)

const (
Expand Down Expand Up @@ -106,6 +107,22 @@ func (i *KumaInjector) InjectKuma(ctx context.Context, pod *kube_core.Pod) error
if err != nil {
return err
}

sidecarTmp := kube_core.Volume{
Name: "kuma-sidecar-tmp",
VolumeSource: kube_core.VolumeSource{
EmptyDir: &kube_core.EmptyDirVolumeSource{},
},
}
pod.Spec.Volumes = append(pod.Spec.Volumes, sidecarTmp)

container.VolumeMounts = append(container.VolumeMounts, kube_core.VolumeMount{
Name: sidecarTmp.Name,
MountPath: "/tmp",
ReadOnly: false,
})
container.SecurityContext.ReadOnlyRootFilesystem = pointer.To(true)

patchedContainer, err := i.applyCustomPatches(logger, container, sidecarPatches)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -158,4 +161,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -166,4 +169,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: coredns-token-9gmrh
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- args:
- -conf
- /etc/coredns/Corefile
Expand Down Expand Up @@ -250,4 +253,6 @@ spec:
- name: coredns-token-9gmrh
secret:
secretName: coredns-token-9gmrh
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -158,4 +161,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -147,4 +151,7 @@ spec:
- NET_RAW
runAsGroup: 0
runAsUser: 0
volumes:
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -159,4 +162,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -158,4 +161,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -161,4 +164,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -160,4 +163,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -159,4 +162,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -158,4 +161,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -158,4 +161,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
livenessProbe:
httpGet:
Expand Down Expand Up @@ -170,4 +173,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
livenessProbe:
httpGet:
Expand Down Expand Up @@ -170,4 +173,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
livenessProbe:
httpGet:
Expand Down Expand Up @@ -170,4 +173,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ spec:
cpu: 150m
memory: 164Mi
securityContext:
readOnlyRootFilesystem: true
runAsGroup: 5678
runAsUser: 5678
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-w7dxf
readOnly: true
- mountPath: /tmp
name: kuma-sidecar-tmp
- image: busybox
name: busybox
resources: {}
Expand Down Expand Up @@ -167,4 +170,6 @@ spec:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir: {}
name: kuma-sidecar-tmp
status: {}
Loading