Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 512794 - sys-apps/sandbox: support namespaces when available
Summary: sys-apps/sandbox: support namespaces when available
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Sandbox (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Sandbox Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-09 03:09 UTC by Matthew Thode ( prometheanfire )
Modified: 2021-10-21 05:34 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2014-06-09 03:09:38 UTC
This is a standard (and as safe as the kernel can be, safe) way of sandboxing.

We could, for example, run servers in a namespace to test against (even though stubing and the like is better).

To break out of a namespace we would have to copy a file or something first, not sure.  Need to investigate how docker/lxc handle it.

Reproducible: Always
Comment 1 SpanKY gentoo-dev 2014-07-29 15:09:19 UTC
the namespaces that exist in the latest release are not sufficient to fully isolate.  they are also not something we'll ever hard require because:
 - they are frequently disabled by users
 - many require recent kernel versions

that said, i've been toying with using them when they are actually available.  the isolation that's available today is nice -- PID & USER & mount.
Comment 2 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2014-07-30 05:29:52 UTC
Ya, I've been meaning to set up a system like rich0 did to test ebuilds.
Comment 3 SpanKY gentoo-dev 2015-09-21 09:30:36 UTC
i've got an implementation now working, but it requires user namespaces when FEATURES=usersandbox is active because portage drops root before executing the sandbox.  but maybe we can teach portage to let the sandbox itself do the dropping of accounts ...

otherwise, what i've got:
 - a unique ipc/sysv namespace is created ... i'm not aware of this causing problems for any packages including portage internals
 - a unique uts namespace is created ... not a big deal, but lets sandbox set a unique/stable hostname, and prevents apps from changing it
 - a unique net namespace is created ... the only network access apps get are to localhost which prevents rogue network connections and conflicts when running tests.  there's overlap here with FEATURES=network-sandbox.
 - a unique pid namespace is created ... no apps get access to processes outside of the sandbox now, and it's impossible for processes to orphan themselves because when the sandbox exits, the kernel guarantees killing children (whoo)
 - a unique mount namespace is created ... not that it normally should matter by itself as you don't normally have access to mount/umount
 - when mount namespaces work, a tiny/reduced /dev/ mount is created.  atm only access is granted to: full, null, ptmx, tty, urandom, zero, pts, fd, std{err,in,out}.  this will implicitly "fix" many packages that try and poke things like video hardware as the /dev/ nodes won't be visible.  also isolates packages that accidentally try to scribble on mem/block nodes.
 - when mount namespaces work, a unique /tmp/ is created.  this guarantees all content is destroyed between phases and ebuilds can't break other packages or system processes (or vice versa).

i'm also thinking about white-ing out /run/ and /run/lock/ as i can't think of any state in there that apps inside of the build sandbox should need access to.

atm i only have command line flags for controlling things.  i want to add support for enabling things via /etc/sandbox.conf before releasing.
Comment 4 SpanKY gentoo-dev 2015-09-27 06:32:10 UTC
initial support released here:
http://gitweb.gentoo.org/proj/sandbox.git/commit/?id=d96587d02f203e2c40790ac1c0e5778c6299d1a2

features are defaulted to off but can be turned on by editing /etc/sandbox.conf.  once this stabilizes a bit and i can update portage, i'll see about flipping at least some of the options to on.