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

Disable unsafe container options #1260

Merged
merged 3 commits into from
Feb 24, 2022
Merged

Conversation

helsaawy
Copy link
Contributor

@helsaawy helsaawy commented Jan 3, 2022

Add annotations to disable unsafe container operations, regardless of container spec:

  • adding writable vSMB or plan9 file shares to hypervisor isolated containers' UVM
  • using gMSAs for WCOW containers
    (Annotation to disable vSMB direct maps already exists)

This PR leverages the default annotations field in the shim options to disable them globally, so orchestrators and clients do not have to vet and process specs for containers.

A disable GMSA flag is parsed from annotations in containerd-shim-runhcs-v1\task_hcs.go:createContainer, which is common to all pod and task creation, process and hypervisor isolated, and sets a flag in hcsoci.CreateOptions. The flag is checked in hcsoci.validateContainerConfig. This will also prevent LCOW container creation if the annotation is set and the Windows.CredentialSpec field in the OCI spec is set.

The disable writable shares flag in uvm.Options is parsed from the annotations and sets the same flag in uvm.UtilityVM. uvm.AddVSMB and uvm.AddPlan9 both error on creating a writable file share in a VM where they are disabled.

Added functionality to expand an annotation into a group of annotations with the same value set. This way a single annotation to disable unsafe annotations can be expanded transparently into the individual annotations that each control one feature.

Moved annotation related code from oci/uvm.go to oci/annotations.go, including code to perform annotation expansion

Grouped together setting common [LW]COW options in one function to improve readability.

Added unit tests for annotation expansion and proper initialization of common uVM creation options from the spec; cri-containerd tests for disabling gMSA creds and writable fileshares; and functional tests for disabling writable file shares directly on uVMs.

Currently, all functional tests are broken.

Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com

@helsaawy helsaawy requested a review from a team as a code owner January 3, 2022 19:33
@dcantah dcantah self-assigned this Jan 3, 2022
@dcantah
Copy link
Contributor

dcantah commented Jan 3, 2022

Did a quick run for the small things, will check again by EOD hopefully for a more in depth review

@katiewasnothere
Copy link
Contributor

We should probably check that anywhere we call DefaultVSMBOptions will still work as intended. Specifically, if it's a mount we're trying to add as part of our setup work (aka not a mount that the user is trying to make) that we do the right thing.

@katiewasnothere katiewasnothere self-assigned this Jan 3, 2022
@kevpar
Copy link
Member

kevpar commented Jan 3, 2022

It would be ideal to have:

  • A single annotation to disable all unsafe behavior for hostile multi-tenant environments. I don't have a preference on if we keep individual annotations for each type of resource as well, but a single way to say "make this safe" is important. If we do keep individual annotations as well then it should be an error to set one of the other annotations in a way that conflicts.
  • A shim config option that sets the default value for the "make this safe" annotation.

@kevpar
Copy link
Member

kevpar commented Jan 3, 2022

It would be ideal to have:

  • A single annotation to disable all unsafe behavior for hostile multi-tenant environments. I don't have a preference on if we keep individual annotations for each type of resource as well, but a single way to say "make this safe" is important. If we do keep individual annotations as well then it should be an error to set one of the other annotations in a way that conflicts.
  • A shim config option that sets the default value for the "make this safe" annotation.

Actually, we probably don't need the second item, and can just use the default annotations feature instead.

@katiewasnothere
Copy link
Contributor

I agree with @kevpar. We have a way to validate a container's spec before proceeding, but it would be worth it to invest some time to add conflict detection for all the annotations specifically for the UVM.

@helsaawy
Copy link
Contributor Author

helsaawy commented Jan 3, 2022

It would be ideal to have:

  • A single annotation to disable all unsafe behavior for hostile multi-tenant environments. I don't have a preference on if we keep individual annotations for each type of resource as well, but a single way to say "make this safe" is important. If we do keep individual annotations as well then it should be an error to set one of the other annotations in a way that conflicts.
  • A shim config option that sets the default value for the "make this safe" annotation.

That works for me: I should be able to add a translation early on in creation process to translate the uni-bus "disable all unsafe behavior" annotation into the sub-annotations for the individual features and check for conflicts

@helsaawy
Copy link
Contributor Author

helsaawy commented Jan 4, 2022

We should probably check that anywhere we call DefaultVSMBOptions will still work as intended. Specifically, if it's a mount we're trying to add as part of our setup work (aka not a mount that the user is trying to make) that we do the right thing.

Tracking this down, the only two places that DefaultVSMBOptions is called in hcsshim with readOnly not hardwired to true is for adding non-root mounts (hcsoci.setupMounts) and sharing in files to the UVM (uvm.Share) (which looks like is only used for shimdiag share requests).

All the setup works seems to mount as read only.

@helsaawy helsaawy force-pushed the he/unsafe branch 2 times, most recently from b115da0 to 8f34d93 Compare January 5, 2022 18:37
internal/oci/uvm.go Outdated Show resolved Hide resolved
@helsaawy helsaawy force-pushed the he/unsafe branch 3 times, most recently from 5a0f624 to 21a61d2 Compare January 5, 2022 20:14
@jterry75
Copy link
Contributor

jterry75 commented Jan 5, 2022

Can someone inform me why we need to disable gMSA versus just not passing in a gMSA cred? Don't those do the same thing? Isnt it up to the orchestrator to pass in the right opts?

@helsaawy
Copy link
Contributor Author

helsaawy commented Jan 5, 2022

Can someone inform me why we need to disable gMSA versus just not passing in a gMSA cred? Don't those do the same thing? Isnt it up to the orchestrator to pass in the right opts?

The motivation was for situations where the container options are passed in from customers, this adds an additional layer of security to explicitly deny gMSA in certain situations, regardless of the spec.

internal/hcsoci/create.go Outdated Show resolved Hide resolved
internal/oci/uvm.go Outdated Show resolved Hide resolved
internal/hcsoci/create.go Outdated Show resolved Hide resolved
@helsaawy helsaawy force-pushed the he/unsafe branch 4 times, most recently from bb3c9ab to 36ea1a9 Compare February 10, 2022 21:38
Added annotation to disable adding writable vSMB or plan 9 file shares
to a UVM.

Grouped together setting common *COW options into a common function to
improve readability.

Added tests for proper initialization and processing of common creation
options, as well as functional tests for disabling writable shares.
Currently, functional tests do not run smoothly.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
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.

Couple comments but mostly lgtm

@helsaawy helsaawy force-pushed the he/unsafe branch 2 times, most recently from 14bd51b to e09cab2 Compare February 24, 2022 00:22
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.

lgtm again, thanks

Comment on lines 132 to 136
ioutil.WriteFile(
filepath.Join(tempDir, testFile),
[]byte(testContent),
0644,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check if the write actually worked, otherwise the rest of the test will be fun to debug haha

Comment on lines 41 to 45
ioutil.WriteFile(
filepath.Join(tempDir, testFile),
[]byte(testContent),
0644,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor

@dcantah dcantah left a comment

Choose a reason for hiding this comment

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

lgtm, small test changes

Can now expand an annotation into several sub annotations to toggle
groups of features on and off. Added tests for this as well.

Moved general annotation handling and parsing from `internal/oci/uvm.go`
to `internal/oci/annotations`, and updated tests.

Combined common OCI and gMSA tests together with subtests
Made capitalization for GMSA consistent throughout.

Removed changes to test/functional/utilities

Removed unnecessary error return.

Removed creation option for disabling gMSA and instead parse the
annotation directly from the spec.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
@helsaawy helsaawy merged commit a483a5a into microsoft:master Feb 24, 2022
@helsaawy helsaawy deleted the he/unsafe branch March 28, 2022 20:47
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
Add annotations to disable unsafe container operations, regardless of container spec:
* adding writable vSMB or plan9 file shares to hypervisor isolated containers' UVM
* using gMSAs for WCOW containers
(Annotation to disable vSMB direct maps already exists)

Signed-off-by: Hamza El-Saawy hamzaelsaawy@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