Tightening Pod/Container Security for All Workloada#100
Open
alix-graylog wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens the default Pod/Container security contexts for Graylog, DataNode, and GeoIP update jobs, and makes those security settings configurable via values.yaml so operators can adjust or opt out as needed.
Changes:
- Added values-driven
podSecurityContext,initContainerSecurityContext, andcontainerSecurityContextdefaults for Graylog and DataNode. - Updated StatefulSet templates to render the new values-driven security contexts, and added a DataNode
data-chowninit container. - Updated GeoIP CronJob/Job rendering to accept Pod/Container security contexts via the shared helper.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| charts/graylog/values.yaml | Introduces configurable default security contexts (and initContainer image config) for Graylog and DataNode. |
| charts/graylog/templates/workload/statefulsets/graylog.yaml | Renders new values-driven pod/container/init-container security contexts for Graylog workload and plugin-copy init containers. |
| charts/graylog/templates/workload/statefulsets/datanode.yaml | Adds values-driven pod/container/init-container security contexts plus a data-chown init container for PVC preparation. |
| charts/graylog/templates/workload/cronjobs/geoip.yaml | Passes security contexts into the GeoIP JobSpec helper. |
| charts/graylog/templates/_helpers.tpl | Extends GeoIP JobSpec helper to optionally render pod/container security contexts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+98
to
+101
| {{- with merge (dict "readOnlyRootFilesystem" true) $.Values.graylog.initContainerSecurityContext }} | ||
| securityContext: | ||
| {{- toYaml . | nindent 12 }} | ||
| {{- end }} |
Comment on lines
+67
to
+71
| mkdir -p \ | ||
| {{ $dataMountPath }}/opensearch/config \ | ||
| {{ $dataMountPath }}/opensearch/data \ | ||
| {{ $dataMountPath }}/opensearch/logs | ||
| chown -R 999:999 {{ $dataMountPath }} |
Comment on lines
+292
to
+295
| initContainerImage: | ||
| repository: "busybox" | ||
| tag: "latest" | ||
| imagePullPolicy: IfNotPresent |
Comment on lines
+184
to
+187
| fsGroup: 1100 | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| initContainerSecurityContext: |
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.
Summary
Locking down default pod and container security contexts, as far as the application currently allows, and exposing the configuration to the
values.yamlDetails
What this does
Moves security contexts out of hardcoded template values and into
values.yamlso they're configurable, and tightens the defaults for both Graylog and Datanode.podSecurityContextandcontainerSecurityContextare now values-driven for both workloadsinitContainerSecurityContext— they don't needNET_BIND_SERVICEsince they never start the JVMcopy-plugin-*init containers getreadOnlyRootFilesystem: true(they only write to an emptyDir)data-chowninit container (busybox) that handles ownership setup on the PVC before the main container starts. The image is configurable viadatanode.initContainerImagefor private registry supportseccompProfile: RuntimeDefaultapplied across all containersallowPrivilegeEscalation: falseandcapabilities: drop: ALLon everythingWhy some things couldn't be locked down further
Graylog —
NET_BIND_SERVICEhas to stay. The JDK binary in the image hascap_net_bind_service=epset as a file capability. Withno_new_privs=1(whichallowPrivilegeEscalation: falsesets), executing a binary that would gain capabilities not already in the process's permitted set fails withEPERM. Pre-addingNET_BIND_SERVICEto the container's permitted set means the file capability doesn't grant anything new, so the exec works.Datanode — has to start as root. This is common with Opensearch in Kubernetes. The entrypoint does
chown -R graylog:graylog /var/lib/graylog-datanodethenexec setpriv --reuid=graylog --regid=graylog --init-groupsunconditionally. That requiresCHOWN,DAC_OVERRIDE,SETUID, andSETGID. We tried moving the chown to the init container to strip those from the main container, but the entrypoint still runs its ownchown -Ron startup — and root withoutCAP_CHOWNcan't chown files owned by uid 999. We also tried settingrunAsUser: 999directly, but the container runtime clears the effective capability set when it switches from root to non-root, soSETGIDends up in the bounding set but not effective —setpriv --init-groupsstill fails. Aftersetprivruns the process has uid 999 and no capabilities, so the running application is fine, just the startup window needs them.readOnlyRootFilesystem— not set on the main containers. Both the Graylog JVM and the OpenSearch-based datanode write to the container filesystem at runtime and would need a full audit + emptyDir mounts to enable this safely.Opting out
If the security contexts cause issues in your environment, each field is fully overridable. To disable them entirely:
Linked issues
PR Checklist
Please check the items that apply to your change.
Testing Checklist
Static Validation
helm lint ./charts/grayloghelm template graylog ./charts/graylog --validateInstallation
helm install graylog ./charts/graylogkubectl rollout status statefulset/grayloghelm test graylogFunctional (if applicable)
Upgrade (if applicable)
Specific to this PR
Notes for reviewers