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

Don't set ambient caps without inheritable ones #4367

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Aug 6, 2024

Commit 98fe566 removed setting inheritable capabilities from

  • runc exec --cap;
  • example spec (used by runc spec);
  • libcontainer/integration test config;
  • libcontainer/README.md;
    but neglected to also remove ambient capabilities.

An ambient capability could only be set if the same inheritable
capability is set, so as a result of the above change ambient
capabilities were not set (but due to a bug in gocapability package,
those errors are never reported).

Once we start using a package with the fix, that bug will become
apparent (both bats-based and inct/int tests will fail).

This PR removes setting ambient capabilities where inheritable ones
are not set. This has no effect in the current codebase (since those
ambient capabilities were not set anyway, and the errors were ignored),
but will prevent errors once we switch to the fixed capability package.

As we do not have any tests for runc exec --cap, add one.

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

However, IMHO, it would be great to document why we removed inheritable capabilities in the first place. It is clear that if we remove inh, we should remove ambient too.

exec.go Show resolved Hide resolved
@kolyshkin
Copy link
Contributor Author

However, IMHO, it would be great to document why we removed inheritable capabilities in the first place. It is clear that if we remove inh, we should remove ambient too.

All I remember it was a security fix, originally reported by cap maintainers (Andrew Morgan). Something along the lines that inheritable capabilities are usually being set from the file system attributes, and are not expected to be set this way (runc exec --cap).

@lifubang
Copy link
Member

Another problem, maybe there is a situation we should consider:
A user wants to exec with a cap in inheritable cap list in ‘config.json’ but not in ambient cap list in ‘config.json’. In my brain, when doing exec, the process’s inheritable cap list is inherited from ‘config.json’, so it maybe exists in ‘runc exec’. The original security patch is to prevent extend the inheritable cap list, but not delete it.

If this is true, I think this PR is wrong.

@kolyshkin
Copy link
Contributor Author

A user wants to exec with a cap in inheritable cap list in ‘config.json’ but not in ambient cap list in ‘config.json’.

With a single --caps option which does not allow a user to specify the type of capabilities it's not possible. If needed, a user can use runc exec --process process.json and specify all the individual types of caps.

@lifubang try to look at this PR in the following way:

  • it is not possible to set ambient caps without inheritable caps set;
  • inheritable caps should not be set by default, and were removed to fix GHSA-f3fp-gc8g-vw66;
  • without inheritable caps set, ambient caps bits are now ignored (due to a bug in gocapability);

So what this PR does is removes ambient caps which are not being set anyway (they are ignored). In other words, it changes nothing.

@lifubang
Copy link
Member

lifubang commented Sep 3, 2024

So, what you mean is that the ‘inheritable caps’ should always be empty in ‘config.json’?

@kolyshkin
Copy link
Contributor Author

So, what you mean is that the ‘inheritable caps’ should always be empty in ‘config.json’?

Probably not always, but by default they should be empty.

Whence, ambient caps should also be empty by default, since it's not possible to set ambient without inheritable.

Hope that clears things up.

exec.go Show resolved Hide resolved
Copy link
Member

@lifubang lifubang left a comment

Choose a reason for hiding this comment

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

LGTM
Waiting #4412 merged to unblock CI.

kolyshkin and others added 3 commits September 25, 2024 21:48
Commit 98fe566 removed setting inheritable capabilities from runc exec
--cap, but neglected to also remove ambient capabilities.

An ambient capability could only be set if the same inheritable
capability is set, so as a result of the above change ambient
capabilities were not set (but due to a bug in gocapability package,
those errors are never reported).

Once we start using a library with the fix [1], that bug will become
apparent. Alas, we do not have any tests for runc exec --cap, so add
one.

Yet, if some inheritable bits are already set from spec, let's set
ambient to avoid a possible regression. Add a test case for that, too.

[1]: kolyshkin/capability#3

Fixes: 98fe566 ("runc: do not set inheritable capabilities")
Co-authored-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit 98fe566 removed inheritable capabilities from the example spec
(used by runc spec) and from the libcontainer/integration test config,
but neglected to also remove ambient capabilities.

An ambient capability could only be set if the same inheritable
capability is set, so as a result of the above change ambient
capabilities were not set (but due to a bug in gocapability package,
those errors are never reported).

Once we start using a library with the fix [1], that bug will become
apparent (both bats-based and libct/int tests will fail).

[1]: kolyshkin/capability#3

Fixes: 98fe566 ("runc: do not set inheritable capabilities")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The example is too long since it lists too many capabilities.
Simplify it, leaving only two capabilities.

Also, remove ambient capabilities from the set. Inheritable capabilities
were removed earlier by commit 98fe566, but ambient capabilities can't
be raised without inheritable ones.

Fixes: 98fe566
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin merged commit e1635d5 into opencontainers:main Sep 26, 2024
42 checks passed
@cyphar cyphar mentioned this pull request Oct 2, 2024
20 tasks
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.

3 participants