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

distrobox-host-exec: new tool for host command execution #283

Merged
merged 1 commit into from
May 25, 2022

Conversation

dfaggioli
Copy link
Collaborator

Executing commands on the host, while inside of a container, can be done
either with flatpak-spawn, of playing tricks with chroot. Let's provide
a new script, which will be available inside of the container, that does
exactly that.

This tries to improve (although maybe not completely fix):
#177

Signed-off-by: Dario Faggioli dfaggioli@suse.com

@dfaggioli dfaggioli force-pushed the main branch 2 times, most recently from 97b83e3 to c372476 Compare May 21, 2022 06:08
@dfaggioli
Copy link
Collaborator Author

I think we should also try to install flatpak-spawn automatcally.

I can do that in another patch. Shall we do that at init time, or the first time the user uses distrobox-host-exec?

I kind of like the latter, but it'd mean copying the package handling logic in that script, which is not really nice...

@misobarisic
Copy link
Contributor

Adding a new command requires updating the readme's "What it does" to reflect the addition.

@89luca89
Copy link
Owner

Hi @dfaggioli thanks!

I'd add a couple of things if possible:

1 - an entry in README.md, as we're adding a new command (and updating the TOC)
2 - I'd add this check in the script, just like in export and init:

if [ ! -f /run/.containerenv ] && [ ! -f /.dockerenv ]; then
to ensure we run it only in a container

I'd leave the installation of flatpak-spawn to the user, I'd like to leave the thing as simple as possible

@dfaggioli dfaggioli force-pushed the main branch 2 times, most recently from a6f0d85 to f3c0ac1 Compare May 24, 2022 14:48
@dfaggioli
Copy link
Collaborator Author

Hey, @misobarisic , @89luca89 ! Pull request updated; I think I've done what you've asked

distrobox-host-exec Outdated Show resolved Hide resolved
distrobox-host-exec Outdated Show resolved Hide resolved
@89luca89
Copy link
Owner

@dfaggioli thanks Dario! Left a couple of comments

Testing today the host-exec, I've encountered quite a few problems on the chroot approach sadly
I see that not only you cannot use podman or docker, but you cannot even use sudo

Here are examples:

luca-linux@distrobox:~/Desktop$ ./distrobox-host-exec podman ps
Warning: flatpak-spawn not found! We recommend installing it.
In the meantime, we'll try an alternative (but less powerfull) approach
WARN[0000] "/" is not a shared mount, this could cause issues or missing mounts with rootless containers 
cannot clone: Operation not permitted
WARN[0000] "/" is not a shared mount, this could cause issues or missing mounts with rootless containers 
cannot clone: Operation not permitted
WARN[0000] "/" is not a shared mount, this could cause issues or missing mounts with rootless containers 
cannot clone: Operation not permitted
ERRO[0000] invalid internal status, try resetting the pause process with "podman system migrate": cannot re-exec process 

And for sudo:

luca-linux@distrobox:~/Desktop$ ./distrobox-host-exec bash -l
Warning: flatpak-spawn not found! We recommend installing it.
In the meantime, we'll try an alternative (but less powerfull) approach
[luca-linux@microos Desktop]$ sudo su -
sudo: /etc/sudo.conf is owned by uid 65534, should be 0
sudo: /bin/sudo must be owned by uid 0 and have the setuid bit set
[luca-linux@microos Desktop]$ 

This is only for rootless containers, rootful containers don't have the second problem.

In case of rootful containers we could use nsenter to escape the container:

nsenter -t MY_PID -m -u -n -i sh

Where MY_PID is whatever pid from the $USER

This is obviously not possible as a general approach, where flatpak-spawn excels!

So either:

  • we found another way to escape the container
  • we inform quite more the user of the chroot limitation

@dfaggioli
Copy link
Collaborator Author

So either:
* we found another way to escape the container
* we inform quite more the user of the chroot limitation

Ok... Let me put something together for option 2, and let's see what you think.

@dfaggioli dfaggioli force-pushed the main branch 2 times, most recently from 9dd75e2 to c17faef Compare May 25, 2022 09:53
@dfaggioli
Copy link
Collaborator Author

So either:

  • we found another way to escape the container
  • we inform quite more the user of the chroot limitation

Ok... Let me put something together for option 2, and let's see what you think.

So, @89luca89 , how about now?

If you like it, there are those two shellcheck warnings, that I'm not sure I fully understand what they're trying to tell me, and how to make them go away... :-( Any pointer/suggestion would be much appreciated :-)

@89luca89
Copy link
Owner

So either:

  • we found another way to escape the container
  • we inform quite more the user of the chroot limitation

Ok... Let me put something together for option 2, and let's see what you think.

So, @89luca89 , how about now?

If you like it, there are those two shellcheck warnings, that I'm not sure I fully understand what they're trying to tell me, and how to make them go away... :-( Any pointer/suggestion would be much appreciated :-)

Yep! Much cleaner that the chroot is really there just in case

For the shellcheck, I've found the problems, I'll comment on the code 👍

distrobox-host-exec Outdated Show resolved Hide resolved
distrobox-host-exec Outdated Show resolved Hide resolved
Executing commands on the host, while inside of a container, can be done
either with flatpak-spawn, of playing tricks with chroot. Let's provide
a new script, which will be available inside of the container, that does
exactly that.

This tries to improve (although maybe not completely fix):
89luca89#177

Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
@89luca89
Copy link
Owner

Thanks @dfaggioli LGTM, for now the chroot is explicitly shown as an emergency fallback thanks!

This should Fix #177

Thanks!

@89luca89 89luca89 merged commit 89aa4e2 into 89luca89:main May 25, 2022
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.

None yet

3 participants