From bce8f851c1e891aa6159e61c56ccd712b60c31b7 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Mon, 2 Nov 2020 14:26:30 +0100 Subject: specgen: add support for ambient capabilities if the kernel supports ambient capabilities (Linux 4.3+), also set them when running with euid != 0. This is different that what Moby does, as ambient capabilities are never set. Signed-off-by: Giuseppe Scrivano --- pkg/specgen/generate/config_linux.go | 5 +++++ pkg/specgen/generate/security.go | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'pkg/specgen') diff --git a/pkg/specgen/generate/config_linux.go b/pkg/specgen/generate/config_linux.go index fcb7641d2..2d40dba8f 100644 --- a/pkg/specgen/generate/config_linux.go +++ b/pkg/specgen/generate/config_linux.go @@ -350,3 +350,8 @@ func deviceFromPath(path string) (*spec.LinuxDevice, error) { Minor: int64(unix.Minor(devNumber)), }, nil } + +func supportAmbientCapabilities() bool { + err := unix.Prctl(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, 0, 0, 0) + return err == nil +} diff --git a/pkg/specgen/generate/security.go b/pkg/specgen/generate/security.go index d17cd4a9a..8a9fd7a41 100644 --- a/pkg/specgen/generate/security.go +++ b/pkg/specgen/generate/security.go @@ -145,6 +145,12 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator, } configSpec.Process.Capabilities.Effective = userCaps configSpec.Process.Capabilities.Permitted = userCaps + + // Ambient capabilities were added to Linux 4.3. Set ambient + // capabilities only when the kernel supports them. + if supportAmbientCapabilities() { + configSpec.Process.Capabilities.Ambient = userCaps + } } g.SetProcessNoNewPrivileges(s.NoNewPrivileges) -- cgit v1.2.3-54-g00ecf