Gentoo Archives: gentoo-dev

From: Andrew Savchenko <bircoph@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Figuring out the solution to in-network-sandbox distcc
Date: Tue, 27 Jan 2015 00:03:43
Message-Id: 20150127030331.288b46e48695bae5bae7f8b0@gentoo.org
In Reply to: Re: [gentoo-dev] Figuring out the solution to in-network-sandbox distcc by "Michał Górny"
1 On Sat, 24 Jan 2015 12:03:27 +0100 Michał Górny wrote:
2 > Dnia 2015-01-21, o godz. 11:05:34
3 > Michał Górny <mgorny@g.o> napisał(a):
4 >
5 > > Parent namespace solution
6 > > -------------------------
7 > >
8 > > The alternative is to wrap distcc so that parent network namespace is
9 > > regained. Sadly, for a start this requires SYS_CAP_ADMIN and access to
10 > > parent's /proc entry (so root privileges).
11 > >
12 > > We obviously don't want to lose userpriv, so we have to do with setuid
13 > > wrapper. Of course, setuid wrappers need to be written in C, so we need
14 > > to introduce C compiled executable in Portage. Then we need to take some
15 > > special care for it not to be abused, e.g. to access restricted network
16 > > namespaces of other processes.
17 >
18 > I've started to work on this, and I have all the setup.py code ready.
19 > Now it's just the C program and wrapping it all in Portage.
20 >
21 > The only remaining big issue is how to pass the correct namespace (or
22 > PID) to the distcc process, assuming it may be a deep child of
23 > the ebuild process.
24 >
25 > Possibilities:
26 >
27 > 1. Environment variables. Can't do because:
28 >
29 > a. one of the parent processes may scrub the environment,
30 >
31 > b. malicious process may override the variable, giving subprocess
32 > access to restricted system network namespace.
33 >
34 > 2. Files. Can't do because we would have to pass the path somehow (see
35 > 1.), and if we go for static path, we have collisions between multiple
36 > emerge processes.
37
38 If we're not going to use PID isolation in future, PID-dependent
39 "static" file name may be used, where PID belongs to emerge. This
40 should solve the collision issue.
41
42 > 3. Parent process hierarchy. Seems fragile, requires a lot of scanning
43 > on every spawn and may end up in the wrong namespace if a subprocess
44 > calls setsid() and user put emerge in a separate namespace.
45
46 Why not to use cgroups here?
47
48 > 4. IPv4 socket. While it may seem a real dumb idea, it fits the case
49 > perfectly since it is only run if process is network-namespaced. We can
50 > surely reserve a static port early and run a daemon outputting
51 > the correct PID. Since the port is namespaced, every Portage process
52 > can have its own PID-daemon, and I don't know if there's any way of
53 > overriding the result from parent process.
54
55 Looks fine, though the very idea to have extra daemons is
56 unpleasant.
57
58 Best regards,
59 Andrew Savchenko

Replies