Skip to content

Conversation

@gportay
Copy link
Contributor

@gportay gportay commented Mar 21, 2025

The docker client requires to run as root in rootfull mode. The docker
group allows a user to access to the Unix socket created by the docker
daemon.

The user needs to run docker client with more privileges (i.e. sudo) if
it is not part of that group1.

This prepends sudo to CQFD_DOCKER automatically if CQFD_RUN_WITH_SUDO is
set to true. It turns the internal variable cqfd_docket into an array to
split the command into pieces ("sudo docker" -> "sudo" and "docker").

@gportay
Copy link
Contributor Author

gportay commented Mar 21, 2025

What your thought on this?

@felixlechat1
Copy link
Contributor

Looks good to me, I think it makes sense to have the feature be a separate environment variable. Maybe just update the CQFD_DOCKER readme section to not suggest using sudo there, rather in the new CQFD_RUN_WITH_SUDO variable.

I like the idea of switching to USER sooner instead of using a builder user. Are there any implications to not have that separate builder user for the first few steps of cqfd? Couldn't find any on my side.

@gportay
Copy link
Contributor Author

gportay commented Mar 21, 2025

Maybe just update the CQFD_DOCKER readme section to not suggest using sudo there, rather in the new CQFD_RUN_WITH_SUDO variable.

Oh good catch!

In fact, I would like to update to

I like the idea of switching to USER sooner instead of using a builder user. Are there any implications to not have that separate builder user for the first few steps of cqfd? Couldn't find any on my side.

I have seen none.

In fact I would have choose the user cqfd instead of builder :)

@florentsfl
Copy link
Contributor

At first, I would think that it is a good idea if sudo is left explicit so the user always remember that they are using sudo.

But it is indeed more practical if sudo is included in cqfd.

@gportay
Copy link
Contributor Author

gportay commented Mar 24, 2025

At first, I would think that it is a good idea if sudo is left explicit so the user always remember that they are using sudo.

And now, I am convinced you were right, and I was wrong to automatically default to sudo if user is not a member of the docker group.

But it is indeed more practical if sudo is included in cqfd.

And yes it would be practical but since docker rootless support is almost merged, with podman, it could be annoying to disable sudo for setup that creates an alias for docker (alias docker=podman). Podman does not need to run as sudo, right?

@florentsfl
Copy link
Contributor

podman does not require sudo indeed

@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch from ed5dd42 to 1916021 Compare March 24, 2025 20:24
@florentsfl
Copy link
Contributor

honestly I liked the cqfd_user_home name, because with cqfd_home it sounds like it is the home of cqfd

With cqfd_user_home it is clear that this represents the home of the user invoking cqfd

What do you think about that ?

@gportay
Copy link
Contributor Author

gportay commented Apr 1, 2025

honestly I liked the cqfd_user_home name, because with cqfd_home it sounds like it is the home of cqfd

With cqfd_user_home it is clear that this represents the home of the user invoking cqfd

What do you think about that ?

This is why I suggested to remove the cqfd_ prefix as well.

@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch 2 times, most recently from b99d111 to 70767e0 Compare April 11, 2025 11:57
@gportay
Copy link
Contributor Author

gportay commented Apr 11, 2025

@florentsfl I have removed the rename of the variable from that PR.

But I guess it is better to rename them so they are just a decapitalized version + cqfd_ prefix.

@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch from 70767e0 to e1d8ce0 Compare April 17, 2025 19:44
@florentsfl
Copy link
Contributor

but if someone wants to run $CQFD_DOCKER with sudo, they can just put "sudo docker" in the variable $CQFD_DOCKER ?

@gportay
Copy link
Contributor Author

gportay commented May 21, 2025

but if someone wants to run $CQFD_DOCKER with sudo, they can just put "sudo docker" in the variable $CQFD_DOCKER ?

Yes they can. It is not automatic. No. it needs some changes.

@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch from 882c015 to 4c5feec Compare June 25, 2025 17:48
@gportay
Copy link
Contributor Author

gportay commented Jun 25, 2025

This is just a rebase on top of master.

However, I figured out that cqfd does not work correctly if user is not a member of the docker group.

The command docker run hangs during some tests (not all), it does not even enter the launcher script.

@florentsfl florentsfl added this to the v5.8 milestone Jun 25, 2025
@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch 2 times, most recently from 830d669 to a608a14 Compare June 26, 2025 20:16
@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch from a608a14 to fe24809 Compare July 8, 2025 20:39
@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch from 2542434 to 9b02ebc Compare August 12, 2025 13:36
This sets the three internal variables cqfd_user, cqfd_user_home and
cqfd_user_cwd using the standard environment variables USER, HOME and
PWD if they are set.
This moves the retrieval fo the docker gid (if the group exists) in the
function load_config() so it is guessed sooner.
The docker client requires to run as root in rootfull mode. The docker
group allows a user to access to the Unix socket created by the docker
daemon.

The user needs to run docker client with more privileges (i.e. sudo) if
it is not part of that group[1].

This prepends sudo to CQFD_DOCKER automatically if CQFD_RUN_WITH_SUDO is
set to true. It turns the internal variable cqfd_docket into an array to
split the command into pieces ("sudo docker" -> "sudo" and "docker").

[1]: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user
This adds testing for docker using sudo.

Note: The test "the user's home in passwd == $HOME" is skipped as the
user nobody is homeless.
@gportay gportay force-pushed the github/run-sudo-if-not-in-docker-group branch 2 times, most recently from 25b84ca to 58fa9e1 Compare September 25, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants