test: check whether runc set a correct default home env or not

Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
lifubang
2025-03-25 02:34:22 +00:00
parent e2e3c65383
commit 4a0e282b09
2 changed files with 30 additions and 0 deletions

View File

@@ -352,3 +352,17 @@ EOF
[ ${#lines[@]} -eq 1 ]
[[ ${lines[0]} = *"exec /run.sh: no such file or directory"* ]]
}
# https://github.com/opencontainers/runc/issues/4688
@test "runc exec check default home" {
# --user can't work in rootless containers that don't have idmap.
[ $EUID -ne 0 ] && requires rootless_idmap
echo 'tempuser:x:2000:2000:tempuser:/home/tempuser:/bin/sh' >>rootfs/etc/passwd
runc run -d --console-socket "$CONSOLE_SOCKET" test
[ "$status" -eq 0 ]
runc exec -u 2000 test sh -c "echo \$HOME"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "/home/tempuser" ]
}

View File

@@ -219,3 +219,19 @@ EOF
[ ${#lines[@]} -eq 1 ]
[[ ${lines[0]} = "exec /run.sh: no such file or directory" ]]
}
# https://github.com/opencontainers/runc/issues/4688
@test "runc run check default home" {
# cannot start containers as another user in rootless setup without idmap
[ $EUID -ne 0 ] && requires rootless_idmap
echo 'tempuser:x:2000:2000:tempuser:/home/tempuser:/bin/sh' >>rootfs/etc/passwd
# shellcheck disable=SC2016
update_config ' .process.cwd = "/root"
| .process.user.uid = 2000
| .process.args |= ["sh", "-c", "echo $HOME"]'
runc run test_busybox
[ "$status" -eq 0 ]
[ "${lines[0]}" = "/home/tempuser" ]
}