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

Run all containers as non-root user #3237

Merged
merged 3 commits into from
Jun 21, 2019

Conversation

bradhoekstra
Copy link
Contributor

Related to #3001

Proposed Changes

  • Run all containers as a non-root user

Release Note

Serving containers no longer run as root

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 15, 2019
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.

@bradhoekstra: 0 warnings.

In response to this:

Related to #3001

Proposed Changes

  • Run all containers as a non-root user

Release Note

Serving containers no longer run as root

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.

@bradhoekstra bradhoekstra marked this pull request as ready for review February 15, 2019 16:41
@bradhoekstra
Copy link
Contributor Author

/assign @mattmoor

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

Should there be an integration test validating this? Akin to contract e2e tests?

pkg/reconciler/v1alpha1/revision/resources/queue.go Outdated Show resolved Hide resolved
config/controller.yaml Outdated Show resolved Hide resolved
@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 Feb 15, 2019
@bradhoekstra
Copy link
Contributor Author

Should there be an integration test validating this? Akin to contract e2e tests?

That seems like a good idea, I can file an issue to follow up on that.

@bradhoekstra
Copy link
Contributor Author

/hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 15, 2019
config/activator.yaml Outdated Show resolved Hide resolved
config/activator.yaml Outdated Show resolved Hide resolved
config/autoscaler.yaml Show resolved Hide resolved
config/webhook.yaml Show resolved Hide resolved
@bradhoekstra
Copy link
Contributor Author

I brought up the idea of building/publishing a nonroot image directly in distroless, but it was turned down: GoogleContainerTools/distroless#306.

If we want a nonroot base image, it looks like we will have to build and publish that ourselves.

@pmorie
Copy link
Member

pmorie commented Mar 5, 2019

Does ko have a facility for controlling image metadata?

@mattmoor
Copy link
Member

mattmoor commented Mar 6, 2019

@pmorie No, I'd expect ko to inherit this from the base image.

@pmorie
Copy link
Member

pmorie commented May 23, 2019

Circling back on this - I am not sure where to take things from here. @mattmoor do you have any idea whether GoogleContainerTools/distroless#235 will be actionable?

@dprotaso
Copy link
Member

@pmorie Action taken GoogleContainerTools/distroless#368

@dprotaso
Copy link
Member

Bump @bradhoekstra GoogleContainerTools/distroless#368 merged so you should have non-root distroless images to leverage now.

If you've moved onto other things let us know and I can close/redo this PR.

@bradhoekstra
Copy link
Contributor Author

I can update this PR to use the new tags.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 19, 2019
@knative-prow-robot knative-prow-robot added the area/API API objects and controllers label Jun 19, 2019
.ko.yaml Outdated Show resolved Hide resolved
@bradhoekstra
Copy link
Contributor Author

Rebase and try again...

@bradhoekstra
Copy link
Contributor Author

The only thing that I can think may be happening is that another test run is uploading to the same repository and colliding with this one creating a race.

Can the boskos project be shared by multiple jobs at once?

@mattmoor
Copy link
Member

/retest

@mattmoor
Copy link
Member

@bradhoekstra the failure looks legit:

service.go:141: Successfully created Service should-run-as-user-container-default-giwossyq
user_test.go:93: uid = 0, want: 65532
user_test.go:99: euid = 0, want: 65532				

@mattmoor
Copy link
Member

This is puzzling because if I deploy this image with the .ko.yaml I get:

		"user": {
			"uid": 65532,
			"euid": 65532,
			"gid": 65532,
			"egid": 65532
		}

@mattmoor
Copy link
Member

/retest

@mattmoor
Copy link
Member

FWIW, this passed for me locally, so I'm puzzled. One thing that comes to mind is that maybe .ko.yaml was ignored, but IDK how the prior base image would have been picked up...

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

This looks awesome throughout! I've got one question left regarding the securityContext and one small nit.

pkg/reconciler/revision/resources/queue.go Outdated Show resolved Hide resolved
@@ -64,6 +64,8 @@ spec:
value: config-observability
- name: METRICS_DOMAIN
value: knative.dev/serving
securityContext:
allowPrivilegeEscalation: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate on why this is needed to be set explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This stops the user from being able to sudo or otherwise elevate privileges, without it starting the container as a non-root user does not mean the user cannot become root afterwards.

A good explanation is here: https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privilege-escalation

@bradhoekstra
Copy link
Contributor Author

Somehow the tests passed now, maybe it was an issue due to project sharing?

@bradhoekstra
Copy link
Contributor Author

A thought: if the integration problem is due to the project sharing then merging this change may cause all sort of issues for PR integration tests until all PRs have picked up this change.

Change-Id: I77370d1f198276f59e6033d8515d2c438c8f47c7
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

/lgtm

I don't think that's the problem, I suspect that we should log the raw data payload for debugging...

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 21, 2019
@mattmoor
Copy link
Member

/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bradhoekstra, mattmoor

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2019
@bradhoekstra
Copy link
Contributor Author

/retest

3 similar comments
@bradhoekstra
Copy link
Contributor Author

/retest

@bradhoekstra
Copy link
Contributor Author

/retest

@mattmoor
Copy link
Member

/retest

@knative-prow-robot knative-prow-robot merged commit aa48603 into knative:master Jun 21, 2019
@yu2003w
Copy link
Contributor

yu2003w commented Jun 22, 2019

when deploying latest serving code from master branch, encounter errors as below,

Warning  Failed     7s (x4 over 22s)  kubelet, 172.16.17.35  Error: container has runAsNonRoot and image has non-numeric user (nonroot), cannot verify user is non-root

In my environment, PodSecurityPolicy is enabled.

baseImageOverrides:
github.com/knative/serving/test/test_images/runtime-unprivileged: jenkins/jenkins:lts-slim
# Use :nonroot base image for all containers
defaultBaseImage: gcr.io/distroless/static:nonroot
Copy link
Contributor

Choose a reason for hiding this comment

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

If PodSecurityPolicy is enabled, this base image doesn't work.
Hit error as

"Warning  Failed     7s (x4 over 22s)  kubelet, 172.16.17.35  Error: container has runAsNonRoot and image has non-numeric user (nonroot), cannot verify user is non-root"

@mattmoor
Copy link
Member

Sounds like we should enable PodSecurityPolicy in our test setup.

GoogleContainerTools/distroless#375 should fix this.

@dprotaso
Copy link
Member

dprotaso commented Jun 24, 2019

@yu2003w what's your exact pod security policy?

@yu2003w
Copy link
Contributor

yu2003w commented Jun 24, 2019

@dprotaso I have submitted PR.#4500

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 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. 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.