Skip to content

Commit 7467d81

Browse files
authored
Merge pull request containerd#9836 from kinvolk/rata/userns-runtimeHandler
Add support for userns (k8s >= 1.30)
2 parents 7628c04 + 2cd0815 commit 7467d81

File tree

6 files changed

+510
-442
lines changed

6 files changed

+510
-442
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ require (
7474
k8s.io/apimachinery v0.29.2
7575
k8s.io/client-go v0.29.2
7676
k8s.io/component-base v0.29.2
77-
k8s.io/cri-api v0.30.0-alpha.2.0.20240216190946-4e003cc3b0a4
77+
k8s.io/cri-api v0.30.0-alpha.2.0.20240217224521-840a52e4cd66
7878
k8s.io/klog/v2 v2.120.1
7979
k8s.io/kubelet v0.29.2
8080
k8s.io/utils v0.0.0-20230726121419-3b25d923346b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ k8s.io/client-go v0.29.2 h1:FEg85el1TeZp+/vYJM7hkDlSTFZ+c5nnK44DJ4FyoRg=
799799
k8s.io/client-go v0.29.2/go.mod h1:knlvFZE58VpqbQpJNbCbctTVXcd35mMyAAwBdpt4jrA=
800800
k8s.io/component-base v0.29.2 h1:lpiLyuvPA9yV1aQwGLENYyK7n/8t6l3nn3zAtFTJYe8=
801801
k8s.io/component-base v0.29.2/go.mod h1:BfB3SLrefbZXiBfbM+2H1dlat21Uewg/5qtKOl8degM=
802-
k8s.io/cri-api v0.30.0-alpha.2.0.20240216190946-4e003cc3b0a4 h1:MkxF8QPcofA/nw9k03EQcMkCdP2RcyDZeF1Zda9m/3w=
803-
k8s.io/cri-api v0.30.0-alpha.2.0.20240216190946-4e003cc3b0a4/go.mod h1:9fQTFm+wi4FLyqrkVUoMJiUB3mE74XrVvHz8uFY/sSw=
802+
k8s.io/cri-api v0.30.0-alpha.2.0.20240217224521-840a52e4cd66 h1:N5xMegEabSkJia7wOv7md8SQ6dQtgwEX+7gq7R8a4wM=
803+
k8s.io/cri-api v0.30.0-alpha.2.0.20240217224521-840a52e4cd66/go.mod h1:9fQTFm+wi4FLyqrkVUoMJiUB3mE74XrVvHz8uFY/sSw=
804804
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
805805
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
806806
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=

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)