feat(kubernetes): add support for podSecurityContext and containerSecurityContext configurations - #7033
Open
florianzwagemaker wants to merge 6 commits into
Conversation
…nd container levels
…l relevant templates
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the kubernetes/loculus Helm chart to support configurable pod-level and container-level Kubernetes securityContext settings, enabling deployments in clusters with stricter Pod Security / compliance requirements.
Changes:
- Adds new top-level Helm values + JSON schema definitions for
podSecurityContextandcontainerSecurityContext, supportingdefaultplus per-component overrides. - Introduces
_security-context.tplhelpers and wires them into the chart’s Deployments/CronJobs so security contexts can be rendered consistently. - Updates
loculus.configProcessorcall sites to pass root.Values, enabling the config-processor initContainer to also receive a securityContext.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| kubernetes/loculus/values.yaml | Adds new top-level values placeholders for pod/container security contexts. |
| kubernetes/loculus/values.schema.json | Adds schema definitions + root properties for validating the new securityContext configuration blocks. |
| kubernetes/loculus/templates/_security-context.tpl | New helpers to render pod/container securityContext blocks based on default vs per-component override. |
| kubernetes/loculus/templates/taxonomy-deployment.yaml | Applies pod/container securityContext helpers to taxonomy deployment and initContainer. |
| kubernetes/loculus/templates/silo-deployment.yaml | Applies pod/container securityContext helpers; updates configProcessor include to pass .Values. |
| kubernetes/loculus/templates/minio-deployment.yaml | Applies pod/container securityContext helpers to minio deployment. |
| kubernetes/loculus/templates/loculus-website.yaml | Applies pod/container securityContext helpers; updates configProcessor include to pass .Values. |
| kubernetes/loculus/templates/loculus-preprocessing-deployment.yaml | Applies pod/container securityContext helpers to preprocessing deployment. |
| kubernetes/loculus/templates/loculus-database-standin.yaml | Applies pod/container securityContext helpers to database stand-in deployment. |
| kubernetes/loculus/templates/loculus-backend.yaml | Applies pod/container securityContext helpers; updates configProcessor include to pass .Values. |
| kubernetes/loculus/templates/lapis-deployment.yaml | Applies pod/container securityContext helpers; updates configProcessor include to pass .Values. |
| kubernetes/loculus/templates/keycloak-deployment.yaml | Applies pod/container securityContext helpers; updates configProcessor include to pass .Values. |
| kubernetes/loculus/templates/keycloak-database-standin.yaml | Applies pod/container securityContext helpers to keycloak DB stand-in deployment. |
| kubernetes/loculus/templates/ingest.yaml | Applies pod/container securityContext helpers to the ingest-trigger job. |
| kubernetes/loculus/templates/ena-submission-deployment.yaml | Applies pod/container securityContext helpers to ENA submission deployment + cronjob. |
| kubernetes/loculus/templates/docs-preview.yaml | Applies pod/container securityContext helpers to docs preview deployment. |
| kubernetes/loculus/templates/autoapprove-deployment.yaml | Applies pod/container securityContext helpers to autoapprove deployment. |
| kubernetes/loculus/templates/_ingest-pod-spec.tpl | Applies pod/container securityContext helpers to the shared ingest pod spec (init + main containers). |
| kubernetes/loculus/templates/_config-processor.tpl | Applies container securityContext helper to config-processor container template. |
Suppressed comments (1)
kubernetes/loculus/templates/_security-context.tpl:26
- Same issue as podSecurityContext: empty maps are treated as falsey, so a component key with
{}will fall back tocontainerSecurityContext.defaultinstead of overriding it. This makes it impossible to opt out of the default securityContext for a specific component.
{{- if and $values.containerSecurityContext (index $values.containerSecurityContext $componentName) }}
securityContext:
{{ toYaml (index $values.containerSecurityContext $componentName) | indent 2 }}
{{- else if and $values.containerSecurityContext $values.containerSecurityContext.default }}
securityContext:
{{ toYaml $values.containerSecurityContext.default | indent 2 }}
{{- end }}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolves #7014
This PR introduces security context configuration support to the helm chart, allowing pod-level and container-level security contexts to be customized.
This will allow Loculus to be deployed in k8s environments where specific security policies are enforced (such as running as a specific user, or user/group constraints).
Here we add two root-level properties in the helm chart (values.yaml and schema):
podSecurityContext: which applies specific security contexts on a pod-level (applies to all containers in a pod)containerSecurityContext: applies specific security contexts on a container level (per container)Both properties support a
defaultentry that applies to all workloads, as well as per-component overrides (such as backend, silo, or lapis) A component specific entry will take precedence over the default entry.Note
Regarding overrides: there is no deep merge between
defaultand a component-specific entry. If a component has or needs its own entry, that entry is used in full and thedefaultblock will be ignored for that component. In other words, if it's required to change a field for one component, the complete security context for that component must be specified.Example 1: Defaults applied to all components
This will result in all workloads to render in the helm chart with these security contexts (for example, the silo pod):
Example 2: Defaults applied, with one component needing different settings
For this example we state that the
silo-importercontainer needs to write to the filesystem for logging purposes, as a result it cannot use the defaultreadOnlyRootFilesystem: true.Because there's no deep merge, we will have to specify the full security context for that component like below:
This will result in all containers getting the
defaultcontainer security context, except forsilo-importerwhich will get its own block with a writable root filesystem.A new
_security-context.tpltemplate withloculus.podSecurityContextandloculus.containerSecurityContexthelpers has been added. And all relevant deployment templates are updated to include the helpers & blocks.The configuration blocks added to
values.yamlare empty by default to retain backwards compatibility.Currently, no security contexts will be applied unless explicitly configured.
🚀 Preview: Add
previewlabel to enable