Skip to content

Do not drop effective&permitted set#45511

Merged
thaJeztah merged 2 commits intomoby:masterfrom
xpivarc:capabilites
Jul 27, 2023
Merged

Do not drop effective&permitted set#45511
thaJeztah merged 2 commits intomoby:masterfrom
xpivarc:capabilites

Conversation

@xpivarc
Copy link
Contributor

@xpivarc xpivarc commented May 10, 2023

- What I did

Currently moby drops ep sets before the entrypoint is executed. This does mean that with combination of no-new-privileges the file capabilities stops working with non-root containers. This is undesired as the usability of such containers is harmed comparing to running root containers.

This commit therefore sets the effective/permitted set in order to allow use of file capabilities or libcap(3)/prctl(2) respectively with combination of no-new-privileges and without respectively.

For no-new-privileges the container will be able to obtain capabilities that are requested.

- How I did it

- How to verify it

Use the below as Dockerfile

FROM alpine
RUN apk add --update libcap

RUN ls -la /usr/sbin/capsh
RUN setcap 'cap_sys_admin=ep' /usr/sbin/capsh

docker run --security-opt=no-new-privileges --user=100 --cap-add sys_admin <tag of the build Dockerfile> capsh --print

You should see Current: = cap_sys_admin+ep rather than Current:

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@xpivarc
Copy link
Contributor Author

xpivarc commented May 10, 2023

ref #45491

@corhere
Copy link
Contributor

corhere commented May 10, 2023

There's little point in making this change against master as it will have no effect. An unintended consequence of #44804 is that s.Process.User.UID == 0 is always true when SetCapabilities is called. (cc @rumpl: in (*daemon).createSpec, the relative ordering of WithUser and WithCapabilities is significant.)

Copy link
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now convinced that zeroing out the Effective and Permitted sets was never the right thing to do. This change is not strictly necessary to fix the bug on v24 or master because of the aforementioned oversight, but is still good to have in so we don't accidentally regress.

Note for reviewers: despite setting the Effective and Permitted sets in the container spec, in practice the container's PID 1 will have the respective capability sets zeroed out in most cases when UID > 0 because that's what execve does. The only exception is when the entrypoint has file capabilities set, which is the case that is being fixed.

@thaJeztah thaJeztah added this to the 25.0.0 milestone May 11, 2023
@thaJeztah
Copy link
Member

@xpivarc could you have a look at adding an integration test for this? (let us know if you need help doing so 🤗 )

@xpivarc
Copy link
Contributor Author

xpivarc commented May 22, 2023

@thaJeztah I should have some time this week. Sorry for the delay.

@thaJeztah
Copy link
Member

@justincormack PTAL

Currently moby drops ep sets before the entrypoint is executed.
This does mean that with combination of no-new-privileges the
file capabilities stops working with non-root containers.
This is undesired as the usability of such containers is harmed
comparing to running root containers.

This commit therefore sets the effective/permitted set in order
to allow use of file capabilities or libcap(3)/prctl(2) respectively
with combination of no-new-privileges and without respectively.

For no-new-privileges the container will be able to obtain capabilities
that are requested.

Signed-off-by: Luboslav Pivarc <[email protected]>
Signed-off-by: Bjorn Neergaard <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some discussion happening on the change. Let me put a "request changes" until those are all settled

@neersighted neersighted self-assigned this Jul 6, 2023
@neersighted neersighted mentioned this pull request Jul 10, 2023
26 tasks
@xpivarc
Copy link
Contributor Author

xpivarc commented Jul 17, 2023

@thaJeztah PTAL
I am struggling to find out a way to request the nonewprivileges option. I am pretty sure I am missing something obvious, would you be able to help here?
Also, let me know if the test looks like what you would expect.

@xpivarc
Copy link
Contributor Author

xpivarc commented Jul 18, 2023

Thanks @corhere

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the tests are fixed

@corhere corhere force-pushed the capabilites branch 2 times, most recently from f92519b to 954584e Compare July 24, 2023 20:58
Verify non-root containers are able to use file
capabilities.

Signed-off-by: Luboslav Pivarc <[email protected]>
Co-authored-by: Cory Snider <[email protected]>
Signed-off-by: Cory Snider <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xpivarc
Copy link
Contributor Author

xpivarc commented Aug 10, 2023

@thaJeztah @neersighted are there any plans for backport?

@neersighted
Copy link
Member

Yes, as evidenced by the cherry-pick labels. You are welcome to create them yourself, using prior backport PRs as a model, if you want 😄

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process capabilities cannot be retained when starting a container as non-root with --security-opt=no-new-privileges

5 participants