Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use "become" image to fix sudo-related trouble in /tests/provision/user #2892

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ images: ## Build tmt images for podman/docker
podman build -t tmt --squash -f ./containers/Containerfile.mini .
podman build -t tmt-all --squash -f ./containers/Containerfile.full .

images-unit-tests: image-unit-tests-alpine image-unit-tests-coreos ## Build images for unit tests
images-unit-tests: image-unit-tests-alpine image-unit-tests-coreos image/tests/fedora/rawhide/unprivileged ## Build images for unit tests

image-unit-tests-alpine: ## Build local alpine image for unit tests
podman build -t alpine:$(UNIT_TESTS_IMAGE_TAG) -f ./containers/Containerfile.alpine .

image-unit-tests-coreos: ## Build local CoreOS image for unit tests
podman build -t fedora-coreos:$(UNIT_TESTS_IMAGE_TAG) -f ./containers/Containerfile.coreos .

image/tests/fedora/rawhide/unprivileged: ## Build local Fedora image with unprivileged account and sudo
podman build -t fedora/rawhide/unprivileged:$(UNIT_TESTS_IMAGE_TAG) -f ./containers/fedora/rawhide/Containerfile.unprivileged .

##
## Development
##
Expand Down
11 changes: 11 additions & 0 deletions containers/fedora/rawhide/Containerfile.unprivileged
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# A custom Fedora rawhide image, with unprivieged account & password-less sudo
#

FROM quay.io/fedora/fedora:rawhide

RUN useradd fedora \
&& usermod -aG wheel fedora \
&& echo -e 'fedora\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers

USER fedora
2 changes: 1 addition & 1 deletion tests/provision/become/data/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ adjust:
- when: provisiontest == container
provision+:
how: container
image: localhost/become-container-test:latest
image: localhost/fedora/rawhide/unprivileged:tmt-unit-tests

execute:
how: tmt
7 changes: 2 additions & 5 deletions tests/provision/become/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
rlJournalStart
rlPhaseStartSetup
rlRun "PROVISION_HOW=${PROVISION_HOW:-container}"
rlRun "pushd data"
if [[ "$PROVISION_HOW" == "container" ]]; then
# Try several times to build the container
# https://github.com/teemtee/tmt/issues/2063
build="podman build -t become-container-test:latest ."
build="make -C ../../../ image/tests/fedora/rawhide/unprivileged"
rlRun "rlWaitForCmd '$build' -m 5 -d 5" || rlDie "Unable to prepare the image"
fi
rlRun "pushd data"
rlPhaseEnd

rlPhaseStartTest "$PROVISION_HOW, test with become=true"
Expand Down Expand Up @@ -45,8 +45,5 @@ rlJournalStart

rlPhaseStartCleanup
rlRun "popd"
if [[ "$PROVISION_HOW" == "container" ]]; then
rlRun "podman image rm -f localhost/become-container-test:latest" 0 "Remove custom image"
fi
rlPhaseEnd
rlJournalEnd
14 changes: 6 additions & 8 deletions tests/provision/user/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "$PROVISION_HOW, set specific user"
if [ "$PROVISION_HOW" = "virtual" ]; then
user="fedora"
ids="1000"
else
user="nobody"
ids="65534"
image=""

if [ "$PROVISION_HOW" = "container" ]; then
image="--image localhost/fedora/rawhide/unprivileged:tmt-unit-tests"
fi

rlRun -s "tmt run --scratch -i $run -a provision --how $PROVISION_HOW --user $user report -vvv"
rlAssertGrep "uid=$ids($user) gid=$ids($user) groups=$ids($user)" $rlRun_LOG
rlRun -s "tmt run --scratch -i $run -a provision --how $PROVISION_HOW $image --user fedora report -vvv"
rlAssertGrep "uid=1000(fedora) gid=1000(fedora) groups=1000(fedora)" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
Expand Down
Loading