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

Add missing fields for Security context and secrets #102

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

erikfuego
Copy link
Contributor

@erikfuego erikfuego commented Mar 28, 2023

Due to PodSecurity policies in place after CIS hardening my cluster, I had to add the following to the pod or container security context:

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

With the current securityContext implementation, only securityContext.fsGroup and securityContext.runAsUser were included. This change adds the ability to include everything in the securityContext provided. It also removes the enabled parameter which is unnecessary to me because we can just check if anything in the securityContext exists.

I added a containerSecurityContext to help differentiate between adding these fields for a container or the service itself. If securityContext is added for the service, PodSecurity fails because it specifically asks to be added to the container level.

This also adds a missing field for secrets called secretRef for s3.

@erikfuego erikfuego changed the title Add Security context missing fields Add missing fields for Security context and secrets Mar 28, 2023
@erikfuego erikfuego force-pushed the security-context-missing-fields branch from 854db4a to 9e92aab Compare March 28, 2023 15:34
@erikfuego erikfuego marked this pull request as draft March 28, 2023 15:38
@erikfuego erikfuego force-pushed the security-context-missing-fields branch from 780b3e0 to ed363d7 Compare March 28, 2023 16:35
@erikfuego erikfuego marked this pull request as ready for review March 28, 2023 16:36
@tchinmai7
Copy link

+1 to this - would love to have the ability to pass securityContexts

@joshsizer
Copy link
Collaborator

joshsizer commented Jul 11, 2023

+1 this is a crucial feature

I need this change so that I can set runAsNonRoot: true so that my docker registry deployment passes my Kyverno runAsNonRoot policies

@Mercbot7
Copy link

This is a needed feature for us as well!

@erikfuego
Copy link
Contributor Author

sorry everyone! i was on paternal leave. hoping this gets merged soon

Copy link
Collaborator

@joshsizer joshsizer left a comment

Choose a reason for hiding this comment

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

LGTM

@joshsizer
Copy link
Collaborator

@canterberry Could we get an Approving review?

This MR looks good to me, and it's backwards compatible. Also, happy to become a maintainer for this repo if you need some help going through these issues.

Copy link
Collaborator

@joshsizer joshsizer left a comment

Choose a reason for hiding this comment

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

@erikfuego I realize this is not backwards compatible as of now, if people have securityContext disabled, this update will now automatically enable it which may be undesired and breaking (since there are default fields for securityContext set).

In the case that someone already has it enabled, you receive the following warning when installing:

W0201 10:03:19.051240    7376 warnings.go:70] unknown field "spec.template.spec.securityContext.enabled"

I've suggested some ways to work around this by keeping the enabled field, and omitting it when populating the securityContext sections.

I was using the Bitnami MongoDB chart as a basis

values.yaml Show resolved Hide resolved
templates/deployment.yaml Outdated Show resolved Hide resolved
templates/deployment.yaml Outdated Show resolved Hide resolved
templates/cronjob.yaml Outdated Show resolved Hide resolved
templates/cronjob.yaml Outdated Show resolved Hide resolved
templates/cronjob.yaml Outdated Show resolved Hide resolved
templates/cronjob.yaml Outdated Show resolved Hide resolved
templates/deployment.yaml Outdated Show resolved Hide resolved
templates/deployment.yaml Outdated Show resolved Hide resolved
values.yaml Outdated Show resolved Hide resolved
@erikfuego
Copy link
Contributor Author

@erikfuego I realize this is not backwards compatible as of now, if people have securityContext disabled, this update will now automatically enable it which may be undesired and breaking (since there are default fields for securityContext set).

In the case that someone already has it enabled, you receive the following warning when installing:

W0201 10:03:19.051240    7376 warnings.go:70] unknown field "spec.template.spec.securityContext.enabled"

I've suggested some ways to work around this by keeping the enabled field, and omitting it when populating the securityContext sections.

I was using the Bitnami MongoDB chart as a basis

Yeah thats a good point. Can you confirm that all the changes you suggested are in? The CI tests are failing. Im also going to test this locally with the values I set for the chart

@erikfuego
Copy link
Contributor Author

erikfuego commented Feb 1, 2024

@joshsizer I reverted the changes you suggested for containerSecurityContext because thats a new field I added to make the securityContext work for containers. And accepted your changes to keep the enabled field for securityContext and omit it when populating securityContext

@joshsizer
Copy link
Collaborator

@joshsizer I reverted the changes you suggested for containerSecurityContext because thats a new field I added to make the securityContext work for containers. And accepted your changes to keep the enabled field for securityContext and omit it when populating securityContext

Awesome! I wonder, would it be good to keep the changes for containerSecurityContext, so that the schemas for each section are similar? I see either option as viable, but lean towards keeping them similar. I think lint was failing because we would have to add in to values.yaml

containerSecurityContext:
  enabled: false

@erikfuego
Copy link
Contributor Author

@joshsizer I reverted the changes you suggested for containerSecurityContext because thats a new field I added to make the securityContext work for containers. And accepted your changes to keep the enabled field for securityContext and omit it when populating securityContext

Awesome! I wonder, would it be good to keep the changes for containerSecurityContext, so that the schemas for each section are similar? I see either option as viable, but lean towards keeping them similar. I think lint was failing because we would have to add in to values.yaml

containerSecurityContext:
  enabled: false

I prefer the pattern where enabled is not used because otherwise its an extra value to worry about. But if you want to use enabled, feel free to suggest the changes and I can apply them

@erikfuego
Copy link
Contributor Author

sorry about that weird merge, I merged this branch into a colleagues forked repo to test these changes, and for some reason his changes were merged into my branch.

Copy link
Collaborator

@joshsizer joshsizer left a comment

Choose a reason for hiding this comment

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

The last change we need is to add to values.yaml:

containerSecurityContext:
  enabled: false

templates/cronjob.yaml Outdated Show resolved Hide resolved
templates/cronjob.yaml Outdated Show resolved Hide resolved
templates/deployment.yaml Outdated Show resolved Hide resolved
templates/deployment.yaml Outdated Show resolved Hide resolved
@erikfuego
Copy link
Contributor Author

The last change we need is to add to values.yaml:

containerSecurityContext:
  enabled: false

that broke the CI

@joshsizer
Copy link
Collaborator

The last change we need is to add to values.yaml:

containerSecurityContext:
  enabled: false

that broke the CI

Could you add into values.yaml

containerSecurityContext:
  enabled: false

That will fix the CI.

I'm not sure I can push to this branch

Copy link
Collaborator

@joshsizer joshsizer left a comment

Choose a reason for hiding this comment

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

LGTM

@canterberry Can you review this as well?

@erikfuego
Copy link
Contributor Author

LGTM

@canterberry Can you review this as well?

wanted to bumb this. Thanks!

@joshsizer
Copy link
Collaborator

@erikfuego Would you be able to recommit with signed commits? I am now a maintainer, and can approve and merge, but this repository is setup to only allow signed commits

@erikfuego erikfuego force-pushed the security-context-missing-fields branch 3 times, most recently from 76f5c91 to 436cb9d Compare March 4, 2024 17:29
@erikfuego erikfuego force-pushed the security-context-missing-fields branch from 436cb9d to ed0a778 Compare March 4, 2024 17:36
@erikfuego erikfuego requested a review from joshsizer March 4, 2024 17:37
@vyas-n
Copy link
Collaborator

vyas-n commented Mar 5, 2024

@joshsizer

Not sure what the protocol should be moving forward, but I'm also a maintainer and I can now merge if you'd like.

@joshsizer
Copy link
Collaborator

@joshsizer

Not sure what the protocol should be moving forward, but I'm also a maintainer and I can now merge if you'd like.

Let's do it!

@vyas-n vyas-n merged commit 419a289 into twuni:main Mar 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants