Skip to content

Commit 925d878

Browse files
authored
Merge pull request #49919 from jsafrane/selinux-beta2
Announce improved SELinux volume relabelling beta
2 parents c914dbb + 5d6fb08 commit 925d878

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

content/en/docs/reference/command-line-tools-reference/feature-gates/SELinuxChangePolicy.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ stages:
99
- stage: alpha
1010
defaultValue: false
1111
fromVersion: "1.32"
12+
toVersion: "1.32"
13+
- stage: beta
14+
defaultValue: true
15+
fromVersion: "1.33"
1216
---
1317
Enables `spec.securityContext.seLinuxChangePolicy` field.
1418
This field can be used to opt-out from applying the SELinux label to the pod

content/en/docs/reference/command-line-tools-reference/feature-gates/SELinuxMount.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ stages:
99
- stage: alpha
1010
defaultValue: false
1111
fromVersion: "1.30"
12+
toVersion: "1.32"
13+
- stage: beta
14+
defaultValue: false
15+
fromVersion: "1.33"
16+
1217
---
1318
Speeds up container startup by allowing kubelet to mount volumes
1419
for a Pod directly with the correct SELinux label instead of changing each file on the volumes

content/en/docs/tasks/configure-pod-container/security-context.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ securityContext:
686686

687687
{{< note >}}
688688
To assign SELinux labels, the SELinux security module must be loaded on the host operating system.
689+
On Windows and Linux worker nodes without SELinux support, this field and any SELinux feature gates described
690+
below have no effect.
689691
{{< /note >}}
690692

691693
### Efficient SELinux volume relabeling
@@ -696,24 +698,25 @@ To assign SELinux labels, the SELinux security module must be loaded on the host
696698
Kubernetes v1.27 introduced an early limited form of this behavior that was only applicable
697699
to volumes (and PersistentVolumeClaims) using the `ReadWriteOncePod` access mode.
698700

699-
As an alpha feature, you can enable the `SELinuxMount` and `SELinuxChangePolicy`
700-
[feature gates](/docs/reference/command-line-tools-reference/feature-gates/) to widen that
701-
performance improvement to other kinds of PersistentVolumeClaims, as explained in detail
702-
below.
701+
Kubernetes v1.33 promotes `SELinuxChangePolicy` and `SELinuxMount`
702+
[feature gates](/docs/reference/command-line-tools-reference/feature-gates/)
703+
as beta to widen that performance improvement to other kinds of PersistentVolumeClaims,
704+
as explained in detail below. While in beta, `SELinuxMount` is still disabled by default.
703705
{{< /note >}}
704706

705-
By default, the container runtime recursively assigns SELinux label to all
706-
files on all Pod volumes. To speed up this process, Kubernetes can change the
707+
With `SELinuxMount` feature gate disabled (the default in Kubernetes 1.33 and any previous release),
708+
the container runtime recursively assigns SELinux label to all
709+
files on all Pod volumes by default. To speed up this process, Kubernetes can change the
707710
SELinux label of a volume instantly by using a mount option
708711
`-o context=<label>`.
709712

710713
To benefit from this speedup, all these conditions must be met:
711714

712-
* The [feature gates](/docs/reference/command-line-tools-reference/feature-gates/) `ReadWriteOncePod`
713-
and `SELinuxMountReadWriteOncePod` must be enabled.
715+
* The [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
716+
`SELinuxMountReadWriteOncePod` must be enabled.
714717
* Pod must use PersistentVolumeClaim with applicable `accessModes` and [feature gates](/docs/reference/command-line-tools-reference/feature-gates/):
715718
* Either the volume has `accessModes: ["ReadWriteOncePod"]`, and feature gate `SELinuxMountReadWriteOncePod` is enabled.
716-
* Or the volume can use any other access modes and both feature gates
719+
* Or the volume can use any other access modes and all feature gates
717720
`SELinuxMountReadWriteOncePod`, `SELinuxChangePolicy` and `SELinuxMount` must be enabled
718721
and the Pod has `spec.securityContext.seLinuxChangePolicy` either nil (default) or `MountOption`.
719722
* Pod (or all its Containers that use the PersistentVolumeClaim) must
@@ -724,9 +727,15 @@ To benefit from this speedup, all these conditions must be met:
724727
The CSI driver must announce that it supports mounting with `-o context` by setting
725728
`spec.seLinuxMount: true` in its CSIDriver instance.
726729

727-
For any other volume types, SELinux relabelling happens another way: the container
730+
When any of these conditions is not met, SELinux relabelling happens another way: the container
728731
runtime recursively changes the SELinux label for all inodes (files and directories)
729-
in the volume.
732+
in the volume. Calling out explicitly, this applies to Kubernetes ephemeral volumes like
733+
`secret`, `configMap` and `projected`, and all volumes whose CSIDriver instance does not
734+
explicitly announce mounting with `-o context`.
735+
736+
When this speedup is used, all Pods that use the same applicable volume concurrently on the same node
737+
**must have the same SELinux label**. A Pod with a different SELinux label will fail to start and will be
738+
`ContainerCreating` until all Pods with other SELinux labels that use the volume are deleted.
730739

731740
{{< feature-state feature_gate_name="SELinuxChangePolicy" >}}
732741
For Pods that want to opt-out from relabeling using mount options, they can set
@@ -758,6 +767,12 @@ with different SELinux labels:
758767
A cluster admin can use this information to identify pods affected by the planning change and
759768
proactively opt-out Pods from the optimization (i.e. set `spec.securityContext.seLinuxChangePolicy: Recursive`).
760769

770+
{{< warning >}}
771+
We strongly recommend clusters that use SELinux to enable this controller and make sure that
772+
`selinux_warning_controller_selinux_volume_conflict` metric does not report any conflicts before enabling `SELinuxMount`
773+
feature gate or upgrading to a version where `SELinuxMount` is enabled by default.
774+
{{< /warning >}}
775+
761776
#### Feature gates
762777

763778
The following feature gates control the behavior of SELinux volume relabeling:
@@ -768,11 +783,11 @@ The following feature gates control the behavior of SELinux volume relabeling:
768783
* `SELinuxChangePolicy`: enables `spec.securityContext.seLinuxChangePolicy` field in Pod and related SELinuxWarningController
769784
in kube-controller-manager. This feature can be used before enabling `SELinuxMount` to check Pods running on a cluster,
770785
and to pro-actively opt-out Pods from the optimization.
771-
This feature gate requires `SELinuxMountReadWriteOncePod` enabled. It is alpha and disabled by default in 1.32.
786+
This feature gate requires `SELinuxMountReadWriteOncePod` enabled. It is beta and enabled by default in 1.33.
772787
* `SELinuxMount` enables the optimization for all eligible volumes. Since it can break existing workloads, we recommend
773788
enabling `SELinuxChangePolicy` feature gate + SELinuxWarningController first to check the impact of the change.
774-
This feature gate requires `SELinuxMountReadWriteOncePod` and `SELinuxChangePolicy` enabled. It is alpha and disabled
775-
by default in 1.32.
789+
This feature gate requires `SELinuxMountReadWriteOncePod` and `SELinuxChangePolicy` enabled. It is beta, but disabled
790+
by default in 1.33.
776791

777792
## Managing access to the `/proc` filesystem {#proc-access}
778793

0 commit comments

Comments
 (0)