Skip to content

Support granular capabilities - #2452

Closed
ewindisch wants to merge 1 commit into
moby:masterfrom
ewindisch:2080-capabilities
Closed

ewindisch wants to merge 1 commit into
moby:masterfrom
ewindisch:2080-capabilities

Conversation

@ewindisch

Copy link
Copy Markdown
Contributor

Rather than only supporting lxc.cap.drop, support
should be added for lxc.cap.keep. This would enable
the principle of deny-by-default, with an ability to
granularly enable capabilities.

Allusion to the necessity for this feature is already
noted in lxc_template.go

Resolves issue #2080

Rather than only supporting lxc.cap.drop, support
should be added for lxc.cap.keep. This would enable
the principle of deny-by-default, with an ability to
granularly enable capabilities.

Allusion to the necessity for this feature is already
noted in lxc_template.go

Resolves issue moby#2080
@vieux

vieux commented Oct 29, 2013

Copy link
Copy Markdown
Contributor

/cc @jpetazzo

@kiorky

kiorky commented Oct 30, 2013

Copy link
Copy Markdown
Contributor

if i understand well this PR, it can also help #2391 !

@ewindisch

Copy link
Copy Markdown
Contributor Author

FYI - this patch is presently compiling but does not pass the tests it introduces. Until then, consider a WIP. I'll update when the tests are passing.

@kiorky yes, this would allow users to granularly control capabilities themselves. I might be overly optimistic that it will reduce bike-shedding over which capabilities should be part of the default set ;-)

@ewindisch

Copy link
Copy Markdown
Contributor Author

My test failures are, not surprisingly, based on the LXC version requirement. This requires running off LXC trunk or their nightly-build PPA. Docker presently requires some updates to work with upstream/trunk LXC (pre-v1).

@jpetazzo

Copy link
Copy Markdown
Contributor

Hi Eric,

Thanks for providing this patch. I don't know exactly how it should be merged, though; my main concern are:

  1. It depends on a specific version of LXC.
  2. It's LXC specific.

Re/ 1, we could patch runtime to add LXC version detection, and switch between drop and keep modes depending on the version, and issue warnings (or errors) when people use incompatible flags.

Re/ 2, the long term goal is to support other runtime backends than LXC; having the -lxc-conf flag was already a big hole in that, and I don't know how we feel about poking another one.

However, capabilities are not LXC specific; they are Linux-specific, so we might be able to map them to other backends (probably not FreeBSD, Solaris, and OS X, but still).

What do you think?

@ewindisch

Copy link
Copy Markdown
Contributor Author

@jpetazzo - Thank you.

re: 1

I had seen this as maintaining a default set of capabilities and simply adding -cap to set an override for special cases and for those with specific security requirements. I'd like to see '-privileged' removed, but that might be too tough on users.

Version requirements are nothing really new to software projects.

Choices here seem to be:
a) Rewrite this patch, codify all of the possible capabilities into docker and emulate 'cap.keep' using set subtraction. Possibly only do this as a fallback for older LXC versions. This might be problematic should Linux add new capabilities, or should the kernel not have those capabilities. It would probably break nested docker for these reasons. There might be workarounds for some of these problems.
b) Postpone this feature until February when LXC version 1 is released. Then, only support LXC version 1+
c) When running LXC versions < 1, error when specifying the -cap argument. Something like, "Feature not supported with installed LXC version". Automated tests would need to run LXC version 1, and ideally a test would also run on older supported versions (0.9).
d) When running LXC versions < 1, ignore the -caps parameter, fallback to default capabilities and issue a warning.

I'm inclined to suggest option D. It is fairly clean, doesn't introduce much cruft to remove later, has little possibility for edge-case failures, quirks, etc. Eventually, LXC 0.9 and below are unsupported and the warning is removed. It also sets a good precedent for supporting underlying platforms that might not support this feature.

re: 2

FreeBSD jails have "allow.*" parameters which are equivalent. The names are different, of course. Thus, the '-cap' flag would be the same, but the configuration values would be different and platform-specific. Instead of passing '-cap sys_admin', you'd pass '-cap mount' on FreeBSD. Some platforms might not have as much granularity and this flag may just be unsupported as with LXC 0.9 and below.

These caps are being set as arguments to 'docker run', they're not going into the Dockerfile. As a result, I'd think platform-specific configuration values should be okay?

@jpetazzo

Copy link
Copy Markdown
Contributor

For case 1: solution d makes sense.

For case 2, well, what can I say—this sounds really tempting :-)

Moreover, a Dockerfile may (in the future) explicitly require some caps to be there, and Docker would refuse (or warn) if they are not explicitly given when the container is started. E.g. if a container needs the mount capability but it is not given (through -cap or -privileged or whatever), Docker could refuse to start it, or ask for -override or whatever. But I digress!

/cc-ing @crosbymichael @vieux for their feedback as well.

@shykes

shykes commented Nov 11, 2013

Copy link
Copy Markdown
Contributor

Hi guys, I like option D also. I do want to emphasize the lxc-independence part. Going forward we want to get rid of the dependency on lxc syntax and quirks. We will break -lxc-conf at some point and I would prefer not breaking anything else. So it's really important that all supported arguments to -cap will continue to work on linux even without an lxc backend. How standard are the cap names used by lxc.conf? Are we comfortable adopting the same nomenclature, or should we maintain a nomenclature of our own?

Thanks!

@ewindisch

Copy link
Copy Markdown
Contributor Author

The capability names used by lxc nearly match those in the Linux kernel and
defined in sys/capability.h. The only difference is that the C constants
are prefixed with 'CAP_'. As such, the C constant 'CAP_MOUNT' becomes
'mount' under lxc.

OpenVZ supports capabilities as well, these names are similarly stripped
of the 'CAP_' prefix. Thus, the capabilities would always match for OpenVZ
and LXC backends.

The FreeBSD analogue for jails are prefixed by 'allow.' such as
'allow.mount'. I think here too, the prefix may be safely discarded.
However, the number of options for FreeBSD are fewer than in Linux and far
less granular. I'm not sure if these capability restrictions for jails
apply anywhere else if the FreeBSD world, but I don't think they do.

In FreeBSD, it seems there is less granularly there in favor of less
granular but highly standardized secure-levels, which has no clear analogue
in Linux. However, secure-levels could be functionally emulated through the
primitives of capabilities, namespaces, and selinux labels. It would be
useful to expose these secure-levels on FreeBSD at least.

As for -lxc-conf, there also exist various other parameters for FreeBSD
jails that would be useful to support and difficult to adequately abstract.
I think this discussion belongs elsewhere, but I'd like if docker continued
to support these platform-specific options. The docker-run parameter will
need to change, but perhaps -lxc-conf could stay as a deprecated option
mapped to the new one?
On Nov 11, 2013 3:12 PM, "Solomon Hykes" [email protected] wrote:

Hi guys, I like option D also. I do want to emphasize the lxc-independence
part. Going forward we want to get rid of the dependency on lxc syntax and
quirks. We will break -lxc-conf at some point and I would prefer not
breaking anything else. So it's really important that all supported
arguments to -cap will continue to work on linux even without an lxc
backend. How standard are the cap names used by lxc.conf? Are we
comfortable adopting the same nomenclature, or should we maintain a
nomenclature of our own?

Thanks!

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/2452#issuecomment-28234353
.

@jpetazzo

Copy link
Copy Markdown
Contributor

@shykes, how we should we proceed?

Suggestion:

  • gather a list of "abstract capabilities" (strongly inspired by Linux capabilities for now)
  • add a new Dockerfile statement e.g. REQUIRE mount setuid net_raw
  • add a new docker run flag e.g. docker run -caps mount,setuid,net_raw
  • add some aliases, e.g. privileged implies all caps

Is that a viable plan? Do you want us to take this to docker-dev? (Or draw attention from docker-dev to this thread since there is some talk already here?)

Let us know :)

@creack

creack commented Dec 6, 2013

Copy link
Copy Markdown
Contributor

ping @shykes

@bodenr

bodenr commented Dec 11, 2013

Copy link
Copy Markdown

+1 for per container capabilities... the existing mitigations described here https://groups.google.com/forum/#!msg/docker-user/T45Kc9vD804/xz7UZk_cilsJ are not viable for service class environments needing different caps per container.

even something as simple (hacky) as allowing lxc.cap.drop in lxc-conf options (if cap drop in lxc-conf then don't generate the template drop cap automagically) would be better than nothing short term IMHO.

@crosbymichael

Copy link
Copy Markdown
Contributor

We just merged a Pr removing drop caps from LXC and into the docker init. We can discuss a better way to select capabilities on the original issue now that this is no longer dependent on LXC.

@ewindisch

Copy link
Copy Markdown
Contributor Author

Successors to this patch: #6616, #6687, and #6968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants