Skip to content
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

fix: provide only available capabilities to insecure environment #2394

Merged
merged 1 commit into from
Oct 16, 2021

Conversation

smira
Copy link
Collaborator

@smira smira commented Oct 5, 2021

The problem this change is trying to fix are the environments where some
capabilities are already dropped, so they can't be granted to the
job with --security=insecure.

I know that probably fixed set of capabilities was implemented to
provide a stable build environment, but at the same time this breaks
environments with reduced capabilities.

Signed-off-by: Andrey Smirnov [email protected]

@smira
Copy link
Collaborator Author

smira commented Oct 5, 2021

One more idea is that we could find intersection of what is available and desired set of capabilities, so that build environment doesn't have more capabilities than the fixed list.

@tonistiigi
Copy link
Member

Not sure if this is desired. We should provide a consistent environment between different machines and installations. If an app uses a capability in one system it should always work on another as well. And fail if the installation isn't capable of providing such an environment.

@smira
Copy link
Collaborator Author

smira commented Oct 5, 2021

Not sure if this is desired. We should provide a consistent environment between different machines and installations. If an app uses a capability in one system it should always work on another as well. And fail if the installation isn't capable of providing such an environment.

I fully agree with this, but I don't know at the same time how to combine that with potentially reduced capabilities.

Some background: in the last version of Talos we introduced a security feature to drop some of the capabilities from all processed but PID 1. The idea was that Talos should be able to use kexec, while no other process in the system should be able to use kexec for security reasons. This seems like a reasonable way to provide fast reboots on bare metal while we don't sacrifice security. So if we launch buildkit/buildx on top of Talos, it will have reduced set of capabilities to start with. We use Talos in Talos CI to run Talos builds which rely on --security=insecure to run some unit-tests which in turn launch containerd, so we need best of both worlds.

I don't know if the idea of keeping set of capabilities as it was before this change minus those which are not available right now would make more sense (so that job might have less capabilities, but not more).

@smira
Copy link
Collaborator Author

smira commented Oct 5, 2021

Also related, similar issue in dockerd moby/moby#42906

By the way, privileged pods launched with Kubernetes/containerd correctly handle reduced capability set: launched pods have maximum available capabilities, but it correctly workarounds not allowed capabilities.

@tonistiigi
Copy link
Member

Generally, the solution for this should be to define more specific constraint like cap_admin or maybe something like --security=insecure,-sys_boot. Not very user-friendly though.

Feels hacky but I think I would even be more willing to just do an exception for kexec/sys_boot as it does feel a bit special case. I'd like to avoid case where someone implements something that doesn't have sys_admin and then even something as basic as mount will fail in the build in unexpected way(or build in a wrong way).

@smira
Copy link
Collaborator Author

smira commented Oct 5, 2021

I would rather see the list of capabilities being dynamic to some extent, as in Talos we dropped CAP_SYS_BOOT and CAP_SYS_MODULES (because Talos doesn't have kernel modules, and we don't want random pods to even being able to access it). So in the future I would rather see defaults going towards having less capabilities available. Another option might be to set a list of "insecure" capabilities via some configuration? as it's more specific to the host rather than a build?

Also looks like current list of capabilities in buildkit is not complete (kernel has more caps now), so what are we going to do with that in the future? add more or keep the list fixed?

@AkihiroSuda
Copy link
Member

I'd like to avoid case where someone implements something that doesn't have sys_admin and then even something as basic as mount will fail in the build in unexpected way(or build in a wrong way).

Maybe we should just print a warning (or error out) when cap.Current() lacks SYS_ADMIN ?

@smira
Copy link
Collaborator Author

smira commented Oct 5, 2021

And third option is to print a warning if some capability is not available, but skip it to avoid failures? So that one can see that build environment is not exactly same (some caps missing), but at least proceed with the build?

@smira
Copy link
Collaborator Author

smira commented Oct 5, 2021

Updated the PR to skip caps (with warning) which are not available right now.

@tonistiigi
Copy link
Member

CAP_SYS_BOOT and CAP_SYS_MODULES

This could be like --security=kernel but there will probably be many more specific cases. https://github.com/moby/libentitlement was supposed to define these logical groups but unfortunately it didn't go anywhere.

We don't currently have a good method for sending warnings to client progress. There are many use cases for it though if somebody is willing to spend some time on it.

@thaJeztah
Copy link
Member

FWIW, I also opened a PR for consideration in runc (opencontainers/runc#3240), to make it match the runtime spec (opencontainers/runc#2854)

util/entitlements/security/security_linux.go Outdated Show resolved Hide resolved
util/entitlements/security/security_linux.go Outdated Show resolved Hide resolved
client/client_test.go Outdated Show resolved Hide resolved
@smira
Copy link
Collaborator Author

smira commented Oct 11, 2021

I'm looking at opencontainers/runc#3240 can provide a better solution for unavailable caps. We might still want to expand capability list, but that would be way easier

The problem this change is trying to fix are the environments where some
capabilities are already dropped, so they can't be granted to the
job with `--security=insecure`.

I know that probably fixed set of capabilities was implemented to
provide a stable build environment, but at the same time this breaks
environments with reduced capabilities.

Signed-off-by: Andrey Smirnov <[email protected]>
@smira
Copy link
Collaborator Author

smira commented Oct 15, 2021

@tonistiigi I updated the PR, fixed all the tests. Two test failures seem to be unrelated to my changes.

@tonistiigi tonistiigi merged commit cbf808f into moby:master Oct 16, 2021
@crazy-max crazy-max added this to the v0.10.0 milestone Feb 4, 2022
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.

5 participants