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

Kubelet: Add security context for Windows containers #64009

Merged

Conversation

feiskyer
Copy link
Member

What this PR does / why we need it:

This PR adds windows containers to Kubelet CRI and also implements security context setting for docker containers.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

RunAsUser from Kubernetes API only accept int64 today, which is not supported on Windows. It should be changed to intstr for working with both Windows and Linux containers in a separate PR.

Release note:

Kubelet: Add security context for Windows containers

/cc @PatrickLang @taylorb-microsoft @michmike @JiangtianLi @yujuhong @dchen1107

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 18, 2018
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 18, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 18, 2018
@k8s-ci-robot
Copy link
Contributor

@feiskyer: GitHub didn't allow me to request PR reviews from the following users: taylorb-microsoft, PatrickLang.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

What this PR does / why we need it:

This PR adds windows containers to Kubelet CRI and also implements security context setting for docker containers.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

RunAsUser from Kubernetes API only accept int64 today, which is not supported on Windows. It should be changed to intstr for working with both Windows and Linux containers in a separate PR.

Release note:

Kubelet: Add security context for Windows containers

/cc @PatrickLang @taylorb-microsoft @michmike @JiangtianLi @yujuhong @dchen1107

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@feiskyer
Copy link
Member Author

/retest

@michmike
Copy link
Contributor

i am asking @bsteciuk to review this as well. at a high level it looks good to me but i don't know enough to do a good code review here

@feiskyer
Copy link
Member Author

/sig windows
/sig node

/retest

@k8s-ci-robot k8s-ci-robot added sig/windows Categorizes an issue or PR as relevant to SIG Windows. sig/node Categorizes an issue or PR as relevant to SIG Node. labels May 21, 2018
@feiskyer
Copy link
Member Author

/retest

ping @dchen1107 @bsteciuk

// setup security context
effectiveSc := securitycontext.DetermineEffectiveSecurityContext(pod, container)
// RunAsUser only supports int64 from Kubernetes API, but Windows containers only support username.
// TODO: change RunAsUser to intstr in Kubernetes API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to change it? I'm wondering whether its better to use one field as IntStr that requires different types for Windows vs Linux, or if we should just have two different fields - Int for Linux, Str for Windows?

Copy link
Contributor

Choose a reason for hiding this comment

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

My preference is to keep the fields separate but open to feedback

Copy link
Member Author

@feiskyer feiskyer May 23, 2018

Choose a reason for hiding this comment

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

From CRI perspective, it supports both int64 and string for Linux containers but only string for Windows containers. While in today's API, only int64 is supported yet. So changing kubernetes API to IntStr will work for both Linux and Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. So converging DetermineEffectiveSecurityContext will require the API change later. This PR just adds the new field run_as_user which is Windows only.

Copy link
Member Author

Choose a reason for hiding this comment

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

exactly

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 think username could also be verified, e.g. administrator on Windows or root on Linux.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the docker images will run as user "foo" by default inside the container, (today) kubelet can't check what uid "foo" maps to, and whether it's actually root on the host.

How does this work for windows?...

Copy link
Contributor

Choose a reason for hiding this comment

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

Privileged mode isn't implemented on Windows, and the container administrator account is separate because the filesystem and registry (where the user profile is) are separate from the host's. Putting a check on username won't add any security.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you do want it for consistency with Linux, it could be done but would need to check against localized variants of "Administrator" since microsoft/windowsservercore is localized

Copy link
Member Author

Choose a reason for hiding this comment

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

If the docker images will run as user "foo" by default inside the container, (today) kubelet can't check what uid "foo" maps to, and whether it's actually root on the host.

@yujuhong Good catch. Even non-root username could have uid 0 on Linux, so username won't make sense for linux security context.

If you do want it for consistency with Linux, it could be done but would need to check against localized variants of "Administrator" since microsoft/windowsservercore is localized

@PatrickLang I think checking localized variants not possible because kubelet won't handle container localization.

Let me remove the todo item.

@feiskyer feiskyer added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels May 23, 2018
@feiskyer
Copy link
Member Author

/milestone v1.11
/status approved-for-milestone

@feiskyer
Copy link
Member Author

/kind api-change

@feiskyer feiskyer added kind/bug Categorizes issue or PR as related to a bug. and removed kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels May 23, 2018
@PatrickLang
Copy link
Contributor

/lgtm
@akochnev or @bsteciuk do you want to take a look?

@PatrickLang
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 5, 2018
@dims
Copy link
Member

dims commented Jun 5, 2018

This PR does not look critical for 1.11, and is not in an ready-to-merge state. As such, it will be removed from the 1.11 milestone by the milestone bot when Code Freeze starts at midnight UTC / 5pm PDT. If you feel it is critical to 1.11, please upgrade its priority to critical-urgent

@PatrickLang
Copy link
Contributor

@tallclair or @derekwaynecarr any updates? There were some questions about usernames but no changes requested.

@PatrickLang
Copy link
Contributor

Filed #64801 to investigate PodSecurityPolicy later per @tallclair 's feedback

@tallclair
Copy link
Member

/lgtm
I'd like to see some test coverage though.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 6, 2018
@yujuhong
Copy link
Contributor

yujuhong commented Jun 6, 2018

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feiskyer, PatrickLang, tallclair, yujuhong

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@feiskyer feiskyer added priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. and removed priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Jun 6, 2018
@feiskyer
Copy link
Member Author

feiskyer commented Jun 6, 2018

I'd like to see some test coverage though.

Yep, we should add windows tests definitely. But the test infra is still not ready yet. We expect it ready next release.

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@PatrickLang @derekwaynecarr @feiskyer @tallclair @yujuhong

Pull Request Labels
  • sig/node sig/windows: Pull Request will be escalated to these SIGs if needed.
  • priority/critical-urgent: Never automatically move pull request out of a release milestone; continually escalate to contributor and SIG through all available channels.
  • kind/bug: Fixes a bug discovered during the current release.
Help

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@feiskyer
Copy link
Member Author

feiskyer commented Jun 6, 2018

/test pull-kubernetes-integration

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 64009, 64780, 64354, 64727, 63650). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 999b2da into kubernetes:master Jun 6, 2018
@feiskyer feiskyer deleted the windows-security-context branch June 6, 2018 05:29
@k8s-ci-robot
Copy link
Contributor

@feiskyer: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-integration 7ba26ba link /test pull-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants