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

Add capabilities check #104

Merged
merged 12 commits into from
Dec 14, 2020
Merged

Add capabilities check #104

merged 12 commits into from
Dec 14, 2020

Conversation

kreamkorokke
Copy link
Contributor

This resolves #32

@kreamkorokke kreamkorokke changed the base branch from main to add-slice December 4, 2020 23:14
@kreamkorokke kreamkorokke changed the base branch from add-slice to main December 5, 2020 01:31
@kreamkorokke kreamkorokke marked this pull request as ready for review December 5, 2020 01:32
internal/templates/containercapabilities/template.go Outdated Show resolved Hide resolved
internal/templates/containercapabilities/template.go Outdated Show resolved Hide resolved
internal/templates/containercapabilities/template.go Outdated Show resolved Hide resolved
internal/templates/containercapabilities/template.go Outdated Show resolved Hide resolved
internal/templates/containercapabilities/template.go Outdated Show resolved Hide resolved

// Any capability from scCaps should not match with any from paramCaps
for _, paramCapMatcher := range paramCapMatchers {
for _, scCap := range scCaps.Add {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, the tricky thing here is that containers can have some capabilities implicitly, through defaults. This means we should either:

  1. Use the default list of defaults from here, and assume they are in the container.
  2. Be extra-restrictive, and say that to forbid a capability, you must drop it explicitly. (This is the same as assuming that containers have all capabilities by default.)

As written, the NET_RAW check will not fire by default on an empty capabilities list. But it should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it will not fire on checking ADD list, but it still fires on checking DROP list right?

var found bool
for _, scCap := range scCaps.Drop {
// User can specify to drop "all" under containers as well
if paramCapMatcher(string(scCap)) || literalReservedCapabilitiesAllMatcher(string(scCap)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, I think we should just compute the effective list of capabilities by looking at the "add" and "drop", and pass those into this function.

Copy link
Contributor Author

@kreamkorokke kreamkorokke Dec 10, 2020

Choose a reason for hiding this comment

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

yeah I thought about it as well, but that requires keeping a base list that is consistent with the default caps, which I was not sure if it changes or not.

The cleanest way of doing this would be:

  • 1: find a base list
  • 2: perform add and drop
  • 3: validate against the user specified params.

However, since we don't have that base list, and not sure how safe it is to just hard code one (not only this can change, this has to also work with different versions of kubernetes server), so instead I chose to check it by making sure unwanted caps are:

  • 1: not found in ADD list since this overwrites even if it is included in DROP list
  • 2: dropped in DROP list

Copy link
Contributor

@viswajithiii viswajithiii left a comment

Choose a reason for hiding this comment

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

Looks good!

@kreamkorokke kreamkorokke merged commit 095c753 into main Dec 14, 2020
@kreamkorokke kreamkorokke deleted the add-capabilities-check branch December 14, 2020 19:13
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.

Add checks for capabilities
2 participants