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 host process containers when disable unsafe operations is enabled #2164

Conversation

katiewasnothere
Copy link
Contributor

Host process containers are not safe for multi-tenant scenarios since they run directly on the host and use the host's network. Don't allow host process containers to be used when DisableUnsafeOperations is set.

@katiewasnothere katiewasnothere requested a review from a team as a code owner June 10, 2024 23:32
@@ -322,5 +322,6 @@ var AnnotationExpansions = map[string][]string{
WCOWDisableGMSA,
DisableWritableFileShares,
VSMBNoDirectMap,
HostProcessContainer,
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be set to false, when disable unsafe annotations is true?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh yeah, i missed that
either an annotation for DisableHostProcessContainer needs to be created, or we need an AnnotationDenyList thingy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@helsaawy I added a DisableHostProcessContainer annotation and updated the PR

@katiewasnothere katiewasnothere force-pushed the kabaldau/host_process_unsafe_op branch from 4767980 to 3fdc8da Compare June 12, 2024 00:43
@katiewasnothere
Copy link
Contributor Author

@helsaawy and @anmaxvl I reworked this PR to instead change how we handle annotation expanding. Instead of the annotations sharing the same value as the parent annotation, I added the ability to set a target value for the child annotations. Do y'all have any thoughts on this approach?

Note: optionally in the future we could even expand this to use parent annotations that are not true or false. For example, I could envision an annotation like "memorybacking" and when that annotation's value is "physical" then it could expand with child annotations allowovercommit to false and vpmemdevicecount to 0, like we have for the annotation "fullyphysicallybacked"

Copy link
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

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

i think this implementation breaks the logic where we assume that parent annotation's must match the value of their expansions, and don't try to parse values as booleans.
i would rather we either:

  1. double down on the bool approach, and have AnnotationExpansions be map[string]map[string]bool; or
  2. add an DisableHostProcessContainer that is the antithesis of the HostProcessContainer annotation, with a separate check after annotation expansion that only one of the two can be defined

var AnnotationExpansions = map[string][]string{
// other annotations and their values. It is an error for the expansions to already
// exist and have a value that differs from the value set here.
var AnnotationExpansions = map[string]map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

since we are already changing the type, which is breaking, can we make it:

Suggested change
var AnnotationExpansions = map[string]map[string]string{
func AnnotationExpansions() map[string]map[string]string {

that way, no-one can (inadvertently) modify the map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we just make it a const instead?

internal/oci/annotations.go Outdated Show resolved Hide resolved
internal/oci/annotations_test.go Outdated Show resolved Hide resolved
annotation to DisableUnsafeOperations

Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
@katiewasnothere katiewasnothere force-pushed the kabaldau/host_process_unsafe_op branch from 3fdc8da to f5f103d Compare June 14, 2024 22:38
Copy link
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -55,6 +56,19 @@ func ProcessAnnotations(ctx context.Context, s *specs.Spec) (err error) {
}
}

// validate host process containers annotations are not conflicting
disableHPC := ParseAnnotationsBool(ctx, s.Annotations, annotations.DisableHostProcessContainer, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably the only annotation that needs to be handled like this for now. In the future we may want to consider defining a "conflict annotations map" or similar, e.g.

conflictingAnnotations := map[string]string{
    annotations.DisableHostProcessContainer: annotations.HostProcessContainer,
}

for k, v := range conflictingAnnotations {
    v1 := ParseAnnotationsBool(ctx, s.Annotations, k, false)
    v2 := ParseAnnotationsBool(ctx, s.Annotations, v, false)
    if v1 && v2 {
        // handle conflict
    }
}

Maybe it's worth just doing it now too, rather than special casing it to HPC? thoughts?

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.

lgtm. my comment is non blocking

@katiewasnothere katiewasnothere merged commit 75311a3 into microsoft:main Jun 21, 2024
19 checks passed
@katiewasnothere katiewasnothere deleted the kabaldau/host_process_unsafe_op branch June 21, 2024 22:55
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.

None yet

3 participants