Skip to content

Commit 5e76a88

Browse files
Merge pull request #20998 from edsantiago/safer_isolation
CI: systests: safer isolation in registry & tests
2 parents 7080d99 + 232c32b commit 5e76a88

File tree

7 files changed

+46
-27
lines changed

7 files changed

+46
-27
lines changed

test/system/272-system-connection.bats

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ $c2[ ]\+tcp://localhost:54321[ ]\+true" \
108108
# Start service. Now podman info should work fine. The %%-remote*
109109
# converts "podman-remote --opts" to just "podman", which is what
110110
# we need for the server.
111-
${PODMAN%%-remote*} --root ${PODMAN_TMPDIR}/root \
112-
--runroot ${PODMAN_TMPDIR}/runroot \
111+
${PODMAN%%-remote*} $(podman_isolation_opts ${PODMAN_TMPDIR}) \
113112
system service -t 99 tcp://localhost:$_SERVICE_PORT &
114113
_SERVICE_PID=$!
115114
# Wait for the port and the podman-service to be ready.

test/system/330-corrupt-images.bats

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ PODMAN_CORRUPT_TEST_IMAGE_CANONICAL_FQIN=quay.io/libpod/alpine@sha256:634a8f35b5
1717
PODMAN_CORRUPT_TEST_IMAGE_TAGGED_FQIN=${PODMAN_CORRUPT_TEST_IMAGE_CANONICAL_FQIN%%@sha256:*}:test
1818
PODMAN_CORRUPT_TEST_IMAGE_ID=961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
1919

20-
# All tests in this file (and ONLY in this file) run with a custom rootdir
2120
function setup() {
2221
skip_if_remote "none of these tests run under podman-remote"
23-
_PODMAN_TEST_OPTS="--storage-driver=vfs --root ${PODMAN_CORRUPT_TEST_WORKDIR}/root"
22+
23+
# DANGER! This completely changes the behavior of run_podman,
24+
# forcing it to use a quarantined directory. Make certain that
25+
# it gets unset in teardown.
26+
_PODMAN_TEST_OPTS="--storage-driver=vfs $(podman_isolation_opts ${PODMAN_CORRUPT_TEST_WORKDIR})"
2427
}
2528

2629
function teardown() {
27-
# No other tests should ever run with this custom rootdir
30+
# No other tests should ever run with these scratch options
2831
unset _PODMAN_TEST_OPTS
2932

3033
is_remote && return

test/system/520-checkpoint.bats

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,8 @@ function teardown() {
117117
@test "podman checkpoint --export, with volumes" {
118118
skip_if_remote "Test uses --root/--runroot, which are N/A over remote"
119119

120-
# Create a root in tempdir. We will run a container here.
121-
local p_root=${PODMAN_TMPDIR}/testroot/root
122-
local p_runroot=${PODMAN_TMPDIR}/testroot/runroot
123-
mkdir -p $p_root $p_runroot
124-
125120
# To avoid network pull, copy $IMAGE straight to temp root
126-
local p_opts="--root $p_root --runroot $p_runroot --events-backend file"
121+
local p_opts="$(podman_isolation_opts ${PODMAN_TMPDIR}) --events-backend file"
127122
run_podman save -o $PODMAN_TMPDIR/image.tar $IMAGE
128123
run_podman $p_opts load -i $PODMAN_TMPDIR/image.tar
129124

test/system/550-pause-process.bats

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ function _check_pause_process() {
6060
test $status -eq 0 && die "Pause process $pause_pid is still running even after podman system migrate"
6161
fi
6262

63-
run_podman --root $PODMAN_TMPDIR/root \
64-
--runroot $PODMAN_TMPDIR/runroot \
65-
--tmpdir $PODMAN_TMPDIR/tmp \
66-
$getns
63+
run_podman $(podman_isolation_opts ${PODMAN_TMPDIR}) $getns
6764
tmpdir_userns="$output"
6865

6966
# And now we should once again have a pause process

test/system/helpers.bash

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,20 @@ function podman_storage_driver() {
607607
echo "$output"
608608
}
609609

610+
# Given a (scratch) directory path, returns a set of command-line options
611+
# for running an isolated podman that will not step on system podman. Set:
612+
# - rootdir, so we don't clobber real images or storage;
613+
# - tmpdir, so we use an isolated DB; and
614+
# - runroot, out of an abundance of paranoia
615+
function podman_isolation_opts() {
616+
local path=${1?podman_isolation_opts: missing PATH arg}
617+
618+
for opt in root runroot tmpdir;do
619+
mkdir -p $path/$opt
620+
echo " --$opt $path/$opt"
621+
done
622+
}
623+
610624
# rhbz#1895105: rootless journald is unavailable except to users in
611625
# certain magic groups; which our testuser account does not belong to
612626
# (intentional: that is the RHEL default, so that's the setup we test).

test/system/helpers.registry.bash

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ unset REGISTRY_AUTH_FILE
1919
function start_registry() {
2020
if [[ -d "$PODMAN_LOGIN_WORKDIR/auth" ]]; then
2121
# Already started
22+
23+
# Fixes very obscure corner case in root system tests:
24+
# 1) we run 150-login tests, starting a registry; then
25+
# 2) run 500-network, which runs iptables -F; then
26+
# 3) run 700-play, the "private" test, which needs the
27+
# already-started registry, but its port is now DROPped,
28+
# so the test times out trying to talk to registry
29+
run_podman --storage-driver vfs $(podman_isolation_opts ${PODMAN_LOGIN_WORKDIR}) network reload --all
2230
return
2331
fi
2432

@@ -28,10 +36,8 @@ function start_registry() {
2836
# Registry image; copy of docker.io, but on our own registry
2937
local REGISTRY_IMAGE="$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/registry:2.8"
3038

31-
# Pull registry image, but into a separate container storage
32-
mkdir ${PODMAN_LOGIN_WORKDIR}/root
33-
mkdir ${PODMAN_LOGIN_WORKDIR}/runroot
34-
PODMAN_LOGIN_ARGS="--storage-driver vfs --root ${PODMAN_LOGIN_WORKDIR}/root --runroot ${PODMAN_LOGIN_WORKDIR}/runroot"
39+
# Pull registry image, but into a separate container storage and DB and everything
40+
PODMAN_LOGIN_ARGS="--storage-driver vfs $(podman_isolation_opts ${PODMAN_LOGIN_WORKDIR})"
3541
# _prefetch() will retry twice on network error, and will also use
3642
# a pre-cached image if present (helpful on dev workstation, not in CI).
3743
_PODMAN_TEST_OPTS="${PODMAN_LOGIN_ARGS}" _prefetch $REGISTRY_IMAGE
@@ -86,14 +92,9 @@ function stop_registry() {
8692
skip "[leaving registry running by request]"
8793
fi
8894

89-
run_podman --storage-driver vfs \
90-
--root ${PODMAN_LOGIN_WORKDIR}/root \
91-
--runroot ${PODMAN_LOGIN_WORKDIR}/runroot \
92-
rm -f -t0 registry
93-
run_podman --storage-driver vfs \
94-
--root ${PODMAN_LOGIN_WORKDIR}/root \
95-
--runroot ${PODMAN_LOGIN_WORKDIR}/runroot \
96-
rmi -a -f
95+
opts="--storage-driver vfs $(podman_isolation_opts ${PODMAN_LOGIN_WORKDIR})"
96+
run_podman $opts rm -f -t0 registry
97+
run_podman $opts rmi -a -f
9798

9899
# By default, clean up
99100
if [ -z "${PODMAN_TEST_KEEP_LOGIN_WORKDIR}" ]; then

test/system/setup_suite.bash

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ load helpers.registry
1111
# Create common environment just in case we end up needing a registry.
1212
# These environment variables will be available to all tests.
1313
function setup_suite() {
14+
# FIXME: 2023-12-13: https://github.com/bats-core/bats-core/issues/812
15+
# Running 'bats --filter-tags' sets IFS=',' which ... ugh. Not fun to debug.
16+
# The line below is newline, space, tab.
17+
IFS="
18+
"
19+
1420
# Can't use $BATS_SUITE_TMPDIR because podman barfs:
1521
# Error: the specified runroot is longer than 50 characters
1622
export PODMAN_LOGIN_WORKDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-${TMPDIR:-/tmp}} podman-bats-registry.XXXXXX)
@@ -21,6 +27,10 @@ function setup_suite() {
2127
# FIXME: racy! It could be many minutes between now and when we start it.
2228
# To mitigate, we use a range not used anywhere else in system tests.
2329
export PODMAN_LOGIN_REGISTRY_PORT=$(random_free_port 42000-42999)
30+
31+
# The above does not handle errors. Do a final confirmation.
32+
assert "$PODMAN_LOGIN_REGISTRY_PORT" != "" \
33+
"Unable to set PODMAN_LOGIN_REGISTRY_PORT"
2434
}
2535

2636
# Run at the very end of all tests. Useful for cleanup of non-BATS tmpdirs.

0 commit comments

Comments
 (0)