Skip to content

Drop unnecessary and wrong group detection on host#401

Merged
debarshiray merged 1 commit intocontainers:masterfrom
martinpitt:group-detection
Aug 28, 2020
Merged

Drop unnecessary and wrong group detection on host#401
debarshiray merged 1 commit intocontainers:masterfrom
martinpitt:group-detection

Conversation

@martinpitt
Copy link
Copy Markdown
Contributor

@martinpitt martinpitt commented Apr 2, 2020

Don't call get_group_for_sudo() on the host during create(). That runs
on the host, and thus will check which sudo group exists on the host.
But that is entirely irrelevant for sudo inside the container, and it
breaks when trying to create a Debian or Ubuntu based toolbox on a
Fedora host (or vice versa).

Also, there is no point in running the podman create command with an
extra sudo group, normal user privileges are just fine.

init_container() will call get_group_for_sudo() inside the container and
initialize the groups correctly there.

@martinpitt
Copy link
Copy Markdown
Contributor Author

This can be demonstrated entirely without toolbox. On a Fedora host there is the wheel group, but not sudo:

❱❱❱ getent group sudo wheel
wheel:x:10:martin

The current detection code looks at the host groups, but that doesn't apply to the container:

❱❱❱ podman run --rm -u nobody --group-add sudo docker.io/library/debian:sid id
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup),27(sudo)

❱❱❱ podman run --rm -u nobody --group-add wheel docker.io/library/debian:sid id
Error: error looking up supplemental groups for container 7e66defb63ee61118ddb3af0a8fc8af3d8c76dfdcbaaf8833bff837a5f837ece: Unable to find group wheel

@martinpitt
Copy link
Copy Markdown
Contributor Author

With toolbox, the reproducer is this:

toolbox -y create -c sid --image docker.io/debian:sid && podman start sid

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

@martinpitt martinpitt changed the title Fix sudo group detection when host disagrees with image Drop unnecessary and wrong group detection on host Apr 7, 2020
@martinpitt
Copy link
Copy Markdown
Contributor Author

This fails the tests as it breaks the init-container stage -- at that point get_group_for_sudo() is called inside the container, where indeed there is no podman command and no image:

++ get_group_for_sudo
+++ podman run --rm '' getent group sudo wheel
/usr/bin/toolbox: line 515: podman: command not found

So the fix is even easier -- just drop the redundant "outer" group detection.

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build succeeded.

@Jmennius
Copy link
Copy Markdown
Collaborator

This is revealed/caused by a fix in libpod introduced in 1.8.1.
Thanks for the fix!

@masterzen
Copy link
Copy Markdown

Can this be merged in ?
It isn't possible at all to run toolbox with a fedora image on Fedora CoreOS (which has sudo supplemental group) for the moment, and drastically reduces the ability to troubleshoot issues.

@martinpitt
Copy link
Copy Markdown
Contributor Author

My hunch is that the maintainers now ignore this project as they are working full steam on the Go rewrite. I haven't tested that at all yet (it's not yet in Fedora 32 or even Rawhide). It would still be nice to land this, as this project is really easy to work on and run straight out of git.

@fslds
Copy link
Copy Markdown

fslds commented Jun 8, 2020

I would also like to see this PR being approved and merged in master and consequently released as a package...
It is currently breaking cross-compatibility between Debian and RedHat derivatives, if one is the host and the other is a container.

@crahan
Copy link
Copy Markdown

crahan commented Jun 8, 2020

I'd like to add my vote for merging this fix as well.

@evan-a-a
Copy link
Copy Markdown

evan-a-a commented Jun 8, 2020

The associated code in the Go variant is here:

https://github.com/containers/toolbox/blob/master/src/cmd/create.go#L193
https://github.com/containers/toolbox/blob/master/src/cmd/create.go#L341

The change to remove this setting in Go can probably be added to this pull request as well to ensure this is remains fixed when the Go version becomes official.

martymichal pushed a commit to martymichal/toolbox that referenced this pull request Jul 7, 2020
Don't call get_group_for_sudo() on the host during create(). That runs
on the host, and thus will check which sudo group exists on the host.
But that is entirely irrelevant for sudo inside the container, and it
breaks when trying to create a Debian or Ubuntu based toolbox on a
Fedora host (or vice versa). This also causes problem on CoreOS[0][1]

Also, there is no point in running the `podman create` command with an
extra sudo group, normal user privileges are just fine.

init_container() will call get_group_for_sudo() inside the container and
initialize the groups correctly there.

containers#401

[0] containers#423
[1] coreos/fedora-coreos-tracker#458
@martymichal martymichal added this to the Stable 1.0 milestone Jul 7, 2020
@martymichal martymichal self-assigned this Jul 7, 2020
@martymichal
Copy link
Copy Markdown
Member

I took the liberty of updating your PR to reflect your original changes in the new Go code.

I tried this change on a CoreOS host myself and it really makes rootless Toolbox work. @debarshiray, this should be good to be merged.

Thank you very much for working on this!

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

@martinpitt
Copy link
Copy Markdown
Contributor Author

The tests succeeded in April when I sent this, but the run yesterday (triggered by @HarryMichal ?) now fails with

meson.build:8:0: ERROR: Program(s) ['go'] not found or not executable

That looks like it needs to be fixed in your CI?

@martymichal
Copy link
Copy Markdown
Member

The CI is being fixed in a separate PR.

@Ramblurr
Copy link
Copy Markdown

Any traction on this?

Toolbox is a daily important tool we use. I appreciate the go rewrite, and look forward to it. But the backlog of simple and good bug fixes backing up here is taking its toll.

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

... and other hybrid set-ups where the host and container OSes aren't
the same.

The entry point of a toolbox container already runs as root:root.
Therefore, there's no need to run it with an additional group.
Interactive shells spawned by 'sudo su -' both inside the container
and on the host don't run with such an additional group either. They
run just as root:root.

This prevented toolbox containers from starting up on Fedora CoreOS
hosts, because CoreOS has both the 'sudo' and 'wheel' groups but the
fedora-toolbox images only have the 'wheel' group. Therefore, it
ended up calling 'podman create --group-add sudo ...', and since the
'sudo' group was missing from the image, the container failed to start.

The --group-add flag was added in commit 4bda42d when the
entry point ran as $USER as specified in the user-specific customized
image. The additional group was specified to retain consistency with
interactive shells run as $USER.

Since then, things have changed. There's no longer any user-specific
customized image and commit f74400f made the entry point run
as root:root. The --group-add flag should have been removed as part of
those changes.

#423
@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

@debarshiray debarshiray merged commit 15173f8 into containers:master Aug 28, 2020
@martinpitt martinpitt deleted the group-detection branch August 29, 2020 14:12
@debarshiray
Copy link
Copy Markdown
Member

Looks like this fix for #423 had an unintended side-effect.

Earlier, inside the container, we'd get:

⬢[rishi@toolbox ~]$ id
uid=1000(rishi) gid=1000(rishi) groups=1000(rishi),10(wheel)

... but now:

⬢[rishi@toolbox ~]$ id
uid=1000(rishi) gid=1000(rishi) groups=1000(rishi)

Notice how the wheel group doesn't get listed. It does show up in id rishi, and doesn't seem to affect sudo capabilities. However, this can still trip up users and programs alike.

@debarshiray
Copy link
Copy Markdown
Member

Looks like this fix for #423 had an unintended side-effect.

Owen chased it down the stack and fixed it in crun:

So, all good!

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.

9 participants