On Mon, 14 Dec 2015 13:11:07 -0800
Carlo Contavalli <
ccont...@gmail.com> wrote:
[...]
> what would be the best implementation in golang?
>
> It's a fairly common pattern to provide privilege separation: a more
> privileged but very simple process accepts and executes a very limited
> subset of operations based on input from pipe / socket, a much less
> privileged and more disposable process implements complex
> interactions with the user.
>
> The issues I am running into are:
>
> - fork() seems to be frowned upon. Easiest path seems to have two
> separate binaries? and ForkAndExec the second one? any alternative?
>
> I'd like to avoid that if possible as it comes with installation
> headaches / fragility (eg, figure out path of second binary, make
> sure it is correct one ...).
>
> - dropping posix capabilities ... although I have seen a few open
> source libraries out there for golang.
>
> - ipc via file descriptor - channels are great, but will need some
> code to bridge channels and fd? need to look more into this.
I like re-executing of "/proc/self/exe" with lowered credentials
and with a custom option to switch on in a newly executed command.
Something like [1] (ripped off a real program).
This example could be made more elaborate. For instance, you can
attach a (Go) pipe to the stdin of the spawned process and write
something there expecting it to read this and decode. This can be used
for passing configuration bits to the copy running with lowered
privileges, which that would otherwise unable to access (say, a
configuration file with passwords which is root:root 0600). Or you can
also attach another pipe to the process's stdout and have a
bi-directional communication between them using any protocol you like
(encoding/json, net/textproto, protobuf etc).
1.
http://play.golang.org/p/N7plnGf79z