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

Adding policy for Linux capabilities. #1683

Merged
merged 5 commits into from
Mar 20, 2023
Merged

Adding policy for Linux capabilities. #1683

merged 5 commits into from
Mar 20, 2023

Conversation

matajoh
Copy link
Member

@matajoh matajoh commented Mar 3, 2023

This PR adds enforcement of policy over the capabilities provided to a process, either the init process of the container, or a process being executed inside a container (i.e. this affects the EnforceCreateContainerPolicy and EnforceExecInContainerPolicy enforcement points). Linux capabilities enumerate the things a process can do, and as such a malicious host could grant or deny specific capabilities to processes to create an unexpected and potentially compromised state for the container group. Users can now specify an exact list of capabilities for each of the five sets (bounding, effective, inheritable, permitted, and ambient).

Users can also specify that they wish to enable capabilities dropping, whereby any extraneous capabilities which are granted by the host can be dropped down to a minimum set of needed capabilities.

@matajoh matajoh requested a review from a team as a code owner March 3, 2023 10:04
Copy link
Contributor

@anmaxvl anmaxvl left a comment

Choose a reason for hiding this comment

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

left a few comments, I'll review more to digest the rego bits.

internal/tools/securitypolicy/helpers/helpers.go Outdated Show resolved Hide resolved
pkg/securitypolicy/framework.rego Show resolved Hide resolved
pkg/securitypolicy/framework.rego Show resolved Hide resolved
pkg/securitypolicy/securitypolicyenforcer_rego.go Outdated Show resolved Hide resolved
test/cri-containerd/policy_test.go Show resolved Hide resolved
Copy link
Contributor

@anmaxvl anmaxvl left a comment

Choose a reason for hiding this comment

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

few comments. Also, we should address the rego code duplication...

pkg/securitypolicy/framework.rego Show resolved Hide resolved
pkg/securitypolicy/framework.rego Outdated Show resolved Hide resolved
@SeanTAllen
Copy link
Contributor

@anmaxvl should we squash this now?

pkg/securitypolicy/securitypolicyenforcer.go Show resolved Hide resolved
if len(caps.Bounding) > 0 {
out["bounding"] = caps.Bounding
} else {
out["bounding"] = make([]string, 0)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

in all these cases, caps.Bounding and co should be equivalent to make([]string, 0) if len() == 0.
Is there a reason why we need to make a new slice in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

because it can be nil which is still a 0 for size (thanks go!) but then we have to deal with nil and empty list down the road.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhh, yeah .....
can you add a comment above L504 to the effect of // create new empty []string in case caps has nil array?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added this comment and squashed the branch.

pkg/securitypolicy/framework_objects.json Outdated Show resolved Hide resolved
matajoh and others added 3 commits March 16, 2023 16:19
This commit adds enforcement of policy over the capabilities provided to a process,
either the init process of the container, or a process being executed inside a
container (*i.e.* this affects the `EnforceCreateContainerPolicy` and
`EnforceExecInContainerPolicy` enforcement points). Linux capabilities enumerate
the things a process can do, and as such a malicious host could grant or deny
specific capabilities to processes to create an unexpected and potentially
compromised state for the container group. Users can now specify an exact
list of capabilities for each of the five sets (bounding, effective, inheritable,
permitted, and ambient).

Users can also specify that they wish to enable *capabilities dropping*, whereby
any extraneous capabilities which are granted by the host can be dropped down to a
minimum set of needed capabilities.

Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
And pick up defaults from runtime

Signed-off-by: Sean T. Allen <seanallen@microsoft.com>
matajoh and others added 2 commits March 16, 2023 22:19
Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
@anmaxvl
Copy link
Contributor

anmaxvl commented Mar 17, 2023

hm. forgot that if you resolve the merge conflicts through github UI it does a merge. we should be fine though. I'll just squash merge.

@anmaxvl anmaxvl merged commit 4cf46ad into microsoft:main Mar 20, 2023
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
This commit adds enforcement of policy over the capabilities provided to a process,
either the init process of the container, or a process being executed inside a
container (*i.e.* this affects the `EnforceCreateContainerPolicy` and
`EnforceExecInContainerPolicy` enforcement points). Linux capabilities enumerate
the things a process can do, and as such a malicious host could grant or deny
specific capabilities to processes to create an unexpected and potentially
compromised state for the container group. Users can now specify an exact
list of capabilities for each of the five sets (bounding, effective, inheritable,
permitted, and ambient).

Users can also specify that they wish to enable *capabilities dropping*, whereby
any extraneous capabilities which are granted by the host can be dropped down to a
minimum set of needed capabilities.

Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
Signed-off-by: Sean T. Allen <seanallen@microsoft.com>
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.

4 participants