Skip to content

Commit

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

---------

Co-authored-by: mr-miles <miles.waller@gmail.com>
Co-authored-by: Paul Glass <pglass@hashicorp.com>
  • Loading branch information
3 people authored Aug 23, 2023
1 parent 55cb040 commit b75d803
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2789.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
helm: Add readOnlyRootFilesystem to the default restricted security context when runnning `consul-k8s` in a restricted namespaces.
```
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 @@ -154,6 +154,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 @@ -215,6 +218,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 @@ -239,6 +244,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
5 changes: 5 additions & 0 deletions charts/consul/templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ spec:
{{- toYaml .Values.server.securityContext | nindent 8 }}
{{- end }}
volumes:
- name: tmp
emptyDir: {}
- name: config
configMap:
name: {{ template "consul.fullname" . }}-server-config
Expand Down Expand Up @@ -450,6 +452,9 @@ spec:
mountPath: /trusted-cas
readOnly: false
{{- end }}
- name: tmp
mountPath: /tmp
readOnly: false
ports:
{{- if (or (not .Values.global.tls.enabled) (not .Values.global.tls.httpsOnly)) }}
- name: http
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 @@ -123,6 +123,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 @@ -200,6 +203,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 @@ -221,6 +226,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 @@ -858,6 +858,7 @@ load _helpers
"capabilities": {
"drop": ["ALL"]
},
"readOnlyRootFilesystem": true,
"runAsNonRoot": true,
"seccompProfile": {
"type": "RuntimeDefault"
Expand Down Expand Up @@ -889,6 +890,7 @@ load _helpers
"capabilities": {
"drop": ["ALL"]
},
"readOnlyRootFilesystem": true,
"runAsNonRoot": true,
"seccompProfile": {
"type": "RuntimeDefault"
Expand Down

0 comments on commit b75d803

Please sign in to comment.