Skip to content

Commit 8597b34

Browse files
committed
Enforce the Minimum Kernel Version 6.3 for UserNamespacesSupport feature
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 2aff7db commit 8597b34

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/kubelet/kubelet_pods.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"k8s.io/apimachinery/pkg/types"
4242
"k8s.io/apimachinery/pkg/util/sets"
4343
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
44+
"k8s.io/apimachinery/pkg/util/version"
4445
utilfeature "k8s.io/apiserver/pkg/util/feature"
4546
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
4647
"k8s.io/klog/v2"
@@ -62,6 +63,7 @@ import (
6263
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
6364
"k8s.io/kubernetes/pkg/kubelet/util"
6465
utilfs "k8s.io/kubernetes/pkg/util/filesystem"
66+
utilkernel "k8s.io/kubernetes/pkg/util/kernel"
6567
utilpod "k8s.io/kubernetes/pkg/util/pod"
6668
volumeutil "k8s.io/kubernetes/pkg/volume/util"
6769
"k8s.io/kubernetes/pkg/volume/util/hostutil"
@@ -130,6 +132,17 @@ func (kl *Kubelet) getKubeletMappings() (uint32, uint32, error) {
130132

131133
if !utilfeature.DefaultFeatureGate.Enabled(features.UserNamespacesSupport) {
132134
return defaultFirstID, defaultLen, nil
135+
} else {
136+
kernelVersion, err := utilkernel.GetVersion()
137+
if err != nil {
138+
return 0, 0, fmt.Errorf("failed to get kernel version, unable to determine if feature %s can be supported : %w",
139+
features.UserNamespacesSupport, err)
140+
}
141+
if kernelVersion != nil && !kernelVersion.AtLeast(version.MustParseGeneric(utilkernel.UserNamespacesSupportKernelVersion)) {
142+
return 0, 0, fmt.Errorf(
143+
"the kernel version (%s) is incompatible with the %s feature gate, which needs %s as a minimum kernel version",
144+
kernelVersion, features.UserNamespacesSupport, utilkernel.UserNamespacesSupportKernelVersion)
145+
}
133146
}
134147

135148
_, err := user.Lookup(kubeletUser)

pkg/util/kernel/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ const TCPFinTimeoutNamespacedKernelVersion = "4.6"
4343
// IPVSConnReuseModeFixedKernelVersion is the kernel version in which net.ipv4.vs.conn_reuse_mode was fixed.
4444
// (ref: https://github.com/torvalds/linux/commit/35dfb013149f74c2be1ff9c78f14e6a3cd1539d1)
4545
const IPVSConnReuseModeFixedKernelVersion = "5.9"
46+
47+
// UserNamespacesSupportKernelVersion is the kernel version where idmap for tmpfs support was added
48+
// (ref: https://github.com/torvalds/linux/commit/05e6295f7b5e05f09e369a3eb2882ec5b40fff20)
49+
const UserNamespacesSupportKernelVersion = "6.3"

0 commit comments

Comments
 (0)