From 4a0e282b09879b847dca81f34d3c36431f3221dc Mon Sep 17 00:00:00 2001 From: lifubang Date: Tue, 25 Mar 2025 02:34:22 +0000 Subject: [PATCH] test: check whether runc set a correct default home env or not Signed-off-by: lifubang --- tests/integration/exec.bats | 14 ++++++++++++++ tests/integration/run.bats | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 8e96f3ddd..43fe4c3cd 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -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" ] +} diff --git a/tests/integration/run.bats b/tests/integration/run.bats index 86d016dc2..d1143cfea 100644 --- a/tests/integration/run.bats +++ b/tests/integration/run.bats @@ -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" ] +}