Skip to content

Commit

Permalink
CI: parallel-safe userns test
Browse files Browse the repository at this point in the history
- use safename
- add ci:parallel tags where possible
  - where not possible, document why

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Aug 22, 2024
1 parent a581bbd commit 1154794
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/system/170-run-userns.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function _require_crun() {
fi
}

# bats test_tags=ci:parallel
@test "podman --group-add keep-groups while in a userns" {
skip_if_rootless "chroot is not allowed in rootless mode"
skip_if_remote "--group-add keep-groups not supported in remote mode"
Expand All @@ -23,6 +24,7 @@ function _require_crun() {
is "$output" ".*65534(nobody)" "Check group leaked into user namespace"
}

# bats test_tags=ci:parallel
@test "podman --group-add keep-groups while not in a userns" {
skip_if_rootless "chroot is not allowed in rootless mode"
skip_if_remote "--group-add keep-groups not supported in remote mode"
Expand All @@ -31,6 +33,7 @@ function _require_crun() {
is "$output" ".*1234" "Check group leaked into container"
}

# bats test_tags=ci:parallel
@test "podman --group-add without keep-groups while in a userns" {
skip_if_cgroupsv1 "run --uidmap fails on cgroups v1 (issue 15025, wontfix)"
skip_if_rootless "chroot is not allowed in rootless mode"
Expand All @@ -39,21 +42,22 @@ function _require_crun() {
is "$output" ".*457" "Check group leaked into container"
}

# bats test_tags=ci:parallel
@test "rootful pod with custom ID mapping" {
skip_if_cgroupsv1 "run --uidmap fails on cgroups v1 (issue 15025, wontfix)"
skip_if_rootless "does not work rootless - rootful feature"
random_pod_name=$(random_string 30)
random_pod_name=p_$(safename)
run_podman pod create --uidmap 0:200000:5000 --name=$random_pod_name
run_podman pod start $random_pod_name
run_podman pod inspect --format '{{.InfraContainerID}}' $random_pod_name
run_podman inspect --format '{{.HostConfig.IDMappings.UIDMap}}' $output
is "$output" ".*0:200000:5000" "UID Map Successful"

# Remove the pod and the pause image
# Clean up
run_podman pod rm $random_pod_name
run_podman rmi -f $(pause_image)
}

# bats test_tags=ci:parallel
@test "podman --remote --group-add keep-groups " {
if ! is_remote; then
skip "this test only meaningful under podman-remote"
Expand All @@ -63,16 +67,19 @@ function _require_crun() {
is "$output" ".*not supported in remote mode" "Remote check --group-add keep-groups"
}

# bats test_tags=ci:parallel
@test "podman --group-add without keep-groups " {
run_podman run --rm --group-add 457 $IMAGE id
is "$output" ".*457" "Check group leaked into container"
}

# bats test_tags=ci:parallel
@test "podman --group-add keep-groups plus added groups " {
run_podman 125 run --rm --group-add keep-groups --group-add 457 $IMAGE id
is "$output" ".*the '--group-add keep-groups' option is not allowed with any other --group-add options" "Check group leaked into container"
}

# CANNOT BE PARALLELIZED: userns=auto, rootless, => not enough unused IDs in user namespace
@test "podman userns=auto in config file" {
skip_if_remote "userns=auto is set on the server"

Expand All @@ -99,6 +106,7 @@ EOF
CONTAINERS_CONF_OVERRIDE=$PODMAN_TMPDIR/userns_auto.conf run_podman 0 run --rm $IMAGE awk '{if($2 == "0"){exit 1}}' /proc/self/uid_map /proc/self/gid_map
}

# CANNOT BE PARALLELIZED: userns=auto, rootless, => not enough unused IDs in user namespace
@test "podman userns=auto and secrets" {
ns_user="containers"
if is_rootless; then
Expand All @@ -115,6 +123,7 @@ EOF
run_podman secret rm ${test_name}
}

# bats test_tags=ci:parallel
@test "podman userns=nomap" {
if is_rootless; then
ns_user=$(id -un)
Expand All @@ -133,21 +142,24 @@ EOF
fi
}

# bats test_tags=ci:parallel
@test "podman userns=keep-id" {
user=$(id -u)
run_podman run --rm --userns=keep-id $IMAGE id -u
is "${output}" "$user" "Container should run as the current user"
}

# bats test_tags=ci:parallel
@test "podman userns=keep-id in a pod" {
user=$(id -u)
run_podman pod create --userns keep-id
run_podman pod create --name p_$(safename) --userns keep-id
pid=$output
run_podman run --rm --pod $pid $IMAGE id -u
is "${output}" "$user" "Container should run as the current user"
run_podman rmi -f $(pause_image)
run_podman pod rm $pid
}

# CANNOT BE PARALLELIZED: userns=auto, rootless, => not enough unused IDs in user namespace
@test "podman userns=auto with id mapping" {
skip_if_not_rootless
skip_if_remote
Expand Down

0 comments on commit 1154794

Please sign in to comment.