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

Feature: Let users set allowPrivilegeEscalation = false on ksvc. #13395

Merged
merged 1 commit into from
Oct 15, 2022

Conversation

mattmoor
Copy link
Member

🎁 This allows used to specify allowPrivilegeEscalation (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug

Knative services can now specify securityContext.allowPrivilegeEscalation

/cc @dprotaso @evankanderson @psschwei

🎁 This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug
@knative-prow knative-prow bot added kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/API API objects and controllers labels Oct 14, 2022
@codecov
Copy link

codecov bot commented Oct 14, 2022

Codecov Report

Base: 86.43% // Head: 86.45% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (1c01bd9) compared to base (f9a75d7).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13395      +/-   ##
==========================================
+ Coverage   86.43%   86.45%   +0.01%     
==========================================
  Files         196      196              
  Lines       14549    14551       +2     
==========================================
+ Hits        12576    12580       +4     
+ Misses       1673     1671       -2     
  Partials      300      300              
Impacted Files Coverage Δ
pkg/apis/serving/fieldmask.go 95.56% <100.00%> (+0.01%) ⬆️
pkg/reconciler/revision/background.go 89.09% <0.00%> (-1.82%) ⬇️
pkg/autoscaler/scaling/multiscaler.go 88.59% <0.00%> (+1.34%) ⬆️
pkg/reconciler/configuration/configuration.go 84.36% <0.00%> (+1.42%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@evankanderson
Copy link
Member

Does the GKE security posture dashboard line up with the Pod Security Standards published by Kubernetes (and the Pod Security Admission feature in 1.24 and 1.25)?

I couldn't see any indication either way.

I wish that Kubernetes had a reasonable way of turning on these security features automatically for users. In particular, the restricted profile requires the following entries:

allowPrivilegeEscalation: false
runAsNonRoot: true
seccompProfile:
  type: RuntimeDefault  # or Localhost
capabilities:
  drop: [ALL]

The baseline profile allows the above fields to be undefined as well as the "safe" values.

With the exception of runAsNonRoot (which may break many user containers, I wonder if defaulting in the following would be reasonable if fields are unset):

allowPrivilegeEscalation: false
seccompProfile:
  type: RuntimeDefault  # or Localhost
capabilities:
  drop: [ALL]
  add: [NET_BIND_SERVICE]  # allow bind to low ports as non-root

I think we might want to put this behind a feature flag, and flip the flag forward for the January release (1.9).

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

I'll see about sending a PR for the feature to default to more secure.

An extra-bonus that I'll look at later is pulling the effective user ID when we resolve the OCI image; if the userId is non-zero or specified as non-zero in the SecurityContext, I can set runAsNonRoot: true to allow Knative Services to run under the restricted profile by default, which would be nice.

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Oct 15, 2022
@knative-prow
Copy link

knative-prow bot commented Oct 15, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, 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 knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 15, 2022
@knative-prow knative-prow bot merged commit a18077c into knative:main Oct 15, 2022
@mattmoor mattmoor deleted the allow-specifying-privesc branch October 15, 2022 17:17
@mattmoor
Copy link
Member Author

An extra-bonus that I'll look at later is pulling the effective user ID when we resolve the OCI image; if the userId is non-zero or specified as non-zero in the SecurityContext, I can set runAsNonRoot: true to allow Knative Services to run under the restricted profile by default, which would be nice

@evankanderson one gotcha with this is that the user can be specified as either USER 1234 or USER nonroot. The latter requires reading /etc/passwd, which in the worst case requires fetching the entire image 😞 (and I think used to upset some PSP enforcement). This is why we default to numeric USER in Chainguard Images fwiw.

mattmoor added a commit to mattmoor/hakn that referenced this pull request Oct 15, 2022
mattmoor added a commit to mattmoor/hakn that referenced this pull request Oct 15, 2022
mattmoor added a commit to chainguard-dev/hakn that referenced this pull request Oct 16, 2022
@mattmoor
Copy link
Member Author

I didn't realize y'all had forked the source of truth for our fieldmasking, so unfortunately this missed the CRD schema 😞

I'll send a PR to update that shortly, so the CRD configs include these fields.

mattmoor added a commit to mattmoor/serving that referenced this pull request Oct 16, 2022
…dmask.

🐛 My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395
knative-prow bot pushed a commit that referenced this pull request Oct 16, 2022
…dmask. (#13402)

🐛 My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: #13395
skonto pushed a commit to skonto/serving that referenced this pull request Oct 19, 2022
…native#13395)

🎁 This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug
skonto pushed a commit to skonto/serving that referenced this pull request Oct 19, 2022
…dmask. (knative#13402)

🐛 My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395
skonto pushed a commit to skonto/serving that referenced this pull request Oct 27, 2022
…native#13395)

🎁 This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug
skonto pushed a commit to skonto/serving that referenced this pull request Oct 27, 2022
…dmask. (knative#13402)

🐛 My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395
openshift-merge-robot pushed a commit to openshift/knative-serving that referenced this pull request Oct 27, 2022
…ion (#1282)

* Feature: Let users set `allowPrivilegeEscalation = false` on ksvc. (knative#13395)

:gift: This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug

* Fix: Add the new `AllowPrivilegeEscalation` field to the *other* fieldmask. (knative#13402)

:bug: My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395

* add allowPrivilegeEscalation to manifests

Co-authored-by: Matt Moore <[email protected]>
skonto added a commit to skonto/serving that referenced this pull request Nov 16, 2022
…ion (knative#1282)

* Feature: Let users set `allowPrivilegeEscalation = false` on ksvc. (knative#13395)

:gift: This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug

* Fix: Add the new `AllowPrivilegeEscalation` field to the *other* fieldmask. (knative#13402)

:bug: My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395

* add allowPrivilegeEscalation to manifests

Co-authored-by: Matt Moore <[email protected]>
openshift-merge-robot pushed a commit to openshift-knative/serving that referenced this pull request Nov 16, 2022
…e` on ksvc. (#18)

* [RELEASE-1.5] [BACKPORT] Feature: Let users set allowPrivilegeEscalation (knative#1282)

* Feature: Let users set `allowPrivilegeEscalation = false` on ksvc. (knative#13395)

:gift: This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug

* Fix: Add the new `AllowPrivilegeEscalation` field to the *other* fieldmask. (knative#13402)

:bug: My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395

* add allowPrivilegeEscalation to manifests

Co-authored-by: Matt Moore <[email protected]>

* Add missing allowPrivilegeEscalation patch into 1-serving-crds.yaml (knative#1301)

* fix download script

Co-authored-by: Matt Moore <[email protected]>
Co-authored-by: Kenjiro Nakayama <[email protected]>
openshift-merge-robot pushed a commit to openshift-knative/serving that referenced this pull request Dec 22, 2022
…e` on ksvc. (#18) (#90)

* [RELEASE-1.5] [BACKPORT] Feature: Let users set allowPrivilegeEscalation (knative#1282)

* Feature: Let users set `allowPrivilegeEscalation = false` on ksvc. (knative#13395)

:gift: This allows used to specify `allowPrivilegeEscalation` (in particular to false) to ensure that processes cannot escalate privileges.

Kicking the tires on the new GKE security posture dashboard, I noticed that ~all Knative services get flagged for this despite Knative not allowing me to set it to false!

https://cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard

/kind bug

* Fix: Add the new `AllowPrivilegeEscalation` field to the *other* fieldmask. (knative#13402)

:bug: My previous changed missed the new config file that controls how the CRD schema is updated.

You can now clearly see the fields being added to the schemas.

Apologies for the break, I had no clue this was a thing!

/kind bug

Related: knative#13395

* add allowPrivilegeEscalation to manifests

Co-authored-by: Matt Moore <[email protected]>

* Add missing allowPrivilegeEscalation patch into 1-serving-crds.yaml (knative#1301)

* fix download script

Co-authored-by: Matt Moore <[email protected]>
Co-authored-by: Kenjiro Nakayama <[email protected]>

Co-authored-by: Stavros Kontopoulos <[email protected]>
Co-authored-by: Matt Moore <[email protected]>
Co-authored-by: Kenjiro Nakayama <[email protected]>
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 kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants