Skip to content

Run all containers as non-root user - #3237

Merged
knative-prow-robot merged 3 commits into
knative:masterfrom
bradhoekstra:non-root
Jun 21, 2019
Merged

knative-prow-robot merged 3 commits into
knative:masterfrom
bradhoekstra:non-root

Conversation

@bradhoekstra

Copy link
Copy Markdown
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

@knative-prow-robot knative-prow-robot 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.

@bradhoekstra: 0 warnings.

Details

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
Copy Markdown
Contributor Author

/assign @mattmoor

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

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

Comment thread config/controller.yaml 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
Copy Markdown
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.

Comment thread config/webhook.yaml Resolved
@bradhoekstra

Copy link
Copy Markdown
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
Comment thread config/activator.yaml Resolved
Comment thread config/activator.yaml Resolved
Comment thread config/autoscaler.yaml Resolved
Comment thread config/webhook.yaml Resolved
@bradhoekstra

Copy link
Copy Markdown
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

pmorie commented Mar 5, 2019

Copy link
Copy Markdown
Contributor

Does ko have a facility for controlling image metadata?

@mattmoor

mattmoor commented Mar 6, 2019

Copy link
Copy Markdown
Contributor

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

@pmorie

pmorie commented May 23, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

@pmorie Action taken GoogleContainerTools/distroless#368

@dprotaso

Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread .ko.yaml Resolved
@bradhoekstra

Copy link
Copy Markdown
Contributor Author

Rebase and try again...

@bradhoekstra

Copy link
Copy Markdown
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
Copy Markdown
Contributor

/retest

@mattmoor

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

/retest

@mattmoor

Copy link
Copy Markdown
Contributor

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

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

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

Comment thread config/controller.yaml
- name: METRICS_DOMAIN
value: knative.dev/serving
securityContext:
allowPrivilegeEscalation: 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.

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

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.

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
Copy Markdown
Contributor Author

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

@bradhoekstra

Copy link
Copy Markdown
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

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

/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
Copy Markdown
Contributor

/approve

@knative-prow-robot

Copy link
Copy Markdown
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

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

@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
Copy Markdown
Contributor Author

/retest

3 similar comments
@bradhoekstra

Copy link
Copy Markdown
Contributor Author

/retest

@bradhoekstra

Copy link
Copy Markdown
Contributor Author

/retest

@mattmoor

Copy link
Copy Markdown
Contributor

/retest

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

yu2003w commented Jun 22, 2019 •

Copy link
Copy Markdown
Contributor

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.

Comment thread .ko.yaml
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
Copy Markdown
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
Copy Markdown
Contributor

Sounds like we should enable PodSecurityPolicy in our test setup.

GoogleContainerTools/distroless#375 should fix this.

@dprotaso

dprotaso commented Jun 24, 2019 •

Copy link
Copy Markdown
Member

@yu2003w what's your exact pod security policy?

@yu2003w

yu2003w commented Jun 24, 2019

Copy link
Copy Markdown
Contributor

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