Skip to content

Commit cb340ff

Browse files
committed
libct: fix user ns join order for rootful container
If we are rootless and there are userns-owned namespaces, we need to be in the userns in order to have the necessary permissions to do setns. This is what 2cd9c31 fixed. But for rootful container, if we join the userns in first step, we may can't join some namespaces which have no permissions for the userns we have joined. Signed-off-by: lifubang <lifubang@acmcoder.com>
1 parent 629f6d3 commit cb340ff

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

libcontainer/container_linux.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,13 @@ func (c *Container) currentOCIState() (*specs.State, error) {
959959

960960
// orderNamespacePaths sorts namespace paths into a list of paths that we
961961
// can setns in order.
962-
func (c *Container) orderNamespacePaths(namespaces map[configs.NamespaceType]string) ([]string, error) {
962+
func (c *Container) orderNamespacePaths(namespaces map[configs.NamespaceType]string, rootless bool) ([]string, error) {
963963
paths := []string{}
964-
for _, ns := range configs.NamespaceTypes() {
964+
nsTypes := configs.NamespaceTypes()
965+
if !rootless {
966+
nsTypes = append(nsTypes[1:], nsTypes[0])
967+
}
968+
for _, ns := range nsTypes {
965969

966970
// Remove namespaces that we don't need to join.
967971
if !c.config.Namespaces.Contains(ns) {
@@ -1037,7 +1041,7 @@ func (c *Container) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Namespa
10371041

10381042
// write custom namespace paths
10391043
if len(nsMaps) > 0 {
1040-
nsPaths, err := c.orderNamespacePaths(nsMaps)
1044+
nsPaths, err := c.orderNamespacePaths(nsMaps, c.config.RootlessEUID)
10411045
if err != nil {
10421046
return nil, err
10431047
}

0 commit comments

Comments
 (0)