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 support for mount policy enforcement. #1311

Merged
merged 2 commits into from
Apr 15, 2022

Conversation

anmaxvl
Copy link
Contributor

@anmaxvl anmaxvl commented Mar 2, 2022

It is possible that a malicious mount can be used to attack an LCOW pod.
If the attacker has knowleldge of the workload running, they could
possibly change the environment for a container and alter its execution.

This PR adds support for describing and enforcing mount policy for a
given container. The mount policy closely follows OCI spec to be as
explicit as possible to the user. The policy can be made less explicit
in the future if needed.

The dev tool has been updated to support mount configurations and the
configuration spec is similar to CRI config with the exception of
unsupported features (e.g., selinux config).
The tool translates CRI config to appropriate mount type and options in
mount policy. Initial implementation doesn't support any wildcards and
mount source and destinations are compared directly.

CRI adds some default mounts for all Linux containers and they had to be
hardcoded in this codebase as well. Extra caution is needed in the
future, in case the list expands.

Additional changes have been made to how sandbox and hugepages mounts
are generated to make sure that the same utility functions are used to
generate appropriate mount specs.

TODO:

  • Testing/Validation

Signed-off-by: Maksim An maksiman@microsoft.com

@anmaxvl anmaxvl force-pushed the mount-policy-enforcement branch 7 times, most recently from 54491be to caa48aa Compare March 11, 2022 22:36
@anmaxvl anmaxvl marked this pull request as ready for review March 12, 2022 02:47
@anmaxvl anmaxvl requested a review from a team as a code owner March 12, 2022 02:47
@anmaxvl
Copy link
Contributor Author

anmaxvl commented Mar 16, 2022

@SeanTAllen @KenGordon FYI

@SeanTAllen
Copy link
Contributor

I worry about the handcrafted nature of the test coverage for the functionality. There's a ton of options and a large number of interleavings that probably aren't covered. I'd personally feel more confident if there were generative tests to cover all the edges. That said, I can imagine that writing them would be a pain as would understanding them without copious comments.

Do any of the existing unit tests cover this functionality or is it only the new functional test(s) that provide coverage?

@anmaxvl
Copy link
Contributor Author

anmaxvl commented Mar 16, 2022

@SeanTAllen , I haven't added any unit tests, only the e2e functional ones. I'll get to the unit tests later.

internal/spec/spec.go Outdated Show resolved Hide resolved
pkg/securitypolicy/config.go Outdated Show resolved Hide resolved
internal/guestpath/paths.go Outdated Show resolved Hide resolved
@anmaxvl anmaxvl force-pushed the mount-policy-enforcement branch 2 times, most recently from 69beb99 to 2dbf0a0 Compare March 23, 2022 06:46
@anmaxvl anmaxvl force-pushed the mount-policy-enforcement branch 3 times, most recently from ed88272 to ead70b4 Compare March 23, 2022 06:56
@anmaxvl anmaxvl force-pushed the mount-policy-enforcement branch 5 times, most recently from 0b942d6 to 8c92072 Compare March 29, 2022 23:59
@anmaxvl anmaxvl force-pushed the mount-policy-enforcement branch 3 times, most recently from a0536ce to 15afe54 Compare April 7, 2022 17:16
@kevpar
Copy link
Member

kevpar commented Apr 8, 2022

You have a merge conflict FYI

@anmaxvl
Copy link
Contributor Author

anmaxvl commented Apr 8, 2022

You have a merge conflict FYI

done resolving

Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

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

A small comment or so, but otherwise lgtm

@@ -133,19 +190,28 @@ func NewStandardSecurityPolicyEnforcer(containers []securityPolicyContainer, enc
func (c Containers) toInternal() ([]securityPolicyContainer, error) {
containerMapLength := len(c.Elements)
if c.Length != containerMapLength {
return nil, fmt.Errorf("container numbers don't match in policy. expected: %d, actual: %d", c.Length, containerMapLength)
Copy link
Member

Choose a reason for hiding this comment

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

As a general comment, if you have two sets of changes, things that are really important, and some general cleanup that is not important, it can be helpful to put them in separate PRs. That way it's easier for reviewers to focus on the really important part of the changes. This can be especially helpful with GitHub since it's so bad at just showing you the new pieces of a PR that you've looked at already.

Copy link
Member

Choose a reason for hiding this comment

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

You don't necessarily need to do that here, since it's been around for a while already, but good to consider in the future.

It is possible that a malicious mount can be used to attack an LCOW pod.
If the attacker has knowleldge of the workload running, they could
possibly change the environment for a container and alter its execution.

This PR adds support for describing and enforcing mount policy for a
given container. The mount policy closely follows OCI spec to be as
explicit as possible to the user. The policy can be made less explicit
in the future if needed.

The dev tool has been updated to support mount configurations and the
configuration spec is similar to CRI config with the exception of
unsupported features (e.g., selinux config).
The tool translates CRI config to appropriate mount type and options in
mount policy. Initial implementation doesn't support any wildcards for
the Destination, but supports REGEX for the Source.

CRI adds some default mounts for all Linux containers and they had to be
hardcoded in this codebase as well. Extra caution is needed in the
future, in case the list expands.

Additional changes have been made to how sandbox and hugepages mounts
are generated to make sure that the same utility functions are used to
generate appropriate mount specs.

Add positive and negative tests for security policy mount constraints
Hide mount enforcement behind a LCOWIntegrity feature flag

Update securitypolicy tool docs

Signed-off-by: Maksim An <maksiman@microsoft.com>
Signed-off-by: Maksim An <maksiman@microsoft.com>
@anmaxvl
Copy link
Contributor Author

anmaxvl commented Apr 14, 2022

@kevpar moved ExtendDefaultMounts to SecurityPolicyEnforcer interface and removed unrelated code.

Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

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

LGTM

@anmaxvl anmaxvl merged commit 655b7e1 into microsoft:master Apr 15, 2022
@anmaxvl anmaxvl deleted the mount-policy-enforcement branch April 15, 2022 11:03
anmaxvl added a commit to anmaxvl/hcsshim that referenced this pull request Apr 22, 2022
…)"

This reverts commit 2028de8.

During local testing a gcs with an older version of security policy
was used when doing the fix: microsoft#1322. As we can see, the quotations
weren't there. However, later a PR was merged, which added them: microsoft#1311

Signed-off-by: Maksim An <maksiman@microsoft.com>
anmaxvl added a commit that referenced this pull request Apr 22, 2022
This reverts commit 2028de8.

During local testing a gcs with an older version of security policy
was used when doing the fix: #1322. As we can see, the quotations
weren't there. However, later a PR was merged, which added them: #1311

Signed-off-by: Maksim An <maksiman@microsoft.com>
anmaxvl added a commit that referenced this pull request Feb 7, 2023
Sync ADO with upstream to enable including test GCS binaries as
part of dev-pipeline

Related work items: #1311, #1322, #1341, #1343, #1345, #1347, #1348, #1350, #1353, #1354, #1355, #1358, #1361, #1365, #1368, #1369, #1370
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
* Add support for mount policy enforcement.

It is possible that a malicious mount can be used to attack an LCOW pod.
If the attacker has knowleldge of the workload running, they could
possibly change the environment for a container and alter its execution.

This PR adds support for describing and enforcing mount policy for a
given container. The mount policy closely follows OCI spec to be as
explicit as possible to the user. The policy can be made less explicit
in the future if needed.

The dev tool has been updated to support mount configurations and the
configuration spec is similar to CRI config with the exception of
unsupported features (e.g., selinux config).
The tool translates CRI config to appropriate mount type and options in
mount policy. Initial implementation doesn't support any wildcards for
the Destination, but supports REGEX for the Source.

CRI adds some default mounts for all Linux containers and they had to be
hardcoded in this codebase as well. Extra caution is needed in the
future, in case the list expands.

Additional changes have been made to how sandbox and hugepages mounts
are generated to make sure that the same utility functions are used to
generate appropriate mount specs.

Add positive and negative tests for security policy mount constraints
Hide mount enforcement behind a LCOWIntegrity feature flag

Update securitypolicy tool docs

Signed-off-by: Maksim An <maksiman@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.

5 participants