Skip to content

Added PodSecurityPolicy support required by istio sidecar - #4500

Closed
yu2003w wants to merge 1 commit into
knative:masterfrom
yu2003w:issue#4480
Closed

yu2003w wants to merge 1 commit into
knative:masterfrom
yu2003w:issue#4480

Conversation

@yu2003w

@yu2003w yu2003w commented Jun 24, 2019

Copy link
Copy Markdown
Contributor

Signed-off-by: Wei Yu(Jared) [email protected]

Fixes #4480

Proposed Changes

Release Note

None

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 24, 2019
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 24, 2019
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 24, 2019
@knative-prow-robot

Copy link
Copy Markdown
Contributor

Hi @yu2003w. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

Comment thread config/204-psp.yaml
spec:
allowPrivilegeEscalation: true
allowedCapabilities:
- 'NET_ADMIN'

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.

We only need this for cases where we install istio with sidecar injection enabled, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, serving activator and autoscaler need "NET_ADMIN" to startup.

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.

I think I'd rather have this in test/config until we figure out if/what we want to ship.

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.

@yu2003w I don't think it's the actual activator/autoscaler but rather the istio sidecars (or init containers in this case) that need these permissions.

@yu2003w yu2003w Jun 24, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@markusthoemmes Sorry, I misunderstood that. It's Istio sidecar needs the permission.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mattmoor Moved psp.yaml to test/config.
When both psp and Istio sidecar automatically injection are enabled, deployments in namespace serving-tests also need 'NET_ADMIN'. So I also defined role and rolebinding within namespace serving-tests.

Comment thread config/204-psp.yaml
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny

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.

Do these things need to be as permissive as they are given that we've stopped running as root?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because these fields are mandatory, without them, PSP couldn't created.
Without them following errors will be reported

error: error validating "psp.yaml": error validating data: [ValidationError(PodSecurityPolicy.spec): missing required field "seLinux" in io.k8s.api.extensions.v1beta1.PodSecurityPolicySpec, ValidationError(PodSecurityPolicy.spec): missing required field "runAsUser" in io.k8s.api.extensions.v1beta1.PodSecurityPolicySpec, ValidationError(PodSecurityPolicy.spec): missing required field "supplementalGroups" in io.k8s.api.extensions.v1beta1.PodSecurityPolicySpec, ValidationError(PodSecurityPolicy.spec): missing required field "fsGroup" in io.k8s.api.extensions.v1beta1.PodSecurityPolicySpec]; if you choose to ignore these errors, turn validation off with --validate=false

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.

I'm pretty new to PSP, but this looks like it allows us to do anything, so I'm curious how this is an improvement over where we were prior to :nonroot?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, if PSP is used, :nonroot images is not necessary any more.
Another choice is hand over PSP related stuff to cluster administrator to handle.

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.

Now I am more confused :)

If PSP validates the USER then shouldn't it block our controllers, which run as root (without :nonroot)?

Maybe the answer is that I need to read what this does...

@yu2003w yu2003w Jun 26, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If PSP validates user and container needs to be run as root, it will be blocked.
For example, I created psp for Knative serving as below,

root@filmy1:/mnt/data/gowork/src/github.com/knative/serving# knative get psp knative-serving-psp
NAME                  PRIV   CAPS        SELINUX    RUNASUSER          FSGROUP    SUPGROUP   READONLYROOTFS   VOLUMES
knative-serving-psp   true   NET_ADMIN   RunAsAny   MustRunAsNonRoot   RunAsAny   RunAsAny   false            *

Then I build knative serving with base images ubuntu which need to run as root.
Pod failed to start as below,

  Normal   Pulling    3m34s                 kubelet, 172.16.17.35  pulling image "icpdev.icp:8500/imgrepo/controller-43f0364ab2f6dab17267e80a1f6a4adc@sha256:4806fc2cc89330d8731385033012f4f04ebc43d5f4918af999b7528162e9dd2b"
  Normal   Pulled     3m30s                 kubelet, 172.16.17.35  Successfully pulled image "icpdev.icp:8500/imgrepo/controller-43f0364ab2f6dab17267e80a1f6a4adc@sha256:4806fc2cc89330d8731385033012f4f04ebc43d5f4918af999b7528162e9dd2b"
  Warning  Failed     76s (x12 over 3m30s)  kubelet, 172.16.17.35  Error: container has runAsNonRoot and image will run as root
  Normal   Pulled     76s (x11 over 3m29s)  kubelet, 172.16.17.35  Container image "icpdev.icp:8500/imgrepo/controller-43f0364ab2f6dab17267e80a1f6a4adc@sha256:4806fc2cc89330d8731385033012f4f04ebc43d5f4918af999b7528162e9dd2b" already present on machine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If Istio auto injection is enabled, it needs capability of 'NET_ADMIN' and needs to be run as root. And RunAsUser in psp should be set to RunAsAny.

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.

Ok, so tl;dr this is the PSP one needs with Istio Mesh, which is scary.

What I'm wondering is what knative/serving needs when run without sidecars, e.g. istio-lean.yaml?

My hope was for us to be less scary (and use PSP to verify that), but I see little value in testing it in scenarios where the mesh potentially masks all of our work. If we end up needing two PSPs (mesh and no-mesh) that's fine, and we can tweak scripts to install the right ones.

thanks for your patience while I wrap my head around this.

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/test-and-release It flags unit/e2e/conformance/perf test issues for product features size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 25, 2019
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2019
@knative-prow-robot knative-prow-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 Jun 27, 2019

@markusthoemmes markusthoemmes left a comment

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.

/ok-to-test

We should indeed be a lot less scary in plain Knative. As this is only needed if we install via Istio, I'd be quite hesitant to require such privileges unconditionally.

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 1, 2019
@yu2003w

yu2003w commented Jul 4, 2019

Copy link
Copy Markdown
Contributor Author

Currently no api could be used for determine which admission controller are enabled.
When such API available, if Istio and PodSecurityPolicy are detected, PSP should be created.
kubernetes/kubernetes#79735

@markusthoemmes

Copy link
Copy Markdown
Contributor

@yu2003w right, so should we hide this behind a label so users only install this if they really need it?

On another note: This is kinda only related to istio and the way its configured. It's not really about Knative itself. Should this move into third_party and be documented accordingly?

/assign @mattmoor

@mattmoor

mattmoor commented Jul 9, 2019

Copy link
Copy Markdown
Contributor

I have mixed feelings about this. This is it's effectively testing Istio, not Knative, as it is oriented into such a permissive mode almost entirely driven by the injected sidecar. I'm skeptical that it provides any meaningful coverage of Knative itself.

I actually like @markusthoemmes third_party suggestion best. Could we attach this permissive PSP to the mesh version of istio and a more restrictive PSP to the lean install (that's more representative of Knative)?

@markusthoemmes

Copy link
Copy Markdown
Contributor

Not sure why this was moved to test/config @yu2003w. I think this can be useful in mesh-cases and if the user wants to install istio. As such, I think it can live under third-party/istio*

@yu2003w

yu2003w commented Jul 15, 2019

Copy link
Copy Markdown
Contributor Author

Not sure why this was moved to test/config @yu2003w. I think this can be useful in mesh-cases and if the user wants to install istio. As such, I think it can live under third-party/istio*

Sorry, I just read the comments.
At first, when I initiated this PR, we don't have a clear idea about how to handler PSP. I just added the object needed when PodSecurityPolicy is enabled. So I moved that to test/config.
It's a good idea to move that to thirdparty. I will update this PR.

@yu2003w yu2003w changed the title Added PodSecurityPolicy support for activator and autoscaler. Added PodSecurityPolicy support required by istio sidecar Jul 17, 2019
@yu2003w
yu2003w force-pushed the issue#4480 branch 2 times, most recently from e703dee to 271675d Compare July 17, 2019 06:32
@yu2003w

yu2003w commented Jul 17, 2019 •

Copy link
Copy Markdown
Contributor Author

@markusthoemmes I move the PSP related stuff to thirdparty/istio-psp.yaml.
If PodSecurityPolicy is enabled, user could apply Istio-psp.yaml when install knative serving.

@mattmoor

Copy link
Copy Markdown
Contributor

Moving to test/config was so this got deployed when testing, with the latest round of changes we won't test this at all. Honestly, I'm most interested in the "lean" PSP, which should be a truer reflection of the Knative PSP implications.

Can we add:

  1. a "lean" PSP that accurately reflects the required PSP without a mesh
  2. add logic to install the appropriate PSP alongside istio

… is enabled in k8s cluster, user should also

run 'kubectl apply -f ./thirdparty/istio-psp.yaml' before installing knative serving.

Signed-off-by: Wei Yu(Jared) <[email protected]>
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 22, 2019
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yu2003w
To complete the pull request process, please assign mattmoor
You can assign the PR to them by writing /assign @mattmoor in a comment when ready.

The full list of commands accepted by this bot can be found 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

@yu2003w

yu2003w commented Jul 22, 2019 •

Copy link
Copy Markdown
Contributor Author

@mattmoor I added back psp related files to test/config/psp. To run tests with PodSecurityPolicy enabled, user could run 'ko apply -f test/config -f test/config/psp' to generate necessary stuff.

I think that PSP is not needed if mesh is not enabled.(label of Istio-injection is not enabled for namespace)
Because if PodSecurityPolicy is enabled, at least platform should have provisioned 'lean' psp as default psp.

After testing, I found that only volume types of 'configMap', 'emptyDir' and 'secret' are needed for istio sidecar. So istio-psp.yaml is updated.

Currently, maybe it's impossible to add logic to install appropriate psp along side with istio because it's difficult to determine which admission plugin are enabled when k8s api-server is started. kubernetes#79735

It's possibly psp couldn't be installed alongside with istio automatically until kubernetes#79735 is resolved.

If I misunderstood something or any other comments, please let me know.

Thanks.

@mattmoor

Copy link
Copy Markdown
Contributor

Currently, maybe it's impossible to add logic to install appropriate psp along side with istio because it's difficult to determine which admission plugin are enabled when k8s api-server is started. kubernetes#79735

I understand that in general, however, we know which Istio each of our test setups install. My hope was that we could configure the appropriate PSP with each of them vs. having a "lowest common demoninator" PSP that leaves a hole so big (due to the sidecar requirements) that you could drive a truck through it :(

Like I said, the most interesting PSP to me isn't LCD(serving, istio w/ sidecar) it is really something that paints an accurate picture of the serving requirements. I think this is best captured by LCD(serving, istio w/o sidecar).

Perhaps we could try to schedule a call to discuss this further because going back and forth here seems to be going in circles, and I'd like to make the best use of everyone's time. Want to follow up in #networking or a group chat?

@markusthoemmes

Copy link
Copy Markdown
Contributor

Any updates? Been hanging for a good 3 months now with no activity.

@markusthoemmes

Copy link
Copy Markdown
Contributor

It hung another month. Closing for now, feel free to reopen if still valid.

/close

@knative-prow-robot

Copy link
Copy Markdown
Contributor

@markusthoemmes: Closed this PR.

Details

In response to this:

It hung another month. Closing for now, feel free to reopen if still valid.

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test-and-release It flags unit/e2e/conformance/perf test issues for product features cla: yes Indicates the PR's author has signed the CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Enable PodSecurityPolicy in our test environment

6 participants