Skip to content

Commit

Permalink
feat(transparent-proxy): support readOnlyFileSystem and drop all capa…
Browse files Browse the repository at this point in the history
…bilities on kuma-init (#9688)


---------

Signed-off-by: Jay Chen <[email protected]>
  • Loading branch information
jijiechen authored Mar 26, 2024
1 parent eb56ab7 commit 5a09493
Show file tree
Hide file tree
Showing 81 changed files with 963 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/kumactl/cmd/install/install_transparent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func newInstallTransparentProxy() *cobra.Command {
StoreFirewalld: false,
SkipDNSConntrackZoneSplit: false,
EbpfEnabled: false,
EbpfProgramsSourcePath: "/kuma/ebpf",
EbpfProgramsSourcePath: "/tmp/kuma-ebpf",
EbpfBPFFSPath: "/sys/fs/bpf",
EbpfCgroupPath: "/sys/fs/cgroup",
EbpfTCAttachIface: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ experimental:
# -- Name of the network interface which TC programs should be attached to, we'll try to automatically determine it if empty
tcAttachIface: ""
# -- Path where compiled eBPF programs which will be installed can be found
programsSourcePath: /kuma/ebpf
programsSourcePath: /tmp/kuma-ebpf
# -- If false, it uses legacy API for resource synchronization
deltaKds: true
# -- If true, enable native Kubernetes sidecars. This requires at least
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ spec:
- name: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_INSTANCE_IP_ENV_VAR_NAME
value: "INSTANCE_IP"
- name: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_PROGRAMS_SOURCE_PATH
value: "/kuma/ebpf"
value: "/tmp/kuma-ebpf"
- name: KUMA_RUNTIME_KUBERNETES_INJECTOR_SIDECAR_CONTAINER_IMAGE
value: "docker.io/kumahq/kuma-dp:0.0.1"
- name: KUMA_RUNTIME_KUBERNETES_SERVICE_ACCOUNT_NAME
Expand Down
2 changes: 1 addition & 1 deletion deployments/charts/kuma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ A Helm chart for the Kuma Control Plane
| experimental.ebpf.bpffsPath | string | `"/sys/fs/bpf"` | Path where BPF file system should be mounted |
| experimental.ebpf.cgroupPath | string | `"/sys/fs/cgroup"` | Host's cgroup2 path |
| experimental.ebpf.tcAttachIface | string | `""` | Name of the network interface which TC programs should be attached to, we'll try to automatically determine it if empty |
| experimental.ebpf.programsSourcePath | string | `"/kuma/ebpf"` | Path where compiled eBPF programs which will be installed can be found |
| experimental.ebpf.programsSourcePath | string | `"/tmp/kuma-ebpf"` | Path where compiled eBPF programs which will be installed can be found |
| experimental.deltaKds | bool | `true` | If false, it uses legacy API for resource synchronization |
| experimental.sidecarContainers | bool | `false` | If true, enable native Kubernetes sidecars. This requires at least Kubernetes v1.29 |
| postgres.port | string | `"5432"` | Postgres port, password should be provided as a secret reference in "controlPlane.secrets" with the Env value "KUMA_STORE_POSTGRES_PASSWORD". Example: controlPlane: secrets: - Secret: postgres-postgresql Key: postgresql-password Env: KUMA_STORE_POSTGRES_PASSWORD |
Expand Down
2 changes: 1 addition & 1 deletion deployments/charts/kuma/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ experimental:
# -- Name of the network interface which TC programs should be attached to, we'll try to automatically determine it if empty
tcAttachIface: ""
# -- Path where compiled eBPF programs which will be installed can be found
programsSourcePath: /kuma/ebpf
programsSourcePath: /tmp/kuma-ebpf
# -- If false, it uses legacy API for resource synchronization
deltaKds: true
# -- If true, enable native Kubernetes sidecars. This requires at least
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/raw/helm-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ experimental:
# -- Name of the network interface which TC programs should be attached to, we'll try to automatically determine it if empty
tcAttachIface: ""
# -- Path where compiled eBPF programs which will be installed can be found
programsSourcePath: /kuma/ebpf
programsSourcePath: /tmp/kuma-ebpf
# -- If false, it uses legacy API for resource synchronization
deltaKds: true
# -- If true, enable native Kubernetes sidecars. This requires at least
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/raw/kuma-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ runtime:
# when not specified, we will try to automatically determine it
tcAttachIface: "" # ENV: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_TC_ATTACH_IFACE
# Path where compiled eBPF programs are placed
programsSourcePath: /kuma/ebpf # ENV: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_PROGRAMS_SOURCE_PATH
programsSourcePath: /tmp/kuma-ebpf # ENV: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_PROGRAMS_SOURCE_PATH
# IgnoredServiceSelectorLabels defines a list ignored labels in Service selector.
# If Pod matches a Service with ignored labels, but does not match it fully, it gets Ignored inbound.
# It is useful when you change Service selector and expect traffic to be sent immediately.
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ runtime:
# when not specified, we will try to automatically determine it
tcAttachIface: "" # ENV: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_TC_ATTACH_IFACE
# Path where compiled eBPF programs are placed
programsSourcePath: /kuma/ebpf # ENV: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_PROGRAMS_SOURCE_PATH
programsSourcePath: /tmp/kuma-ebpf # ENV: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_PROGRAMS_SOURCE_PATH
# IgnoredServiceSelectorLabels defines a list ignored labels in Service selector.
# If Pod matches a Service with ignored labels, but does not match it fully, it gets Ignored inbound.
# It is useful when you change Service selector and expect traffic to be sent immediately.
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/plugins/runtime/k8s/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func DefaultKubernetesRuntimeConfig() *KubernetesRuntimeConfig {
InstanceIPEnvVarName: "INSTANCE_IP",
BPFFSPath: "/sys/fs/bpf",
CgroupPath: "/sys/fs/cgroup",
ProgramsSourcePath: "/kuma/ebpf",
ProgramsSourcePath: "/tmp/kuma-ebpf",
},
IgnoredServiceSelectorLabels: []string{},
// topology labels that are useful for, for example, MeshLoadBalancingStrategy policy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ injector:
cgroupPath: /sys/fs/cgroup
enabled: false
instanceIPEnvVarName: INSTANCE_IP
programsSourcePath: /kuma/ebpf
programsSourcePath: /tmp/kuma-ebpf
exceptions:
labels:
openshift.io/build.name: '*'
Expand Down
33 changes: 28 additions & 5 deletions pkg/plugins/runtime/k8s/webhooks/injector/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ func (i *KumaInjector) InjectKuma(ctx context.Context, pod *kube_core.Pod) error
if err != nil {
return err
}
initTmp := kube_core.Volume{
Name: "kuma-init-tmp",
VolumeSource: kube_core.VolumeSource{
EmptyDir: &kube_core.EmptyDirVolumeSource{
SizeLimit: kube_api.NewScaledQuantity(10, kube_api.Mega),
},
},
}
sidecarTmp := kube_core.Volume{
Name: "kuma-sidecar-tmp",
VolumeSource: kube_core.VolumeSource{
Expand All @@ -103,7 +111,7 @@ func (i *KumaInjector) InjectKuma(ctx context.Context, pod *kube_core.Pod) error
},
},
}
pod.Spec.Volumes = append(pod.Spec.Volumes, sidecarTmp)
pod.Spec.Volumes = append(pod.Spec.Volumes, initTmp, sidecarTmp)

container.VolumeMounts = append(container.VolumeMounts, kube_core.VolumeMount{
Name: sidecarTmp.Name,
Expand Down Expand Up @@ -368,6 +376,14 @@ func (i *KumaInjector) NewInitContainer(pod *kube_core.Pod) (kube_core.Container
ImagePullPolicy: kube_core.PullIfNotPresent,
Command: []string{"/usr/bin/kumactl", "install", "transparent-proxy"},
Args: podRedirect.AsKumactlCommandLine(),
Env: []kube_core.EnvVar{
// iptables needs this lock file to be writable:
// source: https://git.netfilter.org/iptables/tree/iptables/xshared.c?h=v1.8.7#n258
{
Name: "XTABLES_LOCKFILE",
Value: "/tmp/xtables.lock",
},
},
SecurityContext: &kube_core.SecurityContext{
RunAsUser: new(int64), // way to get pointer to int64(0)
RunAsGroup: new(int64),
Expand All @@ -376,7 +392,11 @@ func (i *KumaInjector) NewInitContainer(pod *kube_core.Pod) (kube_core.Container
"NET_ADMIN",
"NET_RAW",
},
Drop: []kube_core.Capability{
"ALL",
},
},
ReadOnlyRootFilesystem: pointer.To(true),
},
Resources: kube_core.ResourceRequirements{
Limits: kube_core.ResourceList{
Expand All @@ -388,6 +408,9 @@ func (i *KumaInjector) NewInitContainer(pod *kube_core.Pod) (kube_core.Container
kube_core.ResourceMemory: *kube_api.NewScaledQuantity(20, kube_api.Mega),
},
},
VolumeMounts: []kube_core.VolumeMount{
{Name: "kuma-init-tmp", MountPath: "/tmp", ReadOnly: false},
},
}

if i.cfg.EBPF.Enabled {
Expand All @@ -412,10 +435,10 @@ func (i *KumaInjector) NewInitContainer(pod *kube_core.Pod) (kube_core.Container
kube_core.ResourceMemory: *kube_api.NewScaledQuantity(80, kube_api.Mega),
}

container.VolumeMounts = []kube_core.VolumeMount{
{Name: "sys-fs-cgroup", MountPath: i.cfg.EBPF.CgroupPath},
{Name: "bpf-fs", MountPath: i.cfg.EBPF.BPFFSPath, MountPropagation: &bidirectional},
}
container.VolumeMounts = append(container.VolumeMounts,
kube_core.VolumeMount{Name: "sys-fs-cgroup", MountPath: i.cfg.EBPF.CgroupPath},
kube_core.VolumeMount{Name: "bpf-fs", MountPath: i.cfg.EBPF.BPFFSPath, MountPropagation: &bidirectional},
)
}

return container, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ spec:
readOnly: true
initContainers:
- args:
- --config-file
- /tmp/kumactl/config
- --redirect-outbound-port
- "15001"
- --redirect-inbound=true
Expand All @@ -142,6 +144,9 @@ spec:
- /usr/bin/kumactl
- install
- transparent-proxy
env:
- name: XTABLES_LOCKFILE
value: /tmp/xtables.lock
image: kuma/kuma-init:latest
imagePullPolicy: IfNotPresent
name: kuma-init
Expand All @@ -157,12 +162,21 @@ spec:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 0
runAsUser: 0
volumeMounts:
- mountPath: /tmp
name: kuma-init-tmp
volumes:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir:
sizeLimit: 10M
name: kuma-init-tmp
- emptyDir:
sizeLimit: 10M
name: kuma-sidecar-tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ spec:
name: init
resources: {}
- args:
- --config-file
- /tmp/kumactl/config
- --redirect-outbound-port
- "15001"
- --redirect-inbound=true
Expand All @@ -150,6 +152,9 @@ spec:
- /usr/bin/kumactl
- install
- transparent-proxy
env:
- name: XTABLES_LOCKFILE
value: /tmp/xtables.lock
image: kuma/kuma-init:latest
imagePullPolicy: IfNotPresent
name: kuma-init
Expand All @@ -165,12 +170,21 @@ spec:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 0
runAsUser: 0
volumeMounts:
- mountPath: /tmp
name: kuma-init-tmp
volumes:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir:
sizeLimit: 10M
name: kuma-init-tmp
- emptyDir:
sizeLimit: 10M
name: kuma-sidecar-tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ spec:
enableServiceLinks: true
initContainers:
- args:
- --config-file
- /tmp/kumactl/config
- --redirect-outbound-port
- "15001"
- --redirect-inbound=true
Expand All @@ -204,6 +206,9 @@ spec:
- /usr/bin/kumactl
- install
- transparent-proxy
env:
- name: XTABLES_LOCKFILE
value: /tmp/xtables.lock
image: kuma/kuma-init:latest
imagePullPolicy: IfNotPresent
name: kuma-init
Expand All @@ -219,8 +224,14 @@ spec:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 0
runAsUser: 0
volumeMounts:
- mountPath: /tmp
name: kuma-init-tmp
nodeSelector:
beta.kubernetes.io/os: linux
priority: 2000000000
Expand Down Expand Up @@ -255,6 +266,9 @@ spec:
- name: coredns-token-9gmrh
secret:
secretName: coredns-token-9gmrh
- emptyDir:
sizeLimit: 10M
name: kuma-init-tmp
- emptyDir:
sizeLimit: 10M
name: kuma-sidecar-tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ spec:
readOnly: true
initContainers:
- args:
- --config-file
- /tmp/kumactl/config
- --redirect-outbound-port
- "15001"
- --redirect-inbound=true
Expand All @@ -142,6 +144,9 @@ spec:
- /usr/bin/kumactl
- install
- transparent-proxy
env:
- name: XTABLES_LOCKFILE
value: /tmp/xtables.lock
image: kuma/kuma-init:latest
imagePullPolicy: IfNotPresent
name: kuma-init
Expand All @@ -157,12 +162,21 @@ spec:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 0
runAsUser: 0
volumeMounts:
- mountPath: /tmp
name: kuma-init-tmp
volumes:
- name: default-token-w7dxf
secret:
secretName: default-token-w7dxf
- emptyDir:
sizeLimit: 10M
name: kuma-init-tmp
- emptyDir:
sizeLimit: 10M
name: kuma-sidecar-tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ spec:
resources: {}
initContainers:
- args:
- --config-file
- /tmp/kumactl/config
- --redirect-outbound-port
- "15001"
- --redirect-inbound=true
Expand All @@ -136,6 +138,9 @@ spec:
- /usr/bin/kumactl
- install
- transparent-proxy
env:
- name: XTABLES_LOCKFILE
value: /tmp/xtables.lock
image: kuma/kuma-init:latest
imagePullPolicy: IfNotPresent
name: kuma-init
Expand All @@ -151,9 +156,18 @@ spec:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 0
runAsUser: 0
volumeMounts:
- mountPath: /tmp
name: kuma-init-tmp
volumes:
- emptyDir:
sizeLimit: 10M
name: kuma-init-tmp
- emptyDir:
sizeLimit: 10M
name: kuma-sidecar-tmp
Expand Down
Loading

0 comments on commit 5a09493

Please sign in to comment.