Skip to content

Commit 2cd0815

Browse files
committed
cri: Expose runtimeHandler support for userns
Since kubernetes 1.30, the kubelet will query the runtime handlers features and only start pods with userns if the runtime handler used for that pod supports it. Let's expose the user namespace support to the kubelet. Signed-off-by: Rodrigo Campos <[email protected]>
1 parent 358aef4 commit 2cd0815

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

internal/cri/server/service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ func (c *criService) introspectRuntimeHandlers(ctx context.Context) ([]*runtime.
381381
log.G(ctx).Debugf("runtime %q supports recursive read-only mounts, but the kernel does not", name)
382382
}
383383
}
384+
userns := supportsCRIUserns(rawFeatures)
385+
h.Features.UserNamespaces = userns
386+
log.G(ctx).Debugf("runtime %q supports CRI userns: %v", name, userns)
384387
}
385388
res = append(res, &h)
386389
if name == c.config.DefaultRuntimeName {
@@ -438,3 +441,20 @@ func introspectRuntimeFeatures(ctx context.Context, intro introspection.Service,
438441
}
439442
return features, nil
440443
}
444+
445+
func supportsCRIUserns(f *features.Features) bool {
446+
if f == nil {
447+
return false
448+
}
449+
userns := slices.Contains(f.Linux.Namespaces, "user")
450+
451+
var idmap bool
452+
if m := f.Linux.MountExtensions; m != nil && m.IDMap != nil && m.IDMap.Enabled != nil {
453+
if *m.IDMap.Enabled {
454+
idmap = true
455+
}
456+
}
457+
458+
// user namespace support in CRI requires userns and idmap support.
459+
return userns && idmap
460+
}

0 commit comments

Comments
 (0)