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

Drop unnecessary and wrong group detection on host #401

Merged
merged 1 commit into from Aug 28, 2020
Merged

Drop unnecessary and wrong group detection on host #401

merged 1 commit into from Aug 28, 2020

Conversation

@martinpitt
Copy link
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
Contributor Author

@martinpitt martinpitt commented Apr 2, 2020

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
Contributor Author

@martinpitt martinpitt commented Apr 2, 2020

With toolbox, the reproducer is this:

toolbox -y create -c sid --image docker.io/debian:sid && podman start sid
@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul softwarefactory-project-zuul bot commented Apr 2, 2020

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
Contributor Author

@martinpitt martinpitt commented Apr 7, 2020

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

@softwarefactory-project-zuul softwarefactory-project-zuul bot commented Apr 7, 2020

Build failed.

@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul softwarefactory-project-zuul bot commented Apr 7, 2020

Build succeeded.

@Jmennius
Copy link

@Jmennius Jmennius commented Apr 15, 2020

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

@masterzen
Copy link

@masterzen masterzen commented Apr 28, 2020

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
Contributor Author

@martinpitt martinpitt commented Apr 29, 2020

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

@fslds 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

@crahan crahan commented Jun 8, 2020

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

@evan-a-a
Copy link

@evan-a-a 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.

@Jmennius Jmennius mentioned this pull request Jun 27, 2020
4 of 7 tasks complete
HarryMichal added a commit to HarryMichal/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
@HarryMichal HarryMichal added this to the Stable 1.0 milestone Jul 7, 2020
@HarryMichal HarryMichal self-assigned this Jul 7, 2020
@HarryMichal
Copy link
Collaborator

@HarryMichal HarryMichal commented Jul 7, 2020

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

@softwarefactory-project-zuul softwarefactory-project-zuul bot commented Jul 7, 2020

Build failed.

@martinpitt
Copy link
Contributor Author

@martinpitt martinpitt commented Jul 8, 2020

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?

@HarryMichal
Copy link
Collaborator

@HarryMichal HarryMichal commented Jul 8, 2020

The CI is being fixed in a separate PR.

@Ramblurr
Copy link

@Ramblurr Ramblurr commented Aug 21, 2020

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.

src/cmd/initContainer.go Outdated Show resolved Hide resolved
@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul softwarefactory-project-zuul bot commented Aug 28, 2020

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

@softwarefactory-project-zuul softwarefactory-project-zuul bot commented Aug 28, 2020

Build failed.

@debarshiray debarshiray merged commit 15173f8 into containers:master Aug 28, 2020
1 check failed
1 check failed
local/check check status: failure
Details
@martinpitt martinpitt deleted the martinpitt:group-detection branch Aug 29, 2020
@debarshiray
Copy link
Member

@debarshiray debarshiray commented Aug 30, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants