Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libpod/container_inspect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC
}
}
}

// If userns=auto, setting up the namespace is deferred until the container
// is created. If the container is configured, check if it is going to have a
// private userns and return accordingly
if c.state.State == define.ContainerStateConfigured && c.config.IDMappings.AutoUserNs {
usernsMode = "private"
}
}
hostConfig.UsernsMode = usernsMode
if c.config.IDMappings.UIDMap != nil && c.config.IDMappings.GIDMap != nil {
Expand Down
2 changes: 1 addition & 1 deletion libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
}
}

// Add shared namespaces from other containers
// Add shared namespaces from other containers. Also handles userns=auto
if err := c.addSharedNamespaces(&g); err != nil {
return nil, nil, err
}
Expand Down
18 changes: 18 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,24 @@ for runtime in "${oci_runtimes[@]}"; do
t DELETE containers/$cid 204
done

# 27998: make sure a created (and not started) container with userns=auto shows
# UsernsMode = private before being started

t POST libpod/containers/create \
image=$IMAGE \
UserNS='{"NSMode":"auto"}' \
IDMappings='{"AutoUserNs":true,"AutoUserNsOpts":{"AdditionalUIDMappings":[],"AdditionalGIDMappings":[],"PasswdFile":"","GroupFile":"","InitialSize":0,"Size":0}}' \
201
cid=$(jq -r '.Id' <<<"$output")

t GET libpod/containers/$cid/json \
200 \
.HostConfig.UsernsMode='private'

t DELETE libpod/containers/$cid 200 .[0].Id=$cid


# clean up
podman rmi -f $IMAGE

# Test health status in /containers/json (GH #27786)
Expand Down
Loading