Skip to content

Commit 79ecc1d

Browse files
committed
Fix --userns=ns:<path> conflicting with runc 1.1.11+
Remove dummy UID/GID mappings added when joining existing user namespaces, which runc 1.1.11+ rejects as conflicting. RUNC fix: opencontainers/runc#4124 Fixes #27148 Signed-off-by: Jan Rodák <[email protected]>
1 parent 80b20c7 commit 79ecc1d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pkg/specgen/namespaces.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,6 @@ func SetupUserNS(idmappings *storageTypes.IDMappingOptions, userns Namespace, g
503503
if err := g.AddOrReplaceLinuxNamespace(string(spec.UserNamespace), userns.Value); err != nil {
504504
return user, err
505505
}
506-
// runc complains if no mapping is specified, even if we join another ns. So provide a dummy mapping
507-
g.AddLinuxUIDMapping(uint32(0), uint32(0), uint32(1))
508-
g.AddLinuxGIDMapping(uint32(0), uint32(0), uint32(1))
509506
case Host:
510507
if err := g.RemoveLinuxNamespace(string(spec.UserNamespace)); err != nil {
511508
return user, err

test/system/170-run-userns.bats

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,30 @@ EOF
179179
# gid not mapped
180180
run_podman run --rm --uidmap 0:0:1000 --gidmap 0:1:1000 $IMAGE true
181181
}
182+
183+
# bats test_tags=ci:parallel
184+
@test "podman --userns=ns:<path> join existing user namespace" {
185+
# Test for issue #27148: --userns=ns:<path> should not add dummy mappings
186+
local cname="userns_source_$(safename)"
187+
188+
run_podman run -d --name $cname \
189+
--userns=keep-id \
190+
$IMAGE top
191+
192+
run_podman inspect --format '{{.State.Pid}}' $cname
193+
local pid=$output
194+
local userns_path="/proc/$pid/ns/user"
195+
196+
run_podman exec $cname sh -c "readlink /proc/self/ns/user; echo '---'; cat /proc/self/uid_map"
197+
local expected="$output"
198+
199+
run_podman run --rm \
200+
--userns=ns:$userns_path \
201+
$IMAGE \
202+
sh -c "readlink /proc/self/ns/user; echo '---'; cat /proc/self/uid_map"
203+
local output="$output"
204+
205+
assert "$expected" == "$output" "User namespace identifiers and UID mappings should match"
206+
207+
run_podman rm -f $cname
208+
}

0 commit comments

Comments
 (0)