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

Support more security context properties behind a feature flag #9060

Merged
merged 6 commits into from
Aug 14, 2020

Conversation

dprotaso
Copy link
Member

@dprotaso dprotaso commented Aug 14, 2020

Fixes #7924

Proposed Changes

  • kubernetes.podspec-securitycontext feature flag now allows you to set securityContext options on the Pod & Container
  • The Pod's context allows for runAsUser, runAsGroup, fsGroup runAsNonRoot, supplementalGroups
  • The Container's context allows for runAsUser, runAsGroup, runAsNonRoot

Release Note

- `kubernetes.podspec-securitycontext` feature flag now allows you to set `securityContext` options on the Pod & Container
-  The Pod's context allows for `runAsUser`, `runAsGroup`, `fsGroup`  `runAsNonRoot`, `supplementalGroups`
-  The Container's context allows for `runAsUser`, `runAsGroup`, `runAsNonRoot`

/assign @julz

This applies to PodSecurityContext & Container.SecurityContext

For PodSecurityContext the feature gate now allows
- fsGroup
- runAsGroup
- runAsNonRoot
- runAsUser

For Container.SecurityContext the feature gate now allows
- runAsGroup
- runAsNonRoot
@knative-prow-robot knative-prow-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 14, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@dprotaso: 2 warnings.

In response to this:

Fixes #7924

Proposed Changes

  • kubernetes.podspec-securitycontext feature flag now allows you to set securityContext options on the Pod & Container
  • The Pod's context allows for runAsUser, runAsGroup, fsGroup runAsNonRootUser
  • The Container's context allows for runAsUser, runAsGroup, runAsNonRootUser

Release Note

- `kubernetes.podspec-securitycontext` feature flag now allows you to set `securityContext` options on the Pod & Container
-  The Pod's context allows for `runAsUser`, `runAsGroup`, `fsGroup`  `runAsNonRootUser`
-  The Container's context allows for `runAsUser`, `runAsGroup`, `runAsNonRootUser`

/assign @julz

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.

pkg/apis/serving/fieldmask.go Outdated Show resolved Hide resolved
pkg/apis/serving/k8s_validation.go Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the area/API API objects and controllers label Aug 14, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 14, 2020
@dprotaso
Copy link
Member Author

dprotaso commented Aug 14, 2020

Marking it WIP since it's late and I want to go over it tomorrow - still worth putting up for review in the meantime

pkg/apis/serving/fieldmask.go Outdated Show resolved Hide resolved
return out
}

out.RunAsUser = in.RunAsUser
Copy link
Member

Choose a reason for hiding this comment

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

so one thing I feel a little weird about here that feels worth discussing. This PR ends up not just exposing some new fields on the existing userContainer.SecurityContext (that bit is totally fine), it also exposes the pod security context to the user. Previously the user couldn't touch the pod's security spec, only the spec of their own containers.

I see why we need to do this -- the fsGroup is only present at the pod level, because volumes are shared -- but it seems like quite a big new bit of surface area. For example it means the Queue proxy must now run in whatever podSecurityContext the user supplies (modulo fields that it can explicitly override in the container securityContext).

Few potential upshots of that, off the top of my head:

  • this will affect the ownership of the log volumes we mount in to queue proxy (it will arbitrarily chown them, I think..).
  • any additional sidecars that are injected will also inherit these settings, unless overridden (e.g. Istio in the mesh case, I think).
  • I've had a sneaky idea in the back of my head for a while that it'd be pretty nice to have a custom Queue Proxy that uses cgroups to pause/unpause the user container when there are no requests, for a lambda-like UX -- that likely requires giving QP elevated permissions. (etc)

Anyway, this may well be fine and reasonable, but I wanted to flag this up and make sure we explicitly think it through and decide it's ok.

Copy link
Member Author

@dprotaso dprotaso Aug 14, 2020

Choose a reason for hiding this comment

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

(modulo fields that it can explicitly override in the container securityContext).

yeah for now that being the fsGroup property - (edit) and SupplementalGroups

this will affect the ownership of the log volumes we mount in to queue proxy (it will arbitrarily chown them, I think..).

This makes me think there is an existing issue with our /var/log logging. ie. user container writes logs to an emptyDir as root (unsure if uid mapping get applied). If the daemon set logging agent was running as non-root it could have permission problems reading the logs. Don't know the k8s internals deep enough.

Anyway, this may well be fine and reasonable, but I wanted to flag this up and make sure we explicitly think it through and decide it's ok.

I think this discussion is good and surfaces some potential upstream requirements in K8s (ie. does fsGroup property on the container security context make sense). For some existing pod-spec feature flags I don't think we intent to every change the default from Disabled - this flag may fall into the same class. Thus we should aim to at least let document to operators the issues you've surfaced.

This reminds me to update the _example key of the config map

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso

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

@dprotaso dprotaso changed the title [wip] Support more security context properties behind a feature flag Support more security context properties behind a feature flag Aug 14, 2020
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 14, 2020
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/serving/fieldmask.go 97.9% 98.1% 0.1
pkg/apis/serving/k8s_validation.go 99.3% 99.3% 0.1

@dprotaso
Copy link
Member Author

/assign @mattmoor

@mattmoor
Copy link
Member

/lgtm
/hold

Holding in case @julz has anything further, but this LGTM esp. off by default.

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Aug 14, 2020
Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

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

/lgtm too
/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2020
@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-upgrade-tests 0/3

Failed non-flaky tests preventing automatic retry of pull-knative-serving-upgrade-tests:

test/upgrade.TestCreateNewServicePostUpgrade
test/upgrade.TestProbe

@dprotaso
Copy link
Member Author

/retest

@knative-prow-robot knative-prow-robot merged commit 884f4ed into knative:master Aug 14, 2020
@dprotaso dprotaso deleted the security-context branch August 14, 2020 21:52
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/API API objects and controllers cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. 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.

please support more parts of securityContext
7 participants