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

feat: add spec.template.spec.securityContext #1109

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ChristianBieri1995
Copy link

📑 Description

Adding spec.template.spec.securityContext in order to solve issues when working with Policy Management Tools such as Open Policy Agent and Gatekeeper (as in my case psp-pods-allowed-user-ranges). User and group were taken from https://github.com/k8sgpt-ai/k8sgpt/blob/main/container/Dockerfile#L37. One could also think about adding runAsNonRoot: true and fsGroup: 65532.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

ℹ Additional Information

Even though being more dynamic, other prominent project such as Grafana handle the securityContext in a similar way, see https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml#L142-L146 & https://github.com/grafana/grafana/blob/main/Dockerfile#L106 & https://github.com/grafana/helm-charts/blob/main/charts/grafana/templates/_pod.tpl#L9-L12

Signed-off-by: ChristianBieri1995 <122007149+ChristianBieri1995@users.noreply.github.com>
@ChristianBieri1995 ChristianBieri1995 requested review from a team as code owners May 10, 2024 13:59
@@ -21,6 +21,9 @@ spec:
app.kubernetes.io/name: {{ include "k8sgpt.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
securityContext:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to allow users to customize the securityContext option instead of hardcoding it like this.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, initially thought about this one as well. Shall I change it?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. make it controllerable by values

Copy link
Author

Choose a reason for hiding this comment

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

Done. Did it this way as it is max. flexible (if for example fsGroup should be added in the future, only changing values.yaml is enough). Hope that's fine.

Copy link
Member

@AlexsJones AlexsJones left a comment

Choose a reason for hiding this comment

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

How about making this configurable in the values.yaml?

Signed-off-by: ChristianBieri1995 <122007149+ChristianBieri1995@users.noreply.github.com>
Signed-off-by: ChristianBieri1995 <122007149+ChristianBieri1995@users.noreply.github.com>
@ChristianBieri1995
Copy link
Author

How about making this configurable in the values.yaml?

Done, see above.

@ChristianBieri1995
Copy link
Author

How about making this configurable in the values.yaml?

Done, see above.

Any news on that? Ready to merge?

@@ -14,7 +14,9 @@ deployment:
requests:
cpu: "0.2"
memory: "156Mi"

securityContext:
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems better not to have a default value for securityContext.

Copy link
Author

Choose a reason for hiding this comment

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

I have changed to values.yaml file accordingly. No, there is a possibility to set the securityContext but it's not mandatory. Any thoughts on that?

Signed-off-by: ChristianBieri1995 <122007149+ChristianBieri1995@users.noreply.github.com>
@AlexsJones
Copy link
Member

@k8sgpt-ai/k8sgpt-maintainers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Proposed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants