Skip to content

Commit

Permalink
Add readOnlyRootFilesystem to security context (#2771)
Browse files Browse the repository at this point in the history
* readOnlyRootFilesystem

* Add mount for /tmp

* Add /tmp mountpoint

* Update ingress-gateways-deployment.yaml

* Update terminating-gateways-deployment.yaml

* Update helm unit tests
  • Loading branch information
mr-miles authored and sarahalsmiller committed Apr 24, 2024
1 parent 94ee36e commit 4cb9786
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions charts/consul/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ as well as the global.name setting.
{{- if not .Values.global.enablePodSecurityPolicies -}}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
Expand Down
7 changes: 7 additions & 0 deletions charts/consul/templates/ingress-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ spec:
terminationGracePeriodSeconds: {{ default $defaults.terminationGracePeriodSeconds .terminationGracePeriodSeconds }}
serviceAccountName: {{ template "consul.fullname" $root }}-{{ .name }}
volumes:
- name: tmp
emptyDir:
medium: "Memory"
- name: consul-service
emptyDir:
medium: "Memory"
Expand Down Expand Up @@ -221,6 +224,8 @@ spec:
-log-level={{ default $root.Values.global.logLevel $root.Values.ingressGateways.logLevel }} \
-log-json={{ $root.Values.global.logJSON }}
volumeMounts:
- name: tmp
mountPath: /tmp
- name: consul-service
mountPath: /consul/service
{{- if $root.Values.global.tls.enabled }}
Expand All @@ -245,6 +250,8 @@ spec:
resources: {{ toYaml (default $defaults.resources .resources) | nindent 10 }}
{{- end }}
volumeMounts:
- name: tmp
mountPath: /tmp
- name: consul-service
mountPath: /consul/service
readOnly: true
Expand Down
7 changes: 7 additions & 0 deletions charts/consul/templates/terminating-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ spec:
terminationGracePeriodSeconds: 10
serviceAccountName: {{ template "consul.fullname" $root }}-{{ .name }}
volumes:
- name: tmp
emptyDir:
medium: "Memory"
- name: consul-service
emptyDir:
medium: "Memory"
Expand Down Expand Up @@ -206,6 +209,8 @@ spec:
-log-level={{ default $root.Values.global.logLevel $root.Values.terminatingGateways.logLevel }} \
-log-json={{ $root.Values.global.logJSON }}
volumeMounts:
- name: tmp
mountPath: /tmp
- name: consul-service
mountPath: /consul/service
{{- if $root.Values.global.tls.enabled }}
Expand All @@ -227,6 +232,8 @@ spec:
image: {{ $root.Values.global.imageConsulDataplane | quote }}
{{- include "consul.restrictedSecurityContext" $ | nindent 10 }}
volumeMounts:
- name: tmp
mountPath: /tmp
- name: consul-service
mountPath: /consul/service
readOnly: true
Expand Down
2 changes: 2 additions & 0 deletions charts/consul/test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ load _helpers
"drop": ["ALL"],
"add": ["NET_BIND_SERVICE"]
},
"readOnlyRootFilesystem": true,
"runAsNonRoot": true,
"seccompProfile": {
"type": "RuntimeDefault"
Expand Down Expand Up @@ -1417,6 +1418,7 @@ load _helpers
"drop": ["ALL"],
"add": ["NET_BIND_SERVICE"]
},
"readOnlyRootFilesystem": true,
"runAsNonRoot": true,
"seccompProfile": {
"type": "RuntimeDefault"
Expand Down

0 comments on commit 4cb9786

Please sign in to comment.