You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
by Daniel J Walsh. Note that the guide is older than Kubernetes, it describes
32
-
*Multi-Category Security* (MCS) mode using virtual machines as an example,
33
-
however, similar concept is used for containers.
37
+
If a Pod + its volume satisfies **all** following conditions, Kubernetes will
38
+
_mount_ the volume directly with the right SELinux label. Such mount will happen
39
+
in a constant time and the container runtime will not need to recursively
40
+
relabel any files on it.
34
41
35
-
See a series of blog posts for details how exactly SELinux is applied to
36
-
containers by container runtimes:
42
+
1. The operating system must support SELinux.
37
43
38
-
*[How SELinux separates containers using Multi-Level Security](https://www.redhat.com/en/blog/how-selinux-separates-containers-using-multi-level-security)
39
-
*[Why you should be using Multi-Category Security for your Linux containers](https://www.redhat.com/en/blog/why-you-should-be-using-multi-category-security-your-linux-containers)
44
+
Without SELinux support detected, kubelet and the container runtime does not
45
+
do anything with regard to SELinux.
40
46
41
-
## SELinux in Kubernetes
47
+
1. The [feature gates](/docs/reference/command-line-tools-reference/feature-gates/)
48
+
`ReadWriteOncePod` and `SELinuxMountReadWriteOncePod` must be enabled.
49
+
These feature gates are Beta in Kubernetes 1.27 and Alpha in 1.25.
42
50
43
-
Kubernetes allows setting the complete pod process label in `securityContext`
44
-
field of a Pod, or in `securityContext` of each container in the Pod.
51
+
With any of these feature gates disabled, SELinux labels will be always
52
+
applied by the container runtime by a recursive walk through the volume
53
+
(or its subPaths).
45
54
46
-
Kubernetes passes the SELinux label to the container runtime, together
47
-
with pod's volumes and their subpaths. By default, Kubernetes tells the
48
-
container runtime to recursively apply the SELinux label to all files on all
49
-
volumes that support SELinux before running the pod containers.
55
+
1. The Pod must have at least `seLinuxOptions.level` assigned in its [Pod Security Context](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context) or all Pod containers must have it set in their [Security Contexts](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context-1).
56
+
Kubernetes will read the default `user`, `role` and `type` from the operating
57
+
system defaults (typically `system_u`, `system_r` and `container_t`).
50
58
51
-
{{< caution >}}
52
-
The container runtime relabels only the part of a volume that's visible to the
53
-
running container(s). If a container uses `subPath` of a volume, only that
54
-
`subPath` is relabeled.
59
+
Without Kubernetes knowing at least the SELinux `level`, the container
60
+
runtime will assign a random one _after_ the volumes are mounted. The
61
+
container runtime will still relabel the volumes recursively in that case.
55
62
56
-
This allows two pods that have two different SELinux labels to use the same
57
-
volume, as long as they use different subpaths of it.
by Daniel J Walsh. Note that the guide is older than Kubernetes, it describes
118
+
*Multi-Category Security* (MCS) mode using virtual machines as an example,
119
+
however, similar concept is used for containers.
125
120
126
-
We kindly ask Kubernetes cluster admins to check the metrics and report any
127
-
breakage that would be caused by extending the `context` mount to *all* volumes.
128
-
Please tag `@jsafrane` in Kubernetes issues.
121
+
See a series of blog posts for details how exactly SELinux is applied to
122
+
containers by container runtimes:
123
+
*[How SELinux separates containers using Multi-Level Security](https://www.redhat.com/en/blog/how-selinux-separates-containers-using-multi-level-security)
124
+
*[Why you should be using Multi-Category Security for your Linux containers](https://www.redhat.com/en/blog/why-you-should-be-using-multi-category-security-your-linux-containers)
129
125
130
-
# How can I learn more?
131
126
Read the KEP: [Speed up SELinux volume relabeling using mounts](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1710-selinux-relabeling)
0 commit comments