-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always use ambient capabilities if no new privileges set, not otherwise #1286
Conversation
9266c85
to
00077f7
Compare
…lities Ambient capabilities are a feature, since Linux 4.3, that enables capabilities to be set on non root proesses directly. They are the only way to set these, so are desirable in the case of "no new privileges" where suid binaries or filesystem capabilities cannot be used as tis flag denies these operations, and therefore there is no other way to apply capabilities to non root processes. Without "no new privileges" users generally expect suid binaries or filesystem capabilities to be the way to grant capabilities to non root processes. See opencontainers/runc#1286 for the `runc` pull and detailed explanation of the security issues in offering a choice here. Signed-off-by: Justin Cormack <[email protected]>
Corresponding spec PR at opencontainers/runtime-spec#668 |
Currently we have a build flag to enable ambient capabilities. However this is not a good situation as it means different installations of runc may have significantly different behaviour, which can cause security issues. The reason we introduced this was because that enabling ambient capabilities at all times caused issues with some use cases. There are essentially two ways that capabilities are used, which can be characterised as - "modern" applications which want to grant capabilities directly to applictions, including when they run as a non root user - "traditional" which look more like a traditional Linux distro and wish to mediate capabilities for non root users via suid files or with filesystem capabilities. Granting ambient capabilities causes an issue with the second case as the capabilities are immediately granted to non root processes, rather than only being granted when suid files or files with capabilities are executed, for example `sudo`. This PR removes the build flag, so that all builds are the same. In order to accomodate both types of use case, it makes use of the fact that of the "no new privileges" flag is set in the config, then it is no longer possible for suid or filesystem capabilities to have any effect, so the second use case is not possible. So we only apply ambient capabilities if this is the case. So traditional applications that want to use suid binaries or fs caps should not set the no new privileges flag in the config, and there will be no change in behaviour. Applications that wish to run as a non root user, and grant cpabilities that may be directly used can set the no new provileges flag, and then they will be granted ambient privileges, if the kernel version supports them (since 4.3). Old kernel versions are uncapable of granting direct capabilities to non root processes. The changes that are required for applications using runc after this commit are: - if they were using the old "ambient" build flag, they should set "no new privileges" if they were not before. - programs using the build without ambient capabilities (such as Docker) can use this build. If run without no new capabilities, there will be no change, but with this flag they can grant capabiltiies directly to non root processes. They may wish to consider which capabilties are granted by default in this case; I will make changes to Docker for this. Having all builds have the same security setup is the only safe setup, at present it is easy for a user to accidentally use a build with a different flag setting, causing unexpected privileges to be granted. The setup as in this commit should give a sane setup for all kinds of use case with a single binary build. I will prepare a PR for the runtime specification that says this behaviour is correct. Signed-off-by: Justin Cormack <[email protected]>
00077f7
to
78a6093
Compare
Docker PR moby/moby#30382 for testing this code. |
This is a rework of support for ambient capabilities, to avoid the issues in the previous version, where there was a conflict between two use cases, programs that want to use sudo and programs that want to grant unprivileged users direct capabilities. If you do not use the `--security-opt no-new-privileges` flag, nothing changes with this patch. `sudo`, suid binaries and filesystem capabilities elevate privileges, and non root users can only use privileges via these mechanisms as on a normal Linux userspace. With the `no-new-privileges` flag, the kernel does not allow caps to be granted via suid binaries, so it is assumed that the user wants to be granted capabilities directly, so ambient capabilities are granted. For root this makes little difference, but for a normal user this means that they can be granted capabilities directly, so that privileged operations can be performed directly. As previously no capabilities were granted to a non root user with `no-new-privileges`, we take the opoprtunity to reduce the default capability set in this case to only the three safest capabilities: `CAP_KILL`, `CAP_AUDIT_WRITE` and `CAP_NET_SERVICE`. Other capabilities must be granted with `--cap-add`. `runc` commit is in opencontainers/runc#1286 Spec commit is in opencontainers/runtime-spec#668 fix moby#8460 Signed-off-by: Justin Cormack <[email protected]>
Closing until OCI spec resolved for capabilities |
Since opencontainers/runtime-spec#675 was merged, should discussion here be reopened? |
|
Currently we have a build flag to enable ambient capabilities. However this
is not a good situation as it means different installations of runc may
have significantly different behaviour, which can cause security issues.
The reason we introduced this was because that enabling ambient capabilities
at all times caused issues with some use cases. There are essentially two
ways that capabilities are used, which can be characterised as
applictions, including when they run as a non root user
to mediate capabilities for non root users via suid files or with
filesystem capabilities.
Granting ambient capabilities causes an issue with the second case as the
capabilities are immediately granted to non root processes, rather than
only being granted when suid files or files with capabilities are executed,
for example
sudo
.This PR removes the build flag, so that all builds are the same. In order
to accomodate both types of use case, it makes use of the fact that of the
"no new privileges" flag is set in the config, then it is no longer possible
for suid or filesystem capabilities to have any effect, so the second use
case is not possible. So we only apply ambient capabilities if this is the
case.
So traditional applications that want to use suid binaries or fs caps should
not set the no new privileges flag in the config, and there will be no change
in behaviour.
Applications that wish to run as a non root user, and grant cpabilities that
may be directly used can set the no new provileges flag, and then they
will be granted ambient privileges, if the kernel version supports them
(since 4.3). Old kernel versions are uncapable of granting direct capabilities
to non root processes.
The changes that are required for applications using runc after this commit
are:
privileges" if they were not before.
use this build. If run without no new capabilities, there will be no change,
but with this flag they can grant capabiltiies directly to non root
processes. They may wish to consider which capabilties are granted by
default in this case; I will make changes to Docker for this.
Having all builds have the same security setup is the only safe setup, at
present it is easy for a user to accidentally use a build with a different
flag setting, causing unexpected privileges to be granted. The setup as
in this commit should give a sane setup for all kinds of use case with a
single binary build. I will prepare a PR for the runtime specification
that says this behaviour is correct.
Signed-off-by: Justin Cormack [email protected]