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

Improve the API description of PodSecurityContext.SupplementalGroups to clarify its unfamiliar behavior #113047

Conversation

everpeace
Copy link
Contributor

@everpeace everpeace commented Oct 13, 2022

What type of PR is this?

/kind documentation
/sig node

What this PR does / why we need it:

As reported #112879, the API description of PodSecurityContext.SupplementalGroups is ambiguous regarding how group membership defined in the container image is handled for the first process in the containers.

Assume a pod spec be like the below:

spec:
  securityContext: { runAsUser:1000, runAsGroup:1000, supplementalGroups:[60000] }
  containers:
  - image: some-image # uid=1000 is defined to belong to gid=50000 in this image 

Then, the first process of the container can belong to groups=1000(runAsGroup), 50000(defined in the image), 60000(supplementalGroups) in popular CRI implementations (it was confirmed in containerd and cri-o). here is reproduction code.

I think this behavior would be unfamiliar and confusing to most cluster administrators and users. Moreover, when a cluster enforces some security policy that protects the value of supplementalGroups field, the effect of its enforcement is limited, i.e. user can easily bypass the enforcement just by using a custom image. And, the behavior(unexpected group membership) will cause unexpected file access permission. It would be a security concern in some use cases when using hostPath volumes because uid/gid matters in accessing contents in hostPath volumes.

Thus, this PR improved the API description to clarify this unfamiliar current behavior and added a warning about unexpected group membership for many cluster administrators.

Note: as reported #112879, we once reported this behavior to hackerone.com(#1688374) by following Kubernetes Security and Disclosure Information. Kubernetes Security Response Committee responded that this behavior "works as intended."

Which issue(s) this PR fixes:

#112879 (fixed partially)

Special notes for your reviewer:

This is my first step to resolve #112879 described in #112879 (comment). As a next step, I will write a KEP(kubernetes/enhancements#3619) introducing a new API to customize the behavior (how group membership will be handled in the first process in the container) as proposed in #112879.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/documentation Categorizes issue or PR as related to documentation. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. sig/node Categorizes an issue or PR as relevant to SIG Node. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 13, 2022
@everpeace everpeace changed the title Improve the API description of 'PodSecurityContext.SupplementalGroups' to clarify its unfamiliar behavior Improve the API description of PodSecurityContext.SupplementalGroups to clarify its unfamiliar behavior Oct 13, 2022
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@k8s-ci-robot k8s-ci-robot added area/code-generation sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Oct 13, 2022
@leilajal
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 13, 2022
@everpeace everpeace force-pushed the improve-supplemental-groups-description branch from aa41353 to a7b8c68 Compare October 14, 2022 00:12
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 14, 2022
@everpeace everpeace force-pushed the improve-supplemental-groups-description branch from a7b8c68 to 97cfd4d Compare October 14, 2022 02:25
@everpeace

This comment was marked as off-topic.

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 14, 2022
@everpeace
Copy link
Contributor Author

/assign @liggitt

Comment on lines 3565 to 3566
// any container. Please remember that the group membership defined in the
// container image is kept. That means, if
Copy link
Member

Choose a reason for hiding this comment

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

is this part of the CRI spec or is it container-runtime implementation dependent?

Copy link
Contributor Author

@everpeace everpeace Oct 14, 2022

Choose a reason for hiding this comment

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

@liggitt Thanks for a great question. However, as far as I know, I think this part is also still ambiguous in the CRI spec(v0.25.3): LinuxContainerSecurityContext.supplemental_groups, LinuxSandboxSecurityContext.supplemental_groups

message LinuxContainerSecurityContext {
...
    // List of groups applied to the first process run in the container, in
    // addition to the container's primary GID.
    repeated int64 supplemental_groups = 8;
...
}

message LinuxSandboxSecurityContext {
...
    // List of groups applied to the first process run in the sandbox, in
    // addition to the sandbox's primary GID.
    repeated int64 supplemental_groups = 5;
...
}

At least, I confirmed containerd and cri-o implemented this behavior. here is reproduction code.

Then, would it be better to update the CRI spec too?? I believe https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/cri-api is what we update. Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then, would it be better to update the CRI spec too?? I believe https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/cri-api is what we update. Is this correct?

I updated cri-api at a913eaa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this part of the CRI spec or is it container-runtime implementation dependent?

I will ask this at sig-node and come back again.

Copy link
Contributor

Choose a reason for hiding this comment

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

is this part of the CRI spec or is it container-runtime implementation dependent?

I will ask this at sig-node and come back again.

I think right now, it's technically implementation dependent, because there's no declaration in the cri spec nor a test in critest to validate it. It seems this PR is aiming to update it to be part of the CRI spec (would not hurt to add a follow-up to test this behavior in github.com/kubernetes-sigs/cri-tools)

Copy link
Contributor Author

@everpeace everpeace Oct 17, 2022

Choose a reason for hiding this comment

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

@haircommander Thank you for your comment!

I would like to clarify the behavior in the spec because most popular cri (containerd and crio) does.

Then, I will open a PR to add critest in github.com/kubernetes-sigs/cri-tools.

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 opened a PR in cri-tools repo that adds a test case to critest: kubernetes-sigs/cri-tools#1005

Copy link
Contributor Author

@everpeace everpeace Oct 19, 2022

Choose a reason for hiding this comment

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

I also added an e2e test case in k/k to test the updated API description: 9e88694

@everpeace everpeace force-pushed the improve-supplemental-groups-description branch from 0bb5973 to f7b0788 Compare November 3, 2022 14:27
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 3, 2022
@everpeace
Copy link
Contributor Author

rebased to resolve conflict.

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 3, 2022
@everpeace

This comment was marked as off-topic.

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 3, 2022
@everpeace

This comment was marked as off-topic.

…luding cri-api)

so that it explicitly describe group information defined in the
container image will be kept. This also adds e2e test case of
SupplementalGroups with pre-defined groups in the container
image to make the behaivier clearer.
@everpeace everpeace force-pushed the improve-supplemental-groups-description branch from f7b0788 to ac1d5fd Compare November 6, 2022 01:06
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 6, 2022
@everpeace
Copy link
Contributor Author

everpeace commented Nov 6, 2022

Squashed all the previous commits into ac1d5fd.

@everpeace

This comment was marked as off-topic.

@mrunalp
Copy link
Contributor

mrunalp commented Nov 7, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 7, 2022
@liggitt
Copy link
Member

liggitt commented Nov 7, 2022

/approve
for API doc change

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: everpeace, liggitt, mrunalp

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 7, 2022
@k8s-ci-robot k8s-ci-robot merged commit 68875cf into kubernetes:master Nov 8, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 8, 2022
@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 8, 2022
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. area/code-generation area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/documentation Categorizes issue or PR as related to documentation. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.26
Archived in project
9 participants