Skip to content

Commit 0dda412

Browse files
meili-bors[bot]legal90alallema
authored
Merge #182
182: Run meilisearch as non-root user with readOnlyRootFilesystem r=alallema a=legal90 # Pull Request ## Related issue - meilisearch/meilisearch#2051 (it's just a relevant issue raised on the meilisearch image level) This PR was created in the continuation to our discussion here: #176 (comment) ## What does this PR do? That PR changes the default behaviour of the chart so it runs meilisearch under a non-root user, following the principal of least permissions and improve the security posture: - Enable `securityContext.readOnlyRootFilesystem: true` by default and mount required writable points: - `/tmp` as `emptyDir: {}` [1] - `/meili_data` as `emptyDir: {}` by default, or as a PVC if `persistence.enabled: true` - Default values `fsGroup: 1000` and `fsGroupChangePolicy: OnRootMismatch` allow to keep backward compatibility with existing installations. If the data volume already has files previously created and owned by root (e.q. `persistence.enabled: true`), then k8s will automatically change the group ownership of these files to 1000, so they will still be writable by the non-privileged user in this new chart version. That happens automatically - no user action is needed. [2] - **Small chance of backward incompatibility for some users:** those users who already have `/tmp` mount configured via `volumes` and `volumeMounts` values, might get a failure in upgrade to this new version, because this volume is now declared in the template by default. The fix is simple - just remove the definition of /tmp from your custom values. Due to that I'm bumping the minor version of the chart to 0.2.0. Please let me know if you think we should update it differently. ## Links [1] https://kubernetes.io/docs/concepts/storage/volumes/#emptydir [2] https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Mikhail Zholobov <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents 0ad1b81 + 5794610 commit 0dda412

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

charts/meilisearch/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
appVersion: "v1.2.0"
33
description: A Helm chart for the Meilisearch search engine
44
name: meilisearch
5-
version: 0.1.59
5+
version: 0.2.0
66
icon: https://res.cloudinary.com/meilisearch/image/upload/v1597822872/Logo/logo_img.svg
77
home: https://github.com/meilisearch/meilisearch-kubernetes/tree/main/charts/meilisearch
88
maintainers:

charts/meilisearch/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A Helm chart for the Meilisearch search engine
44

5-
![Version: 0.1.58](https://img.shields.io/badge/Version-0.1.58-informational?style=flat-square) ![AppVersion: v1.2.0](https://img.shields.io/badge/AppVersion-v1.2.0-informational?style=flat-square)
5+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![AppVersion: v1.2.0](https://img.shields.io/badge/AppVersion-v1.2.0-informational?style=flat-square)
66

77
Helm works as a package manager to run pre-configured Kubernetes resources.
88

@@ -88,13 +88,18 @@ You can also use `auth.existingMasterKeySecret` to use an existing secret that h
8888
| persistence.volume.name | string | `"data"` | |
8989
| podAnnotations | object | `{}` | |
9090
| podLabels | object | `{}` | Additional labels to add to the pod(s) only |
91-
| podSecurityContext | object | `{}` | |
91+
| podSecurityContext.fsGroup | int | `1000` | |
92+
| podSecurityContext.fsGroupChangePolicy | string | `"OnRootMismatch"` | |
93+
| podSecurityContext.runAsGroup | int | `1000` | |
94+
| podSecurityContext.runAsNonRoot | bool | `true` | |
95+
| podSecurityContext.runAsUser | int | `1000` | |
9296
| readinessProbe.InitialDelaySeconds | int | `0` | |
9397
| readinessProbe.periodSeconds | int | `10` | |
9498
| replicaCount | int | `1` | Number of Meilisearch pods to run |
9599
| resources | object | `{}` | Resources allocation (Requests and Limits) |
96100
| securityContext.allowPrivilegeEscalation | bool | `false` | |
97101
| securityContext.capabilities.drop[0] | string | `"ALL"` | |
102+
| securityContext.readOnlyRootFilesystem | bool | `true` | |
98103
| service | object | `{"annotations":{},"port":7700,"type":"ClusterIP"}` | Service HTTP port |
99104
| service.annotations | object | `{}` | Additional annotations for service |
100105
| service.type | string | `"ClusterIP"` | Kubernetes Service type |

charts/meilisearch/templates/statefulset.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,34 @@ spec:
3232
securityContext:
3333
{{- toYaml .Values.podSecurityContext | nindent 8 }}
3434
{{- end }}
35-
{{- if or .Values.persistence.enabled .Values.volumes }}
3635
volumes:
36+
- name: tmp
37+
emptyDir: {}
3738
{{- if .Values.persistence.enabled }}
3839
- name: {{ .Values.persistence.volume.name }}
3940
persistentVolumeClaim:
4041
claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ include "meilisearch.fullname" . }}{{- end }}
42+
{{- else }}
43+
- name: {{ .Values.persistence.volume.name }}
44+
emptyDir: {}
4145
{{- end }}
4246
{{- if .Values.volumes }}
4347
{{ toYaml .Values.volumes | indent 8 }}
4448
{{- end }}
45-
{{- end }}
4649
containers:
4750
- name: {{ .Chart.Name }}
4851
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
4952
imagePullPolicy: {{ .Values.image.pullPolicy }}
5053
securityContext:
5154
{{ toYaml .Values.securityContext | indent 12 }}
52-
{{- if or .Values.persistence.enabled .Values.volumeMounts }}
5355
volumeMounts:
54-
{{- if .Values.persistence.enabled }}
56+
- name: tmp
57+
mountPath: /tmp
5558
- name: {{ .Values.persistence.volume.name }}
5659
mountPath: {{ .Values.persistence.volume.mountPath }}
57-
{{- end }}
5860
{{- if .Values.volumeMounts }}
5961
{{ toYaml .Values.volumeMounts | indent 12 }}
6062
{{- end }}
61-
{{- end }}
6263
envFrom:
6364
- configMapRef:
6465
name: {{ template "meilisearch.fullname" . }}-environment

charts/meilisearch/values.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,19 @@ service:
8181
container:
8282
containerPort: 7700
8383

84-
podSecurityContext: {}
84+
podSecurityContext:
85+
runAsNonRoot: true
86+
runAsUser: 1000
87+
runAsGroup: 1000
88+
fsGroup: 1000
89+
fsGroupChangePolicy: OnRootMismatch
8590

8691
securityContext:
8792
capabilities:
8893
drop:
8994
- ALL
9095
allowPrivilegeEscalation: false
91-
# readOnlyRootFilesystem: true
96+
readOnlyRootFilesystem: true
9297

9398
ingress:
9499
# -- Enable ingress controller resource

manifests/meilisearch.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,20 @@ spec:
7575
app.kubernetes.io/component: search-engine
7676
app.kubernetes.io/part-of: meilisearch
7777
annotations:
78-
checksum/config: ae9884187319e63ffb542daf76a83b035abbfb6fe306768ab983e82d34048dca
78+
checksum/config: 2feedcfe9e2a9425200a2c547238c64e882bd9160bf3a521e1dbab0e83ee246f
7979
spec:
8080
serviceAccountName: meilisearch
81+
securityContext:
82+
fsGroup: 1000
83+
fsGroupChangePolicy: OnRootMismatch
84+
runAsGroup: 1000
85+
runAsNonRoot: true
86+
runAsUser: 1000
87+
volumes:
88+
- name: tmp
89+
emptyDir: {}
90+
- name: data
91+
emptyDir: {}
8192
containers:
8293
- name: meilisearch
8394
image: "getmeili/meilisearch:v1.2.0"
@@ -87,6 +98,12 @@ spec:
8798
capabilities:
8899
drop:
89100
- ALL
101+
readOnlyRootFilesystem: true
102+
volumeMounts:
103+
- name: tmp
104+
mountPath: /tmp
105+
- name: data
106+
mountPath: /meili_data
90107
envFrom:
91108
- configMapRef:
92109
name: meilisearch-environment

0 commit comments

Comments
 (0)