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

Support nested user chrootenv environments #61740

Merged
merged 3 commits into from May 30, 2019

Conversation

abbradar
Copy link
Member

Motivation for this change

Previously we couldn't run chrootenv-wrapped applications inside a chrootenv, we can now. My primary motivation was Lutris, although this is also helpful for development environments.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@infinisil
Copy link
Member

Ah darn, unfortunately #62091 introduced a conflict. It seems that that PR isn't needed anymore after this one, but I'm not so sure on that.

const gchar *bind_blacklist[] = {"bin", "etc", "host", "usr", "lib", "lib64", "lib32", "sbin", NULL};
const gchar *bind_blacklist[] = {"bin", "etc", "host", "real-host", "usr", "lib", "lib64", "lib32", "sbin", NULL};

int pivot_root(const char *new_root, const char *put_old) {
Copy link
Member

Choose a reason for hiding this comment

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

Weird that glibc doesn't provide a wrapper for this syscall.

Copy link
Member

@lukateras lukateras left a comment

Choose a reason for hiding this comment

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

LGTM! This is a huge improvement over current design, both on cleanup (tmpfs) and nesting fronts. I don't see any memory allocation issues.

@lukateras
Copy link
Member

Also see #55973, which replaces chrootenv entirely with bubblewrap.

@abbradar
Copy link
Member Author

abbradar commented May 28, 2019 via email

@L-as
Copy link
Member

L-as commented May 30, 2019

@infinisil mine is completely unneeded after this, since this PR doesn't do any nftw or ftw calls seemingly, which are buggy in glibc.

The problem with stacking chrootenv before was that CLONE_NEWUSER cannot
be used when a child uses chroot. So instead of that we use pivot_root
which replaces root in the whole namespace. This requires our new root
to be an actual fs so we mount tmpfs.
* Remove unused argument from pivot_root;
* Factor out tmpdir creation into a separate function;
* Remove unused fstype from bind mount;
* Use unlink instead of a treewalk to remove empty temporary directory.
To avoid symlink loops to /host in nested chrootenvs we need to remove
one level of indirection. This is also what's generally expected of
/host contents.
@abbradar
Copy link
Member Author

Let's merge now; hopefully we can replace all this code with bwrap in the end ;)

@abbradar abbradar merged commit 6723d59 into NixOS:master May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants