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

Pod security standards restricted defaults #9490

Merged
merged 66 commits into from
May 20, 2024

Conversation

sheidkamp
Copy link
Contributor

@sheidkamp sheidkamp commented May 15, 2024

Description

Update Helm templates to allow all containers' securityContexts to be defined in order to support Pod Security Standards.

Provide a flag to default all containers to a securityContext that has the minimal changes needed to conform to restricted policy.

Helm Changes

  • Add a new template to render container securityContexts and apply appropriate defaults.
  • Add a securityContext for each container that did not have one defined.
  • Add globals.podSecurityStandards to manage data related to Pod Security Standards
    • Add globals.podSecurityStandards.container to manage container-level configuration
      • Add global.podSecurityStandards.container.enableRestrictedContainerDefaults - uses restricted compliant defaults for container
      • Add global.podSecurityStandards.container.defaultSeccompProfileType - defines default seccompProfileType to use for containers.

The default securityContext when global.podSecurityStandards.container.enableRestrictedContainerDefaults is enabled is equivalent to:

securityContext:
  allowPrivilegeEscalation: false
  runAsNonRoot: true
  seccompProfile:
    type: RuntimeDefault
  capabilities:
    drop:
    - ALL

There is no variation allowed for these values, except seccompProfile.type can be Localhost instead of RuntimeDefault. That value can be configured with global.podSecurityStandards.container.defaultSeccompProfileType. capabilities.add can also be set to

Context

Users ran into this while attempted to run Gloo Edge with a Restricted Pod Security Policy

Testing steps

Manual validation

Default behavior

With a kubernetes environment created, gloo not installed, and $VERSION defined:

  • create gloo-system namespace and label as warn=restricted
kubectl create namespace gloo-system
kubectl label --overwrite namespace gloo-system pod-security.kubernetes.io/warn=restricted
  • build and package helm charts:
make generate-helm-files build-test-chart -B
  • Install gloo:
helm install gloo _test/gloo-${VERSION}.tgz --namespace gloo-system

You will see output that looks like:

W0516 12:46:38.559070   10276 warnings.go:70] would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "certgen" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "certgen" must set securityContext.capabilities.drop=["ALL"]), seccompProfile (pod or container "certgen" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
W0516 12:46:43.713909   10276 warnings.go:70] would violate PodSecurity "restricted:latest": seccompProfile (pod or container "gateway-proxy" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
W0516 12:46:43.715139   10276 warnings.go:70] would violate PodSecurity "restricted:latest": seccompProfile (pod or container "discovery" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
W0516 12:46:43.715403   10276 warnings.go:70] would violate PodSecurity "restricted:latest": seccompProfile (pod or container "gloo" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
W0516 12:46:43.719802   10276 warnings.go:70] would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "kubectl" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "kubectl" must set securityContext.capabilities.drop=["ALL"]), seccompProfile (pod or container "kubectl" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
W0516 12:46:44.012042   10276 warnings.go:70] would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "kubectl" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "kubectl" must set securityContext.capabilities.drop=["ALL"]), seccompProfile (pod or container "kubectl" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
NAME: gloo
LAST DEPLOYED: Thu May 16 12:46:36 2024
NAMESPACE: gloo-system
STATUS: deployed
REVISION: 1
TEST SUITE: None

Restricted Compliant behavior

  • Uninstall Gloo Edge:
glooctl uninstall
  • Install Gloo Edge with default restricted container securityContexts
helm install gloo _test/gloo-${VERSION}.tgz --namespace gloo-system --set global.podSecurityStandards.container.enableRestrictedContainerDefaults=true

The warnings no longer appear.

  • The namespace can be labelled to enforce the Restricted Security Standard:
k label --overwrite namespace gloo-system pod-security.kubernetes.io/enforce=restricted

And Gloo Edge can be successfully uninstalled and reinstalled.

Automated testing

Additionally, unit tests have been added/expanded, and the global.podSecurityStandards.container.enableRestrictedContainerDefaults=true has been set on the kube2e tests to ensure that functionality works with these standards applied.

The test server used for the kube2e tests uses an image that runs as root, so for the moment we are not applying the labels to the namespace in the e2e tests, instead relying on the helm flag to enforce compliance for Edge components. This can revisited if deemed worth the time and effort.

Notes for reviewers

  • Check Helm template parameter names and documentation
  • Look for any missed containers

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

sheidkamp and others added 30 commits May 10, 2024 14:46
@sheidkamp sheidkamp removed the work in progress signals bulldozer to keep pr open (don't auto-merge) label May 20, 2024
nfuden
nfuden previously approved these changes May 20, 2024
Copy link
Contributor

@bewebi bewebi left a comment

Choose a reason for hiding this comment

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

I haven't done the manual testing, but overall this passes the eye test

I'm hoping that indentation can be more consistent and/or that there can be an explanation for why it needs to be different in certain cases

changelog/v1.17.0-beta29/pod-security-standards.yaml Outdated Show resolved Hide resolved
install/helm/gloo/templates/19-gloo-mtls-certgen-job.yaml Outdated Show resolved Hide resolved
install/test/helm_test.go Outdated Show resolved Hide resolved
install/test/helm_test.go Outdated Show resolved Hide resolved
Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>
Copy link
Contributor Author

@sheidkamp sheidkamp left a comment

Choose a reason for hiding this comment

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

Updated with PR feedback

install/test/helm_test.go Outdated Show resolved Hide resolved
install/test/helm_test.go Outdated Show resolved Hide resolved
install/helm/gloo/templates/19-gloo-mtls-certgen-job.yaml Outdated Show resolved Hide resolved
bewebi
bewebi previously approved these changes May 20, 2024
Copy link
Contributor

@bewebi bewebi 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 also did some of the local validation

install/test/helm_test.go Outdated Show resolved Hide resolved
Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>
@sheidkamp sheidkamp changed the title Pod security standards retricted defaults Pod security standards restricted defaults May 20, 2024
@soloio-bulldozer soloio-bulldozer bot merged commit 54d3a5b into main May 20, 2024
25 checks passed
@soloio-bulldozer soloio-bulldozer bot deleted the pod-security-standards-retricted-defaults branch May 20, 2024 18:36
sheidkamp added a commit that referenced this pull request May 20, 2024
* first round helm changes

* gateway test secure helm

* updates

* Adding changelog file to new location

* Deleting changelog file from old location

* Update helm.yaml

* update names

* Update helm.yaml

* Update helm.yaml

* Update helm_test.go

* refactor GetStructuredDeployment

* Revert "refactor GetStructuredDeployment"

This reverts commit c7325a8.

* All the containers

* generated

* generate and k8s-utils

* Update pod-security-standards.yaml

* Update 7-gateway-proxy-deployment.yaml

* Start of pod security defaults

* Update pod-security-standards.yaml

* updates

* More container updates

* steps - can;t apply defaults

* Helm fixes and add to kube2e helm

* whitespace cleanup

* Update helm-override.yaml

* tests

* add seccompTypeValue

* Update helm_test.go

* Update pod-security-standards.yaml

* Update pod-security-standards.yaml

* Update pod-security-standards.yaml

* Update _helpers.tpl

* Update values.go

* Adding changelog file to new location

* Deleting changelog file from old location

* Update _helpers.tpl

* update template to take ".indent" argument

* Update _helpers.tpl

* generate

* Update _helpers.tpl

* Update _helpers.tpl

* Update changelog/v1.17.0-beta29/pod-security-standards.yaml

Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>

* indenting includes

* PR feedback

* Update install/test/helm_test.go

Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: changelog-bot <changelog-bot>
Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>
soloio-bulldozer bot added a commit that referenced this pull request May 21, 2024
* Pod security standards restricted defaults (#9490)

* first round helm changes

* gateway test secure helm

* updates

* Adding changelog file to new location

* Deleting changelog file from old location

* Update helm.yaml

* update names

* Update helm.yaml

* Update helm.yaml

* Update helm_test.go

* refactor GetStructuredDeployment

* Revert "refactor GetStructuredDeployment"

This reverts commit c7325a8.

* All the containers

* generated

* generate and k8s-utils

* Update pod-security-standards.yaml

* Update 7-gateway-proxy-deployment.yaml

* Start of pod security defaults

* Update pod-security-standards.yaml

* updates

* More container updates

* steps - can;t apply defaults

* Helm fixes and add to kube2e helm

* whitespace cleanup

* Update helm-override.yaml

* tests

* add seccompTypeValue

* Update helm_test.go

* Update pod-security-standards.yaml

* Update pod-security-standards.yaml

* Update pod-security-standards.yaml

* Update _helpers.tpl

* Update values.go

* Adding changelog file to new location

* Deleting changelog file from old location

* Update _helpers.tpl

* update template to take ".indent" argument

* Update _helpers.tpl

* generate

* Update _helpers.tpl

* Update _helpers.tpl

* Update changelog/v1.17.0-beta29/pod-security-standards.yaml

Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>

* indenting includes

* PR feedback

* Update install/test/helm_test.go

Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: changelog-bot <changelog-bot>
Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>

* generate and changelog

* test fixes

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Bernie Birnbaum <bewebi@earthlink.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep pr updated signals bulldozer to keep pr up to date with base branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants