Skip to content

Commit 01875d5

Browse files
[prometheus-elasticsearch-exporter] Refactor securityContext configuration (#2694)
* Refactor securityContext configuration Signed-off-by: Leonhard Mayr <[email protected]> * Remove unnecessary comments Signed-off-by: Leonhard Mayr <[email protected]> * Refactor securityContext CI values Signed-off-by: Leonhard Mayr <[email protected]> * Add notes for breaking changes to README Signed-off-by: Leonhard Mayr <[email protected]> * Fix linter errors Signed-off-by: Leonhard Mayr <[email protected]> * Reword sentence to avoid linting error Signed-off-by: Leonhard Mayr <[email protected]> * Align README style Signed-off-by: Leonhard Mayr <[email protected]> Signed-off-by: Leonhard Mayr <[email protected]>
1 parent 8b9b09c commit 01875d5

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed

charts/prometheus-elasticsearch-exporter/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
description: Elasticsearch stats exporter for Prometheus
33
name: prometheus-elasticsearch-exporter
4-
version: 4.15.1
4+
version: 5.0.0
55
kubeVersion: ">=1.10.0-0"
66
appVersion: 1.5.0
77
home: https://github.com/prometheus-community/elasticsearch_exporter

charts/prometheus-elasticsearch-exporter/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ cluster using the [Helm](https://helm.sh) package manager.
1111

1212
- Kubernetes 1.10+
1313

14-
## Get Repo Info
14+
## Get Helm Repository Info
1515

1616
```console
1717
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
1818
helm repo update
1919
```
2020

21-
_See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation._
21+
_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._
2222

23-
## Install Chart
23+
## Install Helm Chart
2424

2525
```console
2626
# Helm 3
@@ -36,7 +36,7 @@ _See [configuration](#configuration) below._
3636

3737
_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._
3838

39-
## Uninstall Chart
39+
## Uninstall Helm Chart
4040

4141
```console
4242
# Helm 3
@@ -50,7 +50,7 @@ This removes all the Kubernetes components associated with the chart and deletes
5050

5151
_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._
5252

53-
## Upgrading Chart
53+
## Upgrading Helm Chart
5454

5555
```console
5656
# Helm 3 or 2
@@ -59,6 +59,18 @@ $ helm upgrade [RELEASE_NAME] [CHART] --install
5959

6060
_See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._
6161

62+
### To 5.0.0
63+
64+
`securityContext` has been renamed to `podSecurityContext` and `securityContext.enabled` has no effect anymore. To mirror the behaviour of `securityContext.enabled=false` of 4.x unset `podSecurityContext`.
65+
66+
```console
67+
helm install --set podSecurityContext=null my-exporter stable/elasticsearch-exporter
68+
```
69+
70+
In 5.0.0 `securityContext` refers to the container's securityContext instead which was not configurable in earlier versions. The naming is aligned with the base charts created by Helm.
71+
72+
Default values for `podSecurityContext` and `securityContext` have been updated to be compatible with the Pod Security Standard level "restricted". Most notably `seccompProfile.type` is set to `RuntimeDefault`.
73+
6274
### To 4.0.0
6375

6476
While migrating the chart from `stable/elasticsearch-exporter` it was renamed to `prometheus-elasticsearch-exporter`.
@@ -80,7 +92,7 @@ You now need to escape the rules (see `values.yaml`) for examples.
8092

8193
### To 2.0.0
8294

83-
Some Kubernetes apis used from 1.x have been deprecated. You need to update your cluster to Kubernetes 1.10+ to support new definitions used in 2.x.
95+
Some Kubernetes APIs used from 1.x have been deprecated. You need to update your cluster to Kubernetes 1.10+ to support new definitions used in 2.x.
8496

8597
## Configuration
8698

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
# Set default security context for kubernetes
2+
# Unset pod level securityContext
33

4-
securityContext:
5-
disable: true
4+
podSecurityContext: null

charts/prometheus-elasticsearch-exporter/templates/deployment.yaml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ spec:
4848
{{- end }}
4949
{{- include "elasticsearch-exporter.image.pullSecret.name" (dict "images" (list .Values.image) "context" $) | nindent 6 }}
5050
restartPolicy: {{ .Values.restartPolicy }}
51-
{{- if .Values.securityContext.enabled }}
51+
{{- with .Values.podSecurityContext }}
5252
securityContext:
53-
runAsNonRoot: true
54-
runAsUser: {{ .Values.securityContext.runAsUser }}
53+
{{- toYaml . | nindent 8 }}
5554
{{- end }}
5655
{{- with .Values.dnsConfig }}
5756
dnsConfig:
@@ -125,24 +124,10 @@ spec:
125124
{{- end }}
126125
"--web.listen-address=:{{ .Values.service.httpPort }}",
127126
"--web.telemetry-path={{ .Values.web.path }}"]
127+
{{- with .Values.securityContext }}
128128
securityContext:
129-
capabilities:
130-
drop:
131-
- SETPCAP
132-
- MKNOD
133-
- AUDIT_WRITE
134-
- CHOWN
135-
- NET_RAW
136-
- DAC_OVERRIDE
137-
- FOWNER
138-
- FSETID
139-
- KILL
140-
- SETGID
141-
- SETUID
142-
- NET_BIND_SERVICE
143-
- SYS_CHROOT
144-
- SETFCAP
145-
readOnlyRootFilesystem: true
129+
{{- toYaml . | nindent 12 }}
130+
{{- end }}
146131
{{- with .Values.resources }}
147132
resources:
148133
{{- toYaml . | nindent 12 }}

charts/prometheus-elasticsearch-exporter/values.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ image:
1818
pullPolicy: IfNotPresent
1919
pullSecret: ""
2020

21-
## Set enabled to false if you don't want securityContext
22-
## in your Deployment.
23-
## The below values are the default for kubernetes.
24-
## Openshift won't deploy with runAsUser: 1000 without additional permissions.
25-
securityContext:
26-
enabled: true # Should be set to false when running on OpenShift
21+
podSecurityContext:
22+
runAsNonRoot: true
2723
runAsUser: 1000
24+
seccompProfile:
25+
type: "RuntimeDefault"
26+
27+
securityContext:
28+
allowPrivilegeEscalation: false
29+
capabilities:
30+
drop:
31+
- ALL
32+
readOnlyRootFilesystem: true
2833

2934
# Custom DNS configuration to be added to prometheus-elasticsearch-exporter pods
3035
dnsConfig: {}

0 commit comments

Comments
 (0)