os/exec: add way to influence the ambient capability set on Linux #19713
Labels
FeatureRequest
Issues asking for a new feature that does not need a proposal.
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Motivation
I’d like to use capabilities in order to run unprivileged programs under unprivileged user accounts with only precisely the capabilities the program needs. A concrete example is removing all privileges but
CAP_SYS_TIME
from an NTP client.Example/details on what’s not working
Unfortunately, it seems like Go currently doesn’t provide a way to do this.
Here are 2 example programs:
CAP_SYS_TIME
CAP_SYS_TIME
capability in the inheritable and ambient capability set, then runs the first example program.The output of program 2 is:
I would have expected the program to include
sys_time
in its effective capabilities set and not report an error.Upon closer investigation, it turns out that
setuid(2)
clears the ambient capability set. SinceforkAndExecInChild
(src/syscall/exec_linux.go) applies cmd.SysProcAttr.Credential usingsetuid(2)
, the ambient capability set is cleared before my program is started.Looking at systemd, you can see that they restore the ambient capability set after applying credentials: https://github.com/systemd/systemd/blob/1539a651a9d31c18273df917bbfe175ab3606025/src/core/execute.c#L2711-L2748
Proof of concept
Directly modifying the standard library to set the
CAP_SYS_TIME
capability as follows……results in my test programs working:
Question
Would a CL which adds an ambient capability struct member to syscall.SysProcAttr be accepted? If not, which other way would you recommend for starting processes with an ambient capability set?
Further reading
The text was updated successfully, but these errors were encountered: