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

Quadlet - make sure the /etc/containers/systemd/users is traversed in rootless #24815

Conversation

ygalblum
Copy link
Contributor

Does this PR introduce a user-facing change?

No

None

Resolves: #24783

@openshift-ci openshift-ci bot added release-note-none approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 10, 2024
@ygalblum
Copy link
Contributor Author

I'm not sure how to test this. The problem is that creating folders under /etc/containers/systemd/users requires root privileges

@vrothberg
Copy link
Member

I'm not sure how to test this. The problem is that creating folders under /etc/containers/systemd/users requires root privileges

That's usually done via env vars. Could you use QUADLET_UNIT_DIRS for the tests and point it to a directory the tests control? Besides the permission issue, I wouldn't want tests writing to /etc/ if possible.

@Luap99
Copy link
Member

Luap99 commented Dec 11, 2024

QUADLET_UNIT_DIRS

I don't think this can help here, it will not trigger the code path in question here as this does not change the root.

I think for testing it may be possible to run quadlet in a container where we can have full control over all dirs or just chroot() may be enough? But it still is no clear to me how we could integrate this into the existing e2e test.

@ygalblum
Copy link
Contributor Author

Yes, @Luap99 is correct. When QUADLET_UNIT_DIRS is set, the changed code is not reached.
@edsantiago can you think of a way to test this?
The problem is that the code in question traverses directories under /etc/containers/systemd which the test code cannot change (without root permissions)

@edsantiago
Copy link
Member

Containerized e2e could be a safe way to test, but not trivial (test fixtures would need to be set up outside the test itself). And, sorry, I can't remember if we run rootless containerized.

@Luap99
Copy link
Member

Luap99 commented Dec 12, 2024

Maybe in the e2e test instead of calling quadlet on the host we can wrap it in a container like this:

podman run --rm -v /:/host:ro -v /tmp/test/:/host/etc/containers/systemd:Z  quay.io/libpod/testimage:20241011 chroot /host /usr/libexec/podman/quadlet -dryrun

Where /tmp/test is the source of the quadlet files, that seems to work and we have full control where to place the files.
And with the podman run command we can test rootless by adding --user 1000:1000 so we even have a stable uid to check the uid matching logic as well.

@ygalblum
Copy link
Contributor Author

I've tried running this containerized, but I still see issues. While I would like to explore the idea, can we still merge this PR (by skipping the new tests requirement) as it does fix a real issue?

@Luap99
Copy link
Member

Luap99 commented Jan 7, 2025

Yeah if there is no easy way I am fine to bypass the test requirement.

Although I just touched the quadlet unit tests and there seems to be some chroot logic in there so maybe something can be done there, thought not sure.
https://github.com/containers/podman/blob/main/cmd/quadlet/main_test.go

@ygalblum ygalblum force-pushed the quadlet-traverse-base-users-dir branch from 4c238aa to 0b3ad66 Compare January 7, 2025 19:52
@ygalblum
Copy link
Contributor Author

ygalblum commented Jan 7, 2025

@Luap99 Thanks a lot for this pointer. I didn't notice it before. I added some more tests to the unit tests (with some cleanup of code duplication)

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

createDir := func(path, name string) string {
dirName := filepath.Join(path, name)
err = os.Mkdir(dirName, 0755)
assert.Nil(t, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking as it is pre existing and done in way to many other places but error checks should be done with
assert.NoError() because that prints a better message when it fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just copy pasted the code. I see that it's being fixed in #24974

Copy link
Contributor

openshift-ci bot commented Jan 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, ygalblum

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhatdan
Copy link
Member

rhatdan commented Jan 8, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 8, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 4593f8d into containers:main Jan 8, 2025
80 checks passed
@ygalblum ygalblum deleted the quadlet-traverse-base-users-dir branch January 8, 2025 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quadlets in subfolders not generated
5 participants