Skip to content

Commit 793c5f3

Browse files
authored
fix(helm): use a read-only gateway root (#6011)
Signed-off-by: Simon Scatton <sscatton@nvidia.com>
1 parent a138874 commit 793c5f3

6 files changed

Lines changed: 169 additions & 0 deletions

File tree

‎deploy/helm/openshell/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ for peer identity policies, multi-node registrations, and authorization.
728728
| sandboxServiceAccount.name | string | `""` | Existing service account name for sandbox pods when sandboxServiceAccount.create is false. |
729729
| securityContext.allowPrivilegeEscalation | bool | `false` | Whether the gateway container can gain additional privileges. |
730730
| securityContext.capabilities.drop | list | `["ALL"]` | Linux capabilities dropped from the gateway container. |
731+
| securityContext.readOnlyRootFilesystem | bool | `true` | Mount the gateway container root filesystem read-only. Mount additional writable paths with server.extraVolumes and server.extraVolumeMounts. |
731732
| securityContext.runAsNonRoot | bool | `true` | Require the gateway container to run as a non-root user. |
732733
| securityContext.runAsUser | int | `1000` | UID assigned to the gateway container. |
733734
| securityContext.seccompProfile.type | string | `"RuntimeDefault"` | Seccomp profile applied to the gateway container. |

‎deploy/helm/openshell/templates/_gateway-workload.tpl‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Gateway pod template shared by the StatefulSet and Deployment workload shapes.
1919
{{- $legacyVaultResources := get $legacyCredentialDrivers "vault" | default dict -}}
2020
{{- $vaultCaConfigMapName := get $vaultResources "caConfigMapName" | default (get $legacyVaultResources "caConfigMapName") -}}
2121
{{- $supervisorNetwork := .Values.supervisor.network | default dict -}}
22+
{{- $hasTmpMount := false -}}
23+
{{- range .Values.server.extraVolumeMounts -}}
24+
{{- if eq .mountPath "/tmp" -}}{{- $hasTmpMount = true -}}{{- end -}}
25+
{{- end -}}
2226
metadata:
2327
annotations:
2428
# Roll the gateway workload when the rendered gateway TOML changes - the
@@ -225,6 +229,10 @@ spec:
225229
{{- end }}
226230
- name: gateway-state
227231
mountPath: /var/lib/openshell-state
232+
{{- if not $hasTmpMount }}
233+
- name: gateway-tmp
234+
mountPath: /tmp
235+
{{- end }}
228236
ports:
229237
- name: grpc
230238
containerPort: {{ .Values.service.port }}
@@ -356,6 +364,10 @@ spec:
356364
{{- end }}
357365
- name: gateway-state
358366
emptyDir: {}
367+
{{- if not $hasTmpMount }}
368+
- name: gateway-tmp
369+
emptyDir: {}
370+
{{- end }}
359371
{{- with .Values.priorityClassName }}
360372
priorityClassName: {{ . }}
361373
{{- end }}

‎deploy/helm/openshell/tests/gateway_pod_security_context_test.yaml‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ suite: gateway pod securityContext
55
templates:
66
- templates/gateway-config.yaml
77
- templates/statefulset.yaml
8+
- templates/deployment.yaml
89
release:
910
name: openshell
1011
namespace: my-namespace
@@ -43,6 +44,143 @@ tests:
4344
path: spec.template.spec.containers[0].securityContext.capabilities.drop
4445
value:
4546
- ALL
47+
- equal:
48+
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
49+
value: true
50+
- contains:
51+
path: spec.template.spec.containers[0].volumeMounts
52+
content:
53+
name: gateway-tmp
54+
mountPath: /tmp
55+
- contains:
56+
path: spec.template.spec.volumes
57+
content:
58+
name: gateway-tmp
59+
emptyDir: {}
60+
- contains:
61+
path: spec.template.spec.containers[0].volumeMounts
62+
content:
63+
name: openshell-data
64+
mountPath: /var/openshell
65+
- contains:
66+
path: spec.template.spec.containers[0].volumeMounts
67+
content:
68+
name: gateway-state
69+
mountPath: /var/lib/openshell-state
70+
- contains:
71+
path: spec.template.spec.volumes
72+
content:
73+
name: gateway-state
74+
emptyDir: {}
75+
76+
- it: keeps a Deployment root read-only with writable temporary and state volumes
77+
template: templates/deployment.yaml
78+
set:
79+
workload.kind: deployment
80+
server.externalDbSecret: my-pg-secret
81+
asserts:
82+
- equal:
83+
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
84+
value: true
85+
- contains:
86+
path: spec.template.spec.containers[0].volumeMounts
87+
content:
88+
name: gateway-tmp
89+
mountPath: /tmp
90+
- contains:
91+
path: spec.template.spec.volumes
92+
content:
93+
name: gateway-tmp
94+
emptyDir: {}
95+
- contains:
96+
path: spec.template.spec.containers[0].volumeMounts
97+
content:
98+
name: gateway-state
99+
mountPath: /var/lib/openshell-state
100+
- contains:
101+
path: spec.template.spec.volumes
102+
content:
103+
name: gateway-state
104+
emptyDir: {}
105+
106+
- it: allows an operator to opt out of a read-only root filesystem
107+
template: templates/statefulset.yaml
108+
set:
109+
securityContext.readOnlyRootFilesystem: false
110+
asserts:
111+
- equal:
112+
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
113+
value: false
114+
115+
- it: preserves an operator-supplied temporary volume without duplicate mounts
116+
template: templates/statefulset.yaml
117+
set:
118+
server.extraVolumes:
119+
- name: custom-tmp
120+
emptyDir:
121+
medium: Memory
122+
server.extraVolumeMounts:
123+
- name: custom-tmp
124+
mountPath: /tmp
125+
asserts:
126+
- equal:
127+
path: spec.template.spec.containers[0].volumeMounts[?(@.mountPath == "/tmp")].name
128+
value: custom-tmp
129+
- contains:
130+
path: spec.template.spec.volumes
131+
content:
132+
name: custom-tmp
133+
emptyDir:
134+
medium: Memory
135+
- notContains:
136+
path: spec.template.spec.volumes
137+
content:
138+
name: gateway-tmp
139+
emptyDir: {}
140+
141+
- it: preserves Deployment temporary volume overrides
142+
template: templates/deployment.yaml
143+
set:
144+
workload.kind: deployment
145+
server.externalDbSecret: my-pg-secret
146+
securityContext.readOnlyRootFilesystem: false
147+
server.extraVolumes:
148+
- name: custom-tmp
149+
emptyDir: {}
150+
server.extraVolumeMounts:
151+
- name: custom-tmp
152+
mountPath: /tmp
153+
asserts:
154+
- equal:
155+
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
156+
value: false
157+
- equal:
158+
path: spec.template.spec.containers[0].volumeMounts[?(@.mountPath == "/tmp")].name
159+
value: custom-tmp
160+
- notContains:
161+
path: spec.template.spec.volumes
162+
content:
163+
name: gateway-tmp
164+
emptyDir: {}
165+
166+
- it: retains writable temporary storage with OpenShift-assigned identities
167+
template: templates/statefulset.yaml
168+
set:
169+
securityContext.runAsUser: null
170+
podSecurityContext.fsGroup: null
171+
asserts:
172+
- notExists:
173+
path: spec.template.spec.containers[0].securityContext.runAsUser
174+
- notExists:
175+
path: spec.template.spec.securityContext.fsGroup
176+
- equal:
177+
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
178+
value: true
179+
- contains:
180+
path: spec.template.spec.volumes
181+
content:
182+
name: gateway-tmp
183+
emptyDir: {}
46184

47185
- it: omits the pod securityContext block when podSecurityContext is null
48186
template: templates/statefulset.yaml

‎deploy/helm/openshell/values.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ podSecurityContext:
275275
fsGroup: 1000
276276

277277
securityContext:
278+
# -- Mount the gateway container root filesystem read-only. Mount additional
279+
# writable paths with server.extraVolumes and server.extraVolumeMounts.
280+
readOnlyRootFilesystem: true
278281
# -- Require the gateway container to run as a non-root user.
279282
runAsNonRoot: true
280283
# -- UID assigned to the gateway container.

‎docs/kubernetes/setup.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,12 @@ carrying the same rules as the chart's `openshell-sandbox` Role.
561561

562562
The gateway workload and the PKI bootstrap hooks satisfy the [Restricted Pod Security Standard](https://kubernetes.io/docs/concepts/security/pod-security-standards/), so the release installs into a namespace labeled `pod-security.kubernetes.io/enforce=restricted`.
563563

564+
The gateway container uses a read-only root filesystem by default. The chart
565+
provides writable volumes for `/tmp`, gateway state, and the StatefulSet's database.
566+
For custom file output paths, add writable mounts with `server.extraVolumes` and
567+
`server.extraVolumeMounts`. An extra mount at `/tmp` replaces the chart's temporary
568+
volume. Set `securityContext.readOnlyRootFilesystem=false` to opt out.
569+
564570
## Probes
565571

566572
The gateway exposes `/healthz` for process liveness and `/readyz` for dependency-aware readiness on the health port. The Helm chart wires both into Kubernetes probes:

‎skills/debug-openshell-cluster/SKILL.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,15 @@ kubectl -n openshell logs <gateway-pod> -c openshell-gateway --tail=200
585585
`server.telemetryEnabled` renders `OPENSHELL_TELEMETRY_ENABLED` on the gateway
586586
pod, and the gateway propagates the effective value to sandbox supervisors.
587587

588+
The Helm gateway container defaults to a read-only root filesystem. For
589+
`Read-only file system` errors, check that writes target the writable `/tmp`,
590+
`/var/lib/openshell-state`, or StatefulSet `/var/openshell` mounts. The chart adds
591+
a `gateway-tmp` emptyDir at `/tmp` unless `server.extraVolumeMounts` already mounts
592+
that path; the default optional OCSF log uses `/tmp/gateway-ocsf.jsonl`. Custom
593+
output paths need writable mounts through `server.extraVolumes` and
594+
`server.extraVolumeMounts`. Inspect `securityContext.readOnlyRootFilesystem` if
595+
an operator explicitly opted out.
596+
588597
Gateway pod scheduling accepts top-level `nodeSelector`, `affinity`,
589598
`tolerations`, `priorityClassName`, and `topologySpreadConstraints` values for
590599
both StatefulSet and Deployment workloads. The last two default to unset.

0 commit comments

Comments
 (0)