Skip to content

Commit

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

* readOnlyRootFilesystem

* Add mount for /tmp

* Add /tmp mountpoint

* Update ingress-gateways-deployment.yaml

* Update terminating-gateways-deployment.yaml

* Update helm unit tests

* Create 2781.txt

* rename changelog file

* rename changelog file

* Mount /tmp to volume for snapshots

* rename changelog

* changelog

---------

Co-authored-by: mr-miles <miles.waller@gmail.com>
Co-authored-by: Paul Glass <pglass@hashicorp.com>
Co-authored-by: Sarah Alsmiller <sarah.alsmiller@hashicorp.com>
  • Loading branch information
4 people authored May 8, 2024
1 parent 2cebe95 commit 58f715a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2909.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 @@ -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
5 changes: 5 additions & 0 deletions charts/consul/templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,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 @@ -562,6 +564,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 @@ -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 58f715a

Please sign in to comment.