From 4e179bddcaae964084e0afeda36ac68408f39c4b Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Wed, 28 Sep 2016 09:13:56 +0100 Subject: [PATCH] Set ambient capabilities where supported Since Linux 4.3 ambient capabilities are available. If set these allow unprivileged child processes to inherit capabilities, while at present there is no means to set capabilities on non root processes, other than via filesystem capabilities which are not usually supported in image formats. With ambient capabilities non root processes can be given capabilities as well, and so the main reason to use root in containers goes away, and capabilities work as expected. The code falls back to the existing behaviour if ambient capabilities are not supported. Signed-off-by: Justin Cormack --- Godeps/Godeps.json | 2 +- .../gocapability/capability/capability.go | 20 ++++---- .../capability/capability_linux.go | 50 +++++++++++++++++-- .../syndtr/gocapability/capability/enum.go | 4 ++ .../gocapability/capability/syscall_linux.go | 9 ++++ libcontainer/capabilities_linux.go | 2 +- 6 files changed, 71 insertions(+), 16 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index fb59cbed..455dffb9 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -67,7 +67,7 @@ }, { "ImportPath": "github.com/syndtr/gocapability/capability", - "Rev": "2c00daeb6c3b45114c80ac44119e7b8801fdd852" + "Rev": "e7cb7fa329f456b3855136a2642b197bad7366ba" }, { "ImportPath": "github.com/vishvananda/netlink", diff --git a/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability.go b/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability.go index c13f4e52..c07c5579 100644 --- a/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability.go +++ b/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability.go @@ -10,42 +10,42 @@ package capability type Capabilities interface { // Get check whether a capability present in the given // capabilities set. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Get(which CapType, what Cap) bool // Empty check whether all capability bits of the given capabilities // set are zero. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Empty(which CapType) bool // Full check whether all capability bits of the given capabilities // set are one. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Full(which CapType) bool // Set sets capabilities of the given capabilities sets. The // 'which' value should be one or combination (OR'ed) of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Set(which CapType, caps ...Cap) // Unset unsets capabilities of the given capabilities sets. The // 'which' value should be one or combination (OR'ed) of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Unset(which CapType, caps ...Cap) // Fill sets all bits of the given capabilities kind to one. The - // 'kind' value should be one or combination (OR'ed) of CAPS or - // BOUNDS. + // 'kind' value should be one or combination (OR'ed) of CAPS, + // BOUNDS or AMBS. Fill(kind CapType) // Clear sets all bits of the given capabilities kind to zero. The - // 'kind' value should be one or combination (OR'ed) of CAPS or - // BOUNDS. + // 'kind' value should be one or combination (OR'ed) of CAPS, + // BOUNDS or AMBS. Clear(kind CapType) // String return current capabilities state of the given capabilities // set as string. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE BOUNDING or AMBIENT StringCap(which CapType) string // String return current capabilities state as string. diff --git a/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability_linux.go b/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability_linux.go index 3dfcd398..6d2135ac 100644 --- a/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability_linux.go +++ b/Godeps/_workspace/src/github.com/syndtr/gocapability/capability/capability_linux.go @@ -235,9 +235,10 @@ func (c *capsV1) Apply(kind CapType) error { } type capsV3 struct { - hdr capHeader - data [2]capData - bounds [2]uint32 + hdr capHeader + data [2]capData + bounds [2]uint32 + ambient [2]uint32 } func (c *capsV3) Get(which CapType, what Cap) bool { @@ -256,6 +257,8 @@ func (c *capsV3) Get(which CapType, what Cap) bool { return (1<