Skip to content

API Changes for RunAsGroup#52077

Merged
k8s-github-robot merged 1 commit intokubernetes:masterfrom
krmayankk:runas
Mar 1, 2018
Merged

API Changes for RunAsGroup#52077
k8s-github-robot merged 1 commit intokubernetes:masterfrom
krmayankk:runas

Conversation

@krmayankk
Copy link
Copy Markdown

@krmayankk krmayankk commented Sep 7, 2017

First set of api changes for feature kubernetes/community#756

Add ability to control primary GID of containers through Pod Spec and PodSecurityPolicy

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 7, 2017
@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Sep 7, 2017
@k8s-github-robot
Copy link
Copy Markdown

Adding do-not-merge/release-note-label-needed because the release note process has not been followed.
One of the following labels is required "release-note", "release-note-action-required", or "release-note-none".
Please see: https://github.com/kubernetes/community/blob/master/contributors/devel/pull-requests.md#write-release-notes-if-needed.

@k8s-github-robot k8s-github-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Sep 7, 2017
@dashpole
Copy link
Copy Markdown
Contributor

dashpole commented Sep 7, 2017

/unassign
/assign @pmorie

Copy link
Copy Markdown

@cmluciano cmluciano left a comment

Choose a reason for hiding this comment

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

Can you please separate this into controller changes, api changes, generated code? I'm having a hard time finding all the parts that changed while reviewing.

The test failures that you noted are due to the roundtrip fuzzer receiving a nil value when it injects something in.

This can happen for a number of reasons:

  • conversion code is not accurate (if manually crafted)
  • fuzzer is filling the value with an improperly formatted type (requires changes to the fuzzer)
  • new required fields are added without defaults (doesn't seem to be the case here)
  • not all supported APIs (v1beta1,v1,etc) have the necessary changes in their types
object.Spec.Template.Spec.Containers[0].SecurityContext.RunAsGroup:
	  a: (*int64)(0xc4207c10d8)
	  b: <nil>

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2017
const (
// container must run as a particular gid.
RunAsGroupStrategyMustRunAs RunAsGroupStrategy = "MustRunAs"
// container must run as a non-root uid
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

gid?

RunAsGroupStrategyMustRunAs RunAsGroupStrategy = "MustRunAs"
// container must run as a non-root uid
RunAsGroupStrategyMustRunAsNonRoot RunAsGroupStrategy = "MustRunAsNonRoot"
// container may make requests for any uid.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

gid?

return autoConvert_extensions_PodSecurityPolicySpec_To_v1beta1_PodSecurityPolicySpec(in, out, s)
}

func Convert_v1beta1_PodSecurityPolicySpec_To_extensions_PodSecurityPolicySpec(in *extensionsv1beta1.PodSecurityPolicySpec, out *extensions.PodSecurityPolicySpec, s conversion.Scope) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this added as a manual conversion?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

frankly i dont know how to auto generate it , i ran all hack/updatexxx and didn't see it generated. if you have suggestions let me know

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@krmayankk what is the output from the generator when you tried to generate the conversions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if you remove this, what fails? if all the manual conversion is doing is calling the autoConvert_... function, it shouldn't be needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It still troubles me that this is a manual conversion. That seems not-right to me.

allErrs = append(allErrs, field.NotSupported(fldPath.Child("rule"), runAsGroup.Rule, supportedRunAsGroupRules.List()))
}

// validate range settings
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it valid to specify ranges with RunAsGroupStrategyMustRunAsNonRoot or RunAsGroupStrategyRunAsAny?

Copy link
Copy Markdown
Author

@krmayankk krmayankk Sep 25, 2017

Choose a reason for hiding this comment

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

hmm , its not valid i think. The check is missing for RunAsUser as well. I will add a check if Ranges is not nil, the strategy must be MustRunAs . Adding @pmorie and @pweil- in case i am missing something

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

non-root and any do not support ranges for UID at this point cc @pmorie

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@krmayankk sounds like we need to validate that you don't get a range with a policy that doesn't support it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added the check

RunAsGroup *Int64Value `protobuf:"bytes,4,opt,name=run_as_group,json=runAsGroup" json:"run_as_group,omitempty"`
// If set, the root filesystem of the sandbox is read-only.
ReadonlyRootfs bool `protobuf:"varint,4,opt,name=readonly_rootfs,json=readonlyRootfs,proto3" json:"readonly_rootfs,omitempty"`
ReadonlyRootfs bool `protobuf:"varint,5,opt,name=readonly_rootfs,json=readonlyRootfs,proto3" json:"readonly_rootfs,omitempty"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doesn't changing proto tags here break compatibility?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixing now

// PodSecurityContext, the value specified in SecurityContext takes precedence
// for that container.
// +optional
RunAsGroup *int64 `json:"runAsGroup,omitempty" protobuf:"varint,3,opt,name=runAsGroup"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

have to take an available proto tag at the end of the range... reassigning existing numbers breaks the ability to read in previously persisted data

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixing now

// May also be set in PodSecurityContext. If set in both SecurityContext and
// PodSecurityContext, the value specified in SecurityContext takes precedence.
// +optional
RunAsGroup *int64 `json:"runAsGroup,omitempty" protobuf:"varint,5,opt,name=runAsGroup"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, use a free proto tag from the end, don't reassign existing tags

// runAsUser is the strategy that will dictate the allowable RunAsUser values that may be set.
RunAsUser RunAsUserStrategyOptions `json:"runAsUser" protobuf:"bytes,11,opt,name=runAsUser"`
// runAsGroup is the strategy that will dictate the allowable RunAsGroup values that may be set.
RunAsGroup RunAsGroupStrategyOptions `json:"runAsGroup" protobuf:"bytes,12,opt,name=runAsGroup"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

proto tag

// RunAsUser is the strategy that will dictate the allowable RunAsUser values that may be set.
RunAsUser RunAsUserStrategyOptions
// RunAsGroup is the strategy that will dictate the allowable RunAsGroup values that may be set.
RunAsGroup RunAsGroupStrategyOptions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's the default? (seems like it would have to be RunAsGroupStrategyRunAsAny for compatibility?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes thats my understanding.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then that should be populated in SetDefaults_PodSecurityPolicySpec

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 25, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 26, 2017
Copy link
Copy Markdown
Member

@liggitt liggitt Feb 27, 2018

Choose a reason for hiding this comment

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

same question here, if RunAsGroup is non-nil, do we require RunAsUser to be non-nil? what if RunAsUser is set on the pod security context, and RunAsGroup is set on the container security context?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

same RunAsGroup can be non nil and RunAsUser can be nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is that because the requirement for runasuser to be non-nil is docker specific? If other runtimes could allow that, it's fine to skip validating that here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the validation is saying that if RunAsGroup is specified at all, then it should be a valid group id. Not sure i follow your comment. Its not validating whether its specified or not. The first if is validating whether its specified at all, the second if is validating that if its specified its a valid group id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was wondering if we wanted to validate that both run as user and run as group were set, because the docker runtime will error if you set group without setting user

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes other implementations could allow that and the limitation is docker specific. for e.g. rkt allows setting both independently

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a validation for it in dockershim - it might be prudent to push that up to the API validation for now.

Copy link
Copy Markdown
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

This is really hard to review. I suggest:

  1. Split the PodSecurityPolicy changes into a separate PR
  2. Put the generated files into a separate commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this actually read anywhere?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

no, this is not implemented, only the RunAsGroup field is. there is a feature gate to disable it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: errors start with lowercase

RunAsGroup is not a string, I think you can just leave it out here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Leave this out. It should be optional.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAICT this is never being enforced?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

only the securityContext is being enforced in Container and pod spec. PSP is not being enforced and hence i added the feature gates and disabled them by default. That was the comment from @liggitt which i have been taking care

@tallclair
Copy link
Copy Markdown
Member

I don't see this making 1.10. If you disagree, please file an extension request.

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Feb 28, 2018

discussed with @tallclair and @krmayankk. Rather than merge API changes for PSP and runAsNonRootGroup before their implementation, we'd prefer limiting this PR to the single runAsGroup field in PodSecurityContext and SecurityContext, which is implemented all the way through CRI and has backing e2e tests.

These fields would still be feature gated and disabled by default, but would allow CRI implementations to integrate/test with this feature in the 1.10 timeframe (and have an e2e test that would exercise their integration).

The PSP and runAsNonRoot fields and enforcement would be continued in 1.11, and would be required to be completed before enabling the RunAsGroup feature by default.

A 1 day exception to remove the PSP and runAsNonRootGroup fields from this PR requested at https://groups.google.com/forum/#!msg/kubernetes-milestone-burndown/kq4zhEI_c-I/vLVpJlMMBAAJ

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this doc change is spurious with runAsNonRootGroup removed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pmorie is "Defaults to group specified in image metadata if unspecified." accurate? or does it default to gid 0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see this is described more fully in another field: "Defaults to group specified in image metadata if unspecified. If group is not specified in image metadata, the default is GID 0."

is that runtime-specific, or an API guarantee?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty sure that's runtime specific. I would just say something along the lines of "Uses runtime default if unset".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still outstanding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this should be an error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can you just do

user = fmt.Sprintf("%s:%d", config.User, sc.GetRunAsGroup().Value)

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: prefer "The GID to run the container's init process"

(entrypoint is a docker term)

Copy link
Copy Markdown
Member

@liggitt liggitt Feb 28, 2018

Choose a reason for hiding this comment

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

this matches RunAsUser doc... I'd leave it for now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto re: entrypoint vs init

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty sure that's runtime specific. I would just say something along the lines of "Uses runtime default if unset".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should match the other RunAsGroup doc, not say the default is GID 0

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Feb 28, 2018

moving back into the milestone per granted exception

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Feb 28, 2018

/status approved-for-milestone

Copy link
Copy Markdown
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

/cc @yujuhong for CRI changes

I skimmed this and it looks ok (1 more file to revert). I'll make another pass after dinner and approve if everything looks ok.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please revert this file.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@tallclair: GitHub didn't allow me to request PR reviews from the following users: CRI, changes, for.

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

Details

In response to this:

/cc @yujuhong for CRI changes

I skimmed this and it looks ok (1 more file to revert). I'll make another pass after dinner and approve if everything looks ok.

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.

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Mar 1, 2018

fyi, I pushed an update to the branch restoring the hack/gen-swagger-doc/example-output/definitions.html file which was unrelated to the changes in this PR:

$ git diff krmayankk/runas --numstat
5982    0       hack/gen-swagger-doc/example-output/definitions.html

$ git push --force-with-lease krmayankk HEAD:runas
To github.com:krmayankk/kubernetes.git
 + 1d5c33287c...7e31ffa0c9 HEAD -> runas (forced update)

API and test changes LGTM
/lgtm

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Mar 1, 2018

@tallclair has approval on pkg/kubelet changes

pkg approver needed for RunAsGroup feature gate

Copy link
Copy Markdown
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

Noticed one more issue with the validation. Everything else LGTM.

Please ping me on slack once you've fixed the validation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error handling here should match the error handling in the pod version - loop over the error messages.

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Mar 1, 2018

/lgtm

1 similar comment
@tallclair
Copy link
Copy Markdown
Member

/lgtm

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Mar 1, 2018

/assign @smarterclayton
Since you were most active in kubernetes/community#756
For approval of RunAsGroup feature gate

@smarterclayton
Copy link
Copy Markdown
Contributor

/approve

Based on sig approval

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: krmayankk, liggitt, pmorie, smarterclayton, tallclair

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

The pull request process is described here

Details 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-github-robot
Copy link
Copy Markdown

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

@k8s-github-robot
Copy link
Copy Markdown

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 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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.