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

Allow specifying the primary group id of the container #756

Merged
merged 10 commits into from
Sep 18, 2017

Conversation

krmayankk
Copy link

@krmayankk krmayankk commented Jun 22, 2017

Allows specifying the Primary Group ID of the container, in addition to Primary User Id when running in Docker similar to how docker supports this.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 22, 2017
@krmayankk
Copy link
Author

@krmayankk
Copy link
Author

@kubernetes/sig-node-proposals

Copy link
Member

@pmorie pmorie left a comment

Choose a reason for hiding this comment

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

Promising start to this proposal, left some comments.

## Abstract


As a Kubernetes User, i should be able to specify both user id and group id for the containers running
Copy link
Member

Choose a reason for hiding this comment

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

s/i/I/

inside a pod on a per Container basis, similar to how docker allows that using docker run options -u,
--user="" Username or UID (format: <name|uid>[:<group|gid>]) format.

PodSecurityContext allows Kubernetes users to specify RUnAsUser which can be overriden by RunAsUser
Copy link
Member

Choose a reason for hiding this comment

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

typo: RUnAsUser

--user="" Username or UID (format: <name|uid>[:<group|gid>]) format.

PodSecurityContext allows Kubernetes users to specify RUnAsUser which can be overriden by RunAsUser
in SecurtiyContext on a per Container basis. There is no equivalent field for specifying the primary
Copy link
Member

Choose a reason for hiding this comment

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

typo: SecurityContext

## Motivation

Enterprise Kubernetes users want to run containers as non root. This means running containers with a
non zero user id and non zero group id. This gives Enterprises confidence that their customer code
Copy link
Member

Choose a reason for hiding this comment

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

Group zero essentially means nothing and has zero security implications. I'm not saying that this isn't a valid use case, but you don't gain anything, to my knowledge, by running as GID 0.

Copy link
Member

Choose a reason for hiding this comment

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

I would buy that someone wants to be able to use GIDs as part of a security scheme, though, possibly derived from LDAP or another identity system.

## Use Cases

Use case 1:
As a cluster operator, i should be able to control both user id and primary group id of containers
Copy link
Member

Choose a reason for hiding this comment

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

I think this is 'as a Kubernetes user', and what's the "so that I can _____________" part of this use-case?

launched using Kubernetes.

Use case 2:
As a cluster operator, i should be able to override user id and primary group id of a container as
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the same use case as the first one?

}


type PoddSecurityContext struct {
Copy link
Member

Choose a reason for hiding this comment

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

typo: PodSecurityContext

// +optional
RunAsUser *int64
// The GID to run the entrypoint of the container process.
// Defaults to user specified in image metadata if unspecified.
Copy link
Member

Choose a reason for hiding this comment

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

Defaults to the group?

- If no RunAsGroup is provided in the PodSecurityContext and SecurityContext, and none in the image,
the container will run with primary Group as root(0).

## Not In Scope
Copy link
Member

Choose a reason for hiding this comment

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

How is this not in scope? We need to add the policy control surface to govern features like this as we implement them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any additions to PodSecurityContext will changes to PodSecurityPolicy - both are part of the API and should evolve together.

@erictune
Copy link
Member

Can you at least compare to the alternative, which is pushing an /etc/groups file to all your nodes and using that for group membership?

@krmayankk
Copy link
Author

@pmorie @smarterclayton addressed comments. @erictune Are you suggesting controlling the gid through the file, while controlling uid through existing runtime mechanisms. It can be done, but not dynamically configurable and one /etc/groups file will affect all containers of a host. Do you still think we should discuss that option in the proposal ?

@krmayankk
Copy link
Author

krmayankk commented Aug 15, 2017

@erictune Also isnt /etc/groups only for controlling secondary/supplemental group ids? Here we are talking about controlling the primary group id the container runs as

@vpal
Copy link

vpal commented Aug 15, 2017

@krmayankk, @erictune I think that the groups file on the host OS does not affect UID and GID allocation in the container.

sudo docker run --rm -ti --user 1000 ubuntu:16.04 /bin/bash
I have no name!@80925fc54764:/$ id
uid=1000 gid=0(root) groups=0(root)
I have no name!@80925fc54764:/$ 

I have user and group 1000 in the group file on the host.
So what you would need to do is rebuild your images with the /etc/groups file, which is the thing we would like to avoid here. That is what the --user is for in docker.
If you have the chance to rebuild the image you can also solve this in other ways like providing UID and GID in the Dockerfile for example.
But if you just want to run something straight from a third party repository and want it to have a specific UID and GID overriding the default one you do not have the option right now. You can only specify the UID and supplemental groups.

@smarterclayton
Copy link
Contributor

smarterclayton commented Aug 15, 2017

I have no objections to this as stated. For symmetry I see no reason why this should be prohibited when the primary UID is allowed.

@smarterclayton
Copy link
Contributor

Something seems to be wrong with lowercase 'i''s in the markdown being converted to capital I.

@smarterclayton smarterclayton added sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. labels Aug 15, 2017
@smarterclayton
Copy link
Contributor

@kubernetes/sig-auth-feature-requests can you chime in if you see any additional implications. I don't see any reason not to add this or enable it as long as the PSP work is done at the same time.

@erictune
Copy link
Member

erictune commented Aug 15, 2017 via email

@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 15, 2017
@smarterclayton
Copy link
Contributor

I'd like at least another sig node reviewer to comment before I mark lgtm.

Copy link
Member

@pmorie pmorie left a comment

Choose a reason for hiding this comment

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

Close to LGTM; a couple nits and one ask to explicitly define behavior when these fields are unspecified.


As a Kubernetes User, we should be able to specify both user id and group id for the containers running
inside a pod on a per Container basis, similar to how docker allows that using docker run options `-u,
--user="" Username or UID (format: <name|uId>[:<group|gid>]) format`.
Copy link
Member

Choose a reason for hiding this comment

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

typo: "uId"

// May also be set in PodSecurityContext. If set in both SecurityContext and
// PodSecurityContext, the value specified in SecurityContext takes precedence.
// +optional
RunAsUser *Int64
Copy link
Member

Choose a reason for hiding this comment

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

nit: int64


PodSecurityPolicy defines strategies or conditions that a pod must run with in order to be accepted
into the system. Two of the relevant strategies are RunAsUser and SupplementalGroups. We introduce
a new strategy called RunAsGroup which will support the following options:-
Copy link
Member

Choose a reason for hiding this comment

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

trailing -


### Model

Introduce a new API field in SecurityContext and PodSecurityContext called `RunAsGroup`
Copy link
Member

Choose a reason for hiding this comment

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

Missing period at the end of this sentence. Can we mention explicitly what the behavior is if these fields are not defined?

@krmayankk krmayankk force-pushed the runasg branch 2 times, most recently from 93d65b4 to 8a69db9 Compare August 30, 2017 22:05
@krmayankk
Copy link
Author

@pmorie there is a Behavior heading already at the bottom of this design proposal. Let me know if its missing something ?

@smarterclayton
Copy link
Contributor

smarterclayton commented Sep 15, 2017 via email

@pmorie
Copy link
Member

pmorie commented Sep 18, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 18, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 65bc9f8 into kubernetes:master Sep 18, 2017
@krmayankk
Copy link
Author

thanks to @pmorie for initial pointers, review and encouragement. And thanks to @pweil- @smarterclayton @vpal for reviewing and it and getting this in

@bgrant0607
Copy link
Member

@krmayankk All of the design proposals moved into SIG-specific subdirectories last week. The security context proposal was moved to auth, so I'd appreciate it if this were moved into that subdirectory, also.

@krmayankk
Copy link
Author

krmayankk commented Sep 20, 2017 via email

k8s-github-robot pushed a commit that referenced this pull request Oct 12, 2017
Automatic merge from submit-queue.

add author to my proposal for reachability

See here #756
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Nov 30, 2017
Automatic merge from submit-queue (batch tested with PRs 56589, 56503). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

MustRunAsNonRoot should reject a pod if it has non-numeric USER

**What this PR does / why we need it**:
This PR modifies kubelet behavior to reject pods with non-numeric USER instead of showing a warning.

**Special notes for your reviewer**:
Related discussion: kubernetes/community#756 (comment)

**Release note**:
```release-note
kubelet: fix bug where `runAsUser: MustRunAsNonRoot` strategy didn't reject a pod with a non-numeric `USER`.
```

PTAL @pweil- @tallclair @liggitt @Random-Liu
CC @simo5 @adelton
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Mar 1, 2018
Automatic merge from submit-queue (batch tested with PRs 52077, 60456, 60591). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

API Changes for RunAsGroup

First set of api changes for feature kubernetes/community#756
```release-note
Add ability to control primary GID of containers through pod Spec and PodSecurityPolicy
```
sttts pushed a commit to sttts/api that referenced this pull request Mar 2, 2018
Automatic merge from submit-queue (batch tested with PRs 52077, 60456, 60591). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

API Changes for RunAsGroup

First set of api changes for feature kubernetes/community#756
```release-note
Add ability to control primary GID of containers through pod Spec and PodSecurityPolicy
```

Kubernetes-commit: 16980f21d167b0166de7fb029e80f5da37ff2ebe
k8s-publishing-bot added a commit to kubernetes/api that referenced this pull request Mar 2, 2018
Automatic merge from submit-queue (batch tested with PRs 52077, 60456, 60591). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

API Changes for RunAsGroup

First set of api changes for feature kubernetes/community#756
```release-note
Add ability to control primary GID of containers through pod Spec and PodSecurityPolicy
```

Kubernetes-commit: 16980f21d167b0166de7fb029e80f5da37ff2ebe
justaugustus pushed a commit to justaugustus/enhancements that referenced this pull request Sep 3, 2018
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
MadhavJivrajani pushed a commit to MadhavJivrajani/community that referenced this pull request Nov 30, 2021
Automatic merge from submit-queue

Allow specifying the primary group id of the container

Allows specifying the Primary Group ID of the container, in addition to Primary User Id when running in Docker similar to how docker supports this.
MadhavJivrajani pushed a commit to kubernetes/design-proposals-archive that referenced this pull request Nov 30, 2021
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
MadhavJivrajani pushed a commit to MadhavJivrajani/design-proposals that referenced this pull request Dec 1, 2021
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
MadhavJivrajani pushed a commit to MadhavJivrajani/design-proposals that referenced this pull request Dec 1, 2021
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
MadhavJivrajani pushed a commit to MadhavJivrajani/design-proposals that referenced this pull request Dec 1, 2021
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
MadhavJivrajani pushed a commit to kubernetes/design-proposals-archive that referenced this pull request Dec 1, 2021
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
MadhavJivrajani pushed a commit to kubernetes/design-proposals-archive that referenced this pull request Dec 1, 2021
Automatic merge from submit-queue.

add author to my proposal for reachability

See here kubernetes/community#756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.