Skip to content

Commit 2b36e6e

Browse files
committed
CI: unprivileged in-container tasks
Add unprivileged versions of the test-in-a-container task that help ensure that we're not missing expected functionality. Test with both overlay and regular vfs when unprivileged. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent e4874ed commit 2b36e6e

18 files changed

+320
-75
lines changed

.cirrus.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ non_blocking_integration_rootless_task:
389389
<<: *standardlogs
390390

391391
in_podman_task:
392-
name: "Containerized Integration"
392+
name: "Containerized Integration (privileged=$PODMAN_PRIVILEGED) w/ $STORAGE_DRIVER"
393393
alias: in_podman
394394
skip: *not_build_docs
395395
depends_on: *smoke_vendor
@@ -398,11 +398,25 @@ in_podman_task:
398398
cpu: 8
399399
memory: "8G"
400400

401-
env:
402-
# This is key, cause the scripts to re-execute themselves inside a container.
403-
IN_PODMAN: 'true'
404-
BUILDAH_ISOLATION: 'chroot'
405-
STORAGE_DRIVER: 'vfs'
401+
matrix:
402+
- env:
403+
# Setting IN_PODMAN tells the scripts to re-execute themselves inside a container.
404+
IN_PODMAN: 'true'
405+
BUILDAH_ISOLATION: 'chroot'
406+
STORAGE_DRIVER: 'vfs'
407+
PODMAN_PRIVILEGED: 'true'
408+
- env:
409+
# Setting IN_PODMAN tells the scripts to re-execute themselves inside a container.
410+
IN_PODMAN: 'true'
411+
BUILDAH_ISOLATION: 'chroot'
412+
STORAGE_DRIVER: 'vfs'
413+
PODMAN_PRIVILEGED: 'false'
414+
- env:
415+
# Setting IN_PODMAN tells the scripts to re-execute themselves inside a container.
416+
IN_PODMAN: 'true'
417+
BUILDAH_ISOLATION: 'chroot'
418+
STORAGE_DRIVER: 'overlay'
419+
PODMAN_PRIVILEGED: 'false'
406420

407421
# Separate scripts for separate outputs, makes debugging easier.
408422
setup_script: '${SCRIPT_BASE}/setup.sh |& ${_TIMESTAMP}'

contrib/cirrus/lib.sh

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,30 @@ REGISTRY_FQIN=${REGISTRY_FQIN:-quay.io/libpod/registry:2.8.2}
100100
ALPINE_FQIN=${ALPINE_FQIN:-quay.io/libpod/alpine}
101101

102102
# for in-container testing
103-
IN_PODMAN_NAME="in_podman_$CIRRUS_TASK_ID"
103+
podman_privilege_level() {
104+
if [[ "$PODMAN_PRIVILEGED" == "false" ]] ; then
105+
echo unprivileged
106+
else
107+
echo privileged
108+
fi
109+
}
110+
podman_cgroup_flags() {
111+
# fixme: eventually test unprivileged with these flags, too;
112+
# as of 20215-08-15, selinux policy has the host's cgroupfs
113+
# as system_u:object_r:cgroup_t:s0 and container_t can't
114+
# 'remount' it, even if only to make it read-only
115+
if [[ $(podman_privilege_level) == privileged ]] ; then
116+
echo --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw
117+
fi
118+
}
119+
podman_privileged_flag() {
120+
if [[ $(podman_privilege_level) == privileged ]] ; then
121+
echo --privileged
122+
fi
123+
}
124+
125+
PODMAN_PRIVILEGE_LEVEL=$(podman_privilege_level)
126+
IN_PODMAN_NAME="in_podman_${PODMAN_PRIVILEGE_LEVEL}_$CIRRUS_TASK_ID"
104127
IN_PODMAN="${IN_PODMAN:-false}"
105128

106129
# rootless_user
@@ -194,19 +217,18 @@ in_podman() {
194217

195218
showrun podman run -i --name="$IN_PODMAN_NAME" \
196219
--net=host \
197-
--privileged \
198-
--cgroupns=host \
220+
$(podman_privileged_flag) \
221+
$(podman_cgroup_flags) \
199222
"${envargs[@]}" \
200223
-e BUILDAH_ISOLATION \
201224
-e STORAGE_DRIVER \
202225
-e "IN_PODMAN=false" \
203226
-e "CONTAINER=podman" \
204227
-e "CGROUP_MANAGER=cgroupfs" \
205228
-v "$HOME/auth:$HOME/auth:ro,z" \
206-
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
207229
-v "/etc/containers/certs.d:/etc/containers/certs.d:O" \
208230
--device /dev/fuse:rwm \
209-
-v "$GOSRC:$GOSRC:z" \
231+
-v "$GOSRC:$GOSRC:U,z" \
210232
--workdir "$GOSRC" \
211233
"$@"
212234
}
@@ -215,26 +237,26 @@ verify_local_registry(){
215237
# On the unexpected/rare chance of a name-clash
216238
local CUSTOM_FQIN=localhost:5000/my-alpine-$RANDOM
217239
echo "Verifying local 'registry' container is operational"
218-
showrun podman version
219-
showrun podman info
220-
showrun podman ps --all
221-
showrun podman images
240+
showrun buildah version
241+
showrun buildah --log-level=debug info
242+
showrun buildah ps --all
243+
showrun buildah images
222244
showrun ls -alF $HOME/auth
223245
mkdir -p /etc/containers/certs.d/localhost:5000
224246
cp -v $HOME/auth/domain.crt /etc/containers/certs.d/localhost:5000/ca.crt
225-
showrun podman pull $ALPINE_FQIN
226-
showrun podman login localhost:5000 --username testuser --password testpassword
227-
showrun podman tag $ALPINE_FQIN $CUSTOM_FQIN
228-
showrun podman push --creds=testuser:testpassword $CUSTOM_FQIN
229-
showrun podman ps --all
230-
showrun podman images
231-
showrun podman rmi $ALPINE_FQIN
232-
showrun podman rmi $CUSTOM_FQIN
233-
showrun podman pull --creds=testuser:testpassword $CUSTOM_FQIN
234-
showrun podman ps --all
235-
showrun podman images
247+
showrun buildah pull $ALPINE_FQIN
248+
showrun buildah login localhost:5000 --username testuser --password testpassword
249+
showrun buildah tag $ALPINE_FQIN $CUSTOM_FQIN
250+
showrun buildah push --creds=testuser:testpassword $CUSTOM_FQIN
251+
showrun buildah ps --all
252+
showrun buildah images
253+
showrun buildah rmi $ALPINE_FQIN
254+
showrun buildah rmi $CUSTOM_FQIN
255+
showrun buildah pull --creds=testuser:testpassword $CUSTOM_FQIN
256+
showrun buildah ps --all
257+
showrun buildah images
236258
echo "Success, local registry is working, cleaning up."
237-
showrun podman rmi $CUSTOM_FQIN
259+
showrun buildah rmi $CUSTOM_FQIN
238260
}
239261

240262
execute_local_registry() {
@@ -262,7 +284,7 @@ execute_local_registry() {
262284

263285
echo "Starting up the local 'registry' container"
264286
showrun podman run -d -p 5000:5000 --name registry \
265-
-v $authdirpath:$authdirpath:Z \
287+
-v $authdirpath:$authdirpath:ro,z \
266288
-e "REGISTRY_AUTH=htpasswd" \
267289
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
268290
-e REGISTRY_AUTH_HTPASSWD_PATH=$authdirpath/htpasswd \

contrib/cirrus/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ req_env_vars OS_RELEASE_ID OS_RELEASE_VER GOSRC IN_PODMAN_IMAGE CIRRUS_CHANGE_TI
1313
msg "Running df."
1414
df -hT
1515

16+
msg "Showing /proc/self/mountinfo."
17+
cat /proc/self/mountinfo
18+
1619
msg "Disabling git repository owner-check system-wide."
1720
# Newer versions of git bark if repo. files are unexpectedly owned.
1821
# This mainly affects rootless and containerized testing. But

tests/add.bats

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ load helpers
1414
}
1515

1616
@test "add-local-plain" {
17+
skip_if_unable_to_mount
18+
1719
createrandom ${TEST_SCRATCH_DIR}/randomfile
1820
createrandom ${TEST_SCRATCH_DIR}/other-randomfile
1921

@@ -59,6 +61,8 @@ load helpers
5961
}
6062

6163
@test "add-local-archive" {
64+
skip_if_unable_to_mount
65+
6266
createrandom ${TEST_SCRATCH_DIR}/randomfile
6367
createrandom ${TEST_SCRATCH_DIR}/other-randomfile
6468

@@ -201,6 +205,8 @@ load helpers
201205
}
202206

203207
@test "add --ignorefile" {
208+
skip_if_unable_to_mount
209+
204210
mytest=${TEST_SCRATCH_DIR}/mytest
205211
mkdir -p ${mytest}
206212
touch ${mytest}/mystuff
@@ -234,6 +240,8 @@ stuff/mystuff"
234240
}
235241

236242
@test "add quietly" {
243+
skip_if_unable_to_mount
244+
237245
_prefetch busybox
238246
createrandom ${TEST_SCRATCH_DIR}/randomfile
239247
run_buildah from --quiet $WITH_POLICY_JSON busybox
@@ -246,6 +254,8 @@ stuff/mystuff"
246254
}
247255

248256
@test "add from container" {
257+
skip_if_unable_to_mount
258+
249259
_prefetch busybox
250260
createrandom ${TEST_SCRATCH_DIR}/randomfile
251261
run_buildah from --quiet $WITH_POLICY_JSON busybox
@@ -265,6 +275,8 @@ stuff/mystuff"
265275
}
266276

267277
@test "add from image" {
278+
skip_if_unable_to_mount
279+
268280
_prefetch busybox ubuntu
269281
run_buildah from --quiet $WITH_POLICY_JSON busybox
270282
cid=$output
@@ -394,26 +406,28 @@ EOF
394406
}
395407

396408
@test "add-link-flag" {
409+
skip_if_unable_to_mount
410+
397411
createrandom ${TEST_SCRATCH_DIR}/randomfile
398412
createrandom ${TEST_SCRATCH_DIR}/other-randomfile
399413

400414
run_buildah from $WITH_POLICY_JSON scratch
401415
cid=$output
402416
run_buildah mount $cid
403417
root=$output
404-
418+
405419
run_buildah config --workingdir=/ $cid
406-
420+
407421
# Test 1: Simple add
408422
run_buildah add --link $cid ${TEST_SCRATCH_DIR}/randomfile
409-
423+
410424
# Test 2: Add with rename (file to file with different name)
411425
run_buildah add --link $cid ${TEST_SCRATCH_DIR}/randomfile /renamed-file
412-
426+
413427
# Test 3: Multiple files to directory
414428
mkdir $root/subdir
415429
run_buildah add --link $cid ${TEST_SCRATCH_DIR}/randomfile ${TEST_SCRATCH_DIR}/other-randomfile /subdir
416-
430+
417431
run_buildah unmount $cid
418432
run_buildah commit $WITH_POLICY_JSON $cid add-link-image
419433

@@ -430,34 +444,36 @@ EOF
430444
newcid=$output
431445
run_buildah mount $newcid
432446
newroot=$output
433-
447+
434448
test -s $newroot/randomfile
435449
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/randomfile
436-
450+
437451
test -s $newroot/renamed-file
438452
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/renamed-file
439-
453+
440454
test -s $newroot/subdir/randomfile
441455
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/subdir/randomfile
442456
test -s $newroot/subdir/other-randomfile
443457
cmp ${TEST_SCRATCH_DIR}/other-randomfile $newroot/subdir/other-randomfile
444458
}
445459

446460
@test "add-link-archive" {
461+
skip_if_unable_to_mount
462+
447463
createrandom ${TEST_SCRATCH_DIR}/file1
448464
createrandom ${TEST_SCRATCH_DIR}/file2
449-
465+
450466
tar -c -C ${TEST_SCRATCH_DIR} -f ${TEST_SCRATCH_DIR}/archive.tar file1 file2
451467

452468
run_buildah from $WITH_POLICY_JSON scratch
453469
cid=$output
454-
470+
455471
run_buildah config --workingdir=/ $cid
456-
472+
457473
run_buildah add --link $cid ${TEST_SCRATCH_DIR}/archive.tar
458-
474+
459475
run_buildah add --link $cid ${TEST_SCRATCH_DIR}/archive.tar /destdir/
460-
476+
461477
run_buildah commit $WITH_POLICY_JSON $cid add-link-archive-image
462478

463479
run_buildah inspect --type=image add-link-archive-image
@@ -471,41 +487,43 @@ EOF
471487
newcid=$output
472488
run_buildah mount $newcid
473489
newroot=$output
474-
490+
475491
test -s $newroot/file1
476492
cmp ${TEST_SCRATCH_DIR}/file1 $newroot/file1
477493
test -s $newroot/file2
478494
cmp ${TEST_SCRATCH_DIR}/file2 $newroot/file2
479-
495+
480496
test -s $newroot/destdir/file1
481497
cmp ${TEST_SCRATCH_DIR}/file1 $newroot/destdir/file1
482498
test -s $newroot/destdir/file2
483499
cmp ${TEST_SCRATCH_DIR}/file2 $newroot/destdir/file2
484500
}
485501

486502
@test "add-link-directory" {
503+
skip_if_unable_to_mount
504+
487505
mkdir -p ${TEST_SCRATCH_DIR}/testdir/subdir
488506
createrandom ${TEST_SCRATCH_DIR}/testdir/file1
489507
createrandom ${TEST_SCRATCH_DIR}/testdir/subdir/file2
490508

491509
run_buildah from $WITH_POLICY_JSON scratch
492510
cid=$output
493-
511+
494512
run_buildah config --workingdir=/ $cid
495-
513+
496514
run_buildah add --link $cid ${TEST_SCRATCH_DIR}/testdir /testdir
497-
515+
498516
run_buildah commit $WITH_POLICY_JSON $cid add-link-dir-image
499517

500518
run_buildah from $WITH_POLICY_JSON add-link-dir-image
501519
newcid=$output
502520
run_buildah mount $newcid
503521
newroot=$output
504-
522+
505523
test -d $newroot/testdir
506524
test -s $newroot/testdir/file1
507525
test -s $newroot/testdir/subdir/file2
508-
526+
509527
cmp ${TEST_SCRATCH_DIR}/testdir/file1 $newroot/testdir/file1
510528
cmp ${TEST_SCRATCH_DIR}/testdir/subdir/file2 $newroot/testdir/subdir/file2
511529
}

tests/basic.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ load helpers
3636
}
3737

3838
@test "mount" {
39+
skip_if_unable_to_mount
40+
3941
run_buildah from $WITH_POLICY_JSON scratch
4042
cid=$output
4143
run_buildah mount $cid
@@ -49,6 +51,8 @@ load helpers
4951
}
5052

5153
@test "by-name" {
54+
skip_if_unable_to_mount
55+
5256
run_buildah from $WITH_POLICY_JSON --name scratch-working-image-for-test scratch
5357
cid=$output
5458
run_buildah mount scratch-working-image-for-test
@@ -58,6 +62,8 @@ load helpers
5862
}
5963

6064
@test "commit" {
65+
skip_if_unable_to_mount
66+
6167
createrandom ${TEST_SCRATCH_DIR}/randomfile
6268
createrandom ${TEST_SCRATCH_DIR}/other-randomfile
6369

0 commit comments

Comments
 (0)