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

docker: validate that containers do not run as ContainerAdmin on Windows #23443

Merged
merged 18 commits into from
Jun 27, 2024

Conversation

pkazmierczak
Copy link
Contributor

@pkazmierczak pkazmierczak commented Jun 26, 2024

This enables checks for ContainerAdmin user on docker images on Windows. It's only checked if users run docker with process isolation and not hyper-v, because hyper-v provides its own, proper sandboxing.

Relates to: #20585
Relates to: #20034
Internal ref: https://hashicorp.atlassian.net/browse/NET-9311

This is part of a solution outlined in RFC NMD-195.

@pkazmierczak pkazmierczak added backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.8.x backport to 1.8.x release line labels Jun 26, 2024
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

The overall approach here is on the right track, @pkazmierczak

.changelog/23443.txt Outdated Show resolved Hide resolved
drivers/docker/driver_test.go Outdated Show resolved Hide resolved
drivers/docker/driver_windows.go Outdated Show resolved Hide resolved
return nil
}

if (user == "ContainerAdmin" || taskUser == "ContainerAdmin") && !driverConfig.Privileged {
Copy link
Member

Choose a reason for hiding this comment

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

The task.user will override the user from the image manifest. Ex. if you have task.user = "ContainerUser" (safe) it'll override "ContainerAdmin" (unsafe) from the image and the container will run as "ContainerUser". It looks like we have it right in the docs, but I don't think we want this to be and "or" condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed in f32473e, have a look if I got this correctly.

Comment on lines 621 to 624
// validate the image user (windows only)
if err := d.validateImageUser(imageUser, task.User, driverConfig); err != nil {
return "", err
}
Copy link
Member

Choose a reason for hiding this comment

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

Suppose we pull the image and find that it's running as "ContainerAdmin". If I try to run the task again on the same node, the image may not have been GC'd. In that case, we'll hit the case above:

// We're going to check whether the image is already downloaded.

And then skip this validation entirely! I think we want to either copy this method into the case above, or move it into the caller so that any image will get checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. We validate in the caller now: 492a750

@pkazmierczak pkazmierczak added this to the 1.8.2 milestone Jun 27, 2024
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM!

One last thing we should do is to put a warning in the upgrade guide, but otherwise this looks ready to ship

@pkazmierczak
Copy link
Contributor Author

@tgross can you have a quick 👀 at 15e684b? is the wording in the upgrade guide ok?

@pkazmierczak pkazmierczak changed the title docker: validate that containers aren't running as ContainerAdmin on windows docker: validate that containers aren't running as ContainerAdmin on Windows Jun 27, 2024
@pkazmierczak pkazmierczak changed the title docker: validate that containers aren't running as ContainerAdmin on Windows docker: validate that containers do not run as ContainerAdmin on Windows Jun 27, 2024
@pkazmierczak pkazmierczak added the backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent label Jun 27, 2024
@pkazmierczak pkazmierczak merged commit 0ece7b5 into main Jun 27, 2024
24 checks passed
@pkazmierczak pkazmierczak deleted the f-docker-windows-validate-images branch June 27, 2024 14:22
pkazmierczak added a commit that referenced this pull request Jun 27, 2024
…ows (#23443)

This enables checks for ContainerAdmin user on docker images on Windows. It's
only checked if users run docker with process isolation and not hyper-v,
because hyper-v provides its own, proper sandboxing.

---------

Co-authored-by: Tim Gross <[email protected]>
@pkazmierczak pkazmierczak added the backport/ent/1.6.x+ent Changes are backported to 1.6.x+ent label Jun 27, 2024
pkazmierczak added a commit that referenced this pull request Jun 27, 2024
…ows (#23443) (#23450)

This enables checks for ContainerAdmin user on docker images on Windows. It's
only checked if users run docker with process isolation and not hyper-v,
because hyper-v provides its own, proper sandboxing.

---------

Co-authored-by: Piotr Kazmierczak <[email protected]>
Co-authored-by: Tim Gross <[email protected]>
pkazmierczak added a commit that referenced this pull request Jun 28, 2024
Following #23443, we no longer need to sandbox template rendering on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.6.x+ent Changes are backported to 1.6.x+ent backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/website This will backport PR changes to `stable-website` && the latest release-branch backport/1.8.x backport to 1.8.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants