Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReadOnlyRootFilesystem to Security Context #2909

Merged
merged 7 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading