Skip to content

Conversation

vrothberg
Copy link
Member

@vrothberg vrothberg commented Aug 9, 2023

Support a new concept in containers.conf called "modules". A "module"
is a containers.conf file located at a specific directory. More than
one module can be loaded in the specified order, following existing
override semantics.

There are three directories to load modules from:

  • $CONFIG_HOME/containers/containers.conf.modules
  • /etc/containers/containers.conf.modules
  • /usr/share/containers/containers.conf.modules

With CONFIG_HOME pointing to $HOME/.config or, if set, $XDG_CONFIG_HOME.
Absolute paths will be loaded as is, relative paths will be resolved
relative to the three directories above allowing for admin configs
(/etc/) to override system configs (/usr/share/) and user configs
($CONFIG_HOME) to override admin configs.

Pulls in containers/common/pull/1599.

Does this PR introduce a user-facing change?

Add a new --module flag for Podman on Linux.

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels Aug 9, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 9, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vrothberg

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2023
@vrothberg vrothberg force-pushed the RUN-1873 branch 2 times, most recently from 64d51d2 to 46ed95e Compare August 10, 2023 09:53
@vrothberg
Copy link
Member Author

@Luap99 @rhatdan @edsantiago WDYT?

@vrothberg
Copy link
Member Author

vrothberg commented Aug 10, 2023

@Luap99 any idea why I am observing the following in shell completion?

podman (RUN-1873) $ ./bin/podman --module
sub/sub.conf  test.conf     

podman (RUN-1873) $ ./bin/podman --module t
test/               transfer.md         troubleshooting.md 

Above it's perfectly capable of detecting the files in the XDG_CONFIG_HOME but it's unable to complete and will pick a path in CWD instead.

EDIT need to fix your comment before and will retry.

@Luap99
Copy link
Member

Luap99 commented Aug 10, 2023

Another problem I just realized, I think we must pass --module this down to the cleanup command to ensure [engine] options are the same for the cleanup process and the one that started the container. For example it would be very important to call the right oci runtime if one was set in a module.

Now doing this sounds easy but there is one big problem with that, if a user starts a container with a module then removes the module file, the cleanup command will fail immediately without doing anything which will be very problematic. Now this is of course a corner case but one that could be impossible to debug as there are almost never logs from the cleanup command. I think there are other cases were this is already a problem, i.e. adding a options that fail config validation so this is not exactly a new problem but one to keep in mind.
So maybe it is fine for now to accept this risk but I think we need a design for a more fault tolerant cleanup process.

@edsantiago
Copy link
Member

A weird thing happened when I tried testing completion:

$ mkdir -p /tmp/fakehome/.config/containers/containers.conf.modules
$ touch /tmp/fakehome/.config/containers/containers.conf.modules/sdfsdf.conf

$ XDG_CONFIG_HOME=/tmp/fakehome/.config bin/podman __completeNoDesc --module ''
sdfsdf.conf            <------- this is good
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

$ XDG_CONFIG_HOME=/tmp/fakehome/.config bin/podman __completeNoDesc --module 'x'
Failed to obtain podman configuration: could not resolve module "x": 3 errors occurred:
        * stat /tmp/fakehome/.config/containers/containers.conf.modules/x: no such file or directory
        * stat /etc/containers/containers.conf.modules/x: no such file or directory
        * stat /usr/share/containers/containers.conf.modules/x: no such file or directory

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

This is way more than I can possibly review, so I just focused on some super-minor nits in tests. Will make another review pass later.

@vrothberg
Copy link
Member Author

A weird thing happened when I tried testing completion:

Nice catch, Ed. Thank you! I think that explains my observation as well. Explanation: modules should not be loaded during shell completion.

@vrothberg
Copy link
Member Author

Pushed a new version with the comments addressed. Still not ready to go but I'll be buried in meetings for a while.

@vrothberg
Copy link
Member Author

vrothberg commented Aug 10, 2023

So maybe it is fine for now to accept this risk but I think we need a design for a more fault tolerant cleanup process.

I honestly never thought of it before but see how this can cause hard to debug issues. Mind opening an issue for it?

@openshift-ci openshift-ci bot added release-note and removed do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels Aug 10, 2023
@vrothberg vrothberg changed the title WIP: add --module flag add --module flag Aug 10, 2023
@vrothberg
Copy link
Member Author

@rhatdan @Luap99 @edsantiago PTanotherL

Once I have your blessings, we can merge containers/common#1599 and properly vendor c/common in here.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2023
@Luap99
Copy link
Member

Luap99 commented Aug 11, 2023

Another problem I just realized, I think we must pass --module this down to the cleanup command to ensure [engine] options are the same for the cleanup process and the one that started the container. For example it would be very important to call the right oci runtime if one was set in a module.

This is still open and important, especially when a container uses --restart=always.

@Luap99
Copy link
Member

Luap99 commented Aug 11, 2023

Also I see no mentions in the docs that --module is not supported on the remote client.

@vrothberg
Copy link
Member Author

This is still open and important, especially when a container uses --restart=always.

Thanks! I will add that. Can you elaborate on the --restart=always case? What could break? I don't find something from the top of my head but an example may even be helpful for a test.

@Luap99
Copy link
Member

Luap99 commented Aug 11, 2023

Can you elaborate on the --restart=always case? What could break?

For example host_containers_internal_ip can only be set in containers.conf and will effect the generated /etc/hosts in the container. Because that option is not stored in the container config it will only be read when we write /etc/hosts. Now we write /etc/hosts on each container start so the one restarted from within the cleanup process could result in a different hosts file which would be bad. I am sure there are more options that would be effected by this.

@vrothberg
Copy link
Member Author

This is still open and important, especially when a container uses --restart=always.

Done ✔️

Also added a regression test: https://github.com/containers/podman/pull/19567/files#diff-07cf7ec60df1f145e45014e0a31d374cde4b1fb4f28cf3999c4e13293b6dc541R127-R131

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2023
@edsantiago
Copy link
Member

Fresh thought: do we need to worry/care about people who try sudo podman --module X with X in their homedir? Probably not a problem for the original requesters, but we have no way of knowing who will be using this.

Was any consideration given to using .d for the new modules directory?

What is the reason for /usr/share/...? The only one I can imagine is for a distro to include preconfigured modules... which sounds kind of alarming TBH. Has that been fully thought out?

@edsantiago
Copy link
Member

Would you consider adding a few more tests?

You also might want to fix some stutter. One of them should be easy, the other, not so much.

@vrothberg
Copy link
Member Author

vrothberg commented Aug 16, 2023

Fresh thought: do we need to worry/care about people who try sudo podman --module X with X in their homedir? Probably not a problem for the original requesters, but we have no way of knowing who will be using this.

HOME is always ignored by Podman when running as root. I think modules should remain consistent with that.

Was any consideration given to using .d for the new modules directory?

Yes. Mixing with .d breaks separation of concerns. .d configs are always loaded and modules should only be loaded on demand, so we needed a new directory to avoid user errors.

What is the reason for /usr/share/...? The only one I can imagine is for a distro to include preconfigured modules... which sounds kind of alarming TBH.

You are right on spot. Imagine an nvidia.conf module being shipped in an RP

Has that been fully thought out?

I hope so. I mean at that point we had weeks of conversations with the requester, a reviewed design document and the other PR in containers/common. If you don't feel comfortable with the current implementation, please block before merging the PR.

Would you consider adding a few more tests?

Will do, thanks a lot!

@vrothberg vrothberg marked this pull request as ready for review August 16, 2023 08:49
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 16, 2023
@vrothberg
Copy link
Member Author

Now vendoring c/common@main.

@rhatdan @Luap99 PTanotherL
Let's not merge without @edsantiago's blessing

@edsantiago
Copy link
Member

Fresh thought: do we need to worry/care about people who try sudo podman --module X with X in their homedir?

HOME is always ignored by Podman when running as root. I think modules should remain consistent with that.

Sorry, I didn't express myself right. I was thinking of someone creating ~/..../module/foo, using --module foo, then later (after they've grown used to it, and forgotten that it's in their homedir) trying sudo podman --module foo and getting a surprise. IMO sudo podman has enough surprises already, one more is not a big deal. I just want to make sure we're aware of this beforehand.

Please don't gate on me. I'm really uncomfortable with this concept, but tests LGTM (thanks for adding those) and I can't find any specific showstoppers.

@vrothberg
Copy link
Member Author

Sorry, I didn't express myself right. I was thinking of someone creating ~/..../module/foo, using --module foo, then later (after they've grown used to it, and forgotten that it's in their homedir) trying sudo podman --module foo and getting a surprise. IMO sudo podman has enough surprises already, one more is not a big deal. I just want to make sure we're aware of this beforehand.

I am curious what others think. So far, rootful Podman ignores all rootless configs. Same for other tools ignoring settings in XDG_CONFIG_HOME.

@vrothberg
Copy link
Member Author

I don't understand the Windows error (https://github.com/containers/podman/pull/19567/checks?check_run_id=15935251777). @Luap99 @edsantiago do you know what's going on?

@Luap99
Copy link
Member

Luap99 commented Aug 16, 2023

I don't understand the Windows error (https://github.com/containers/podman/pull/19567/checks?check_run_id=15935251777). @Luap99 @edsantiago do you know what's going on?

c/common changed the machine defaults, I think you need to merge + rebase onto #19596

@Luap99
Copy link
Member

Luap99 commented Aug 16, 2023

Sorry, I didn't express myself right. I was thinking of someone creating ~/..../module/foo, using --module foo, then later (after they've grown used to it, and forgotten that it's in their homedir) trying sudo podman --module foo and getting a surprise. IMO sudo podman has enough surprises already, one more is not a big deal. I just want to make sure we're aware of this beforehand.

I am curious what others think. So far, rootful Podman ignores all rootless configs. Same for other tools ignoring settings in XDG_CONFIG_HOME.

I don't understand the issue here, sudo is running as root so of course it should ignore rootless configurations. I don't see surprise factor? Like would you expect sudo vim to load the rootless .vimrc? To me the behaviour of ignoring rootless configurations when running as root is the normal expected thing.

Support a new concept in containers.conf called "modules".  A "module"
is a containers.conf file located at a specific directory.  More than
one module can be loaded in the specified order, following existing
override semantics.

There are three directories to load modules from:
 - $CONFIG_HOME/containers/containers.conf.modules
 - /etc/containers/containers.conf.modules
 - /usr/share/containers/containers.conf.modules

With CONFIG_HOME pointing to $HOME/.config or, if set, $XDG_CONFIG_HOME.
Absolute paths will be loaded as is, relative paths will be resolved
relative to the three directories above allowing for admin configs
(/etc/) to override system configs (/usr/share/) and user configs
($CONFIG_HOME) to override admin configs.

Pulls in containers/common/pull/1599.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
@edsantiago
Copy link
Member

It's not about what I expect, it's about end users. We seem to get frequent "sudo doesn't work" questions, and this is just one more thing for less-experienced users to trip on. Anyhow, enough. We can live with that.

@vrothberg
Copy link
Member Author

OK, we're green.

@rhatdan
Copy link
Member

rhatdan commented Aug 16, 2023

LGTM

@baude
Copy link
Member

baude commented Aug 16, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2023
@openshift-merge-robot openshift-merge-robot merged commit f559fc5 into containers:main Aug 16, 2023
@vrothberg vrothberg deleted the RUN-1873 branch August 17, 2023 08:22
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Nov 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants