Skip to content

Commit 5cad2bf

Browse files
bors[bot]carlreid
andauthored
Merge #62
62: Generate secret for master key if the env is set to production r=eskombro a=carlreid With these changes, if someone were to set `MEILI_ENV` to `production` and not set `MEILI_MASTER_KEY`, then a cryptographically secure random secret (using `randAlphaNum`) will be created automatically and then loaded as an environment variable. If you set `MEILI_MASTER_KEY` in the values.yaml, then that is used instead, so no secret is generated/used. If the env is `development` then no secret is created at all. You could still set `MEILI_MASTER_KEY` in the values.yaml, as those just get loaded in no matter what. Resolves #19 and maybe #38 Co-authored-by: Carl Reid <[email protected]>
2 parents 192e080 + f87af58 commit 5cad2bf

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- name: Run chart-testing (lint)
2222
id: lint
23-
uses: helm/chart-testing-action@v1.0.0
23+
uses: helm/chart-testing-action@v2.0.1
2424
with:
2525
command: lint
2626
config: ct.yaml
@@ -35,10 +35,10 @@ jobs:
3535
run: git fetch --prune --unshallow
3636

3737
- name: Create kind cluster
38-
uses: helm/kind-action@v1.0.0-alpha.3
38+
uses: helm/kind-action@v1.1.0
3939

4040
- name: Run chart-testing (install)
41-
uses: helm/chart-testing-action@v1.0.0
41+
uses: helm/chart-testing-action@v2.0.1
4242
with:
4343
command: install
4444
config: ct.yaml

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: "v0.19.0"
33
description: A Helm chart for the Meilisearch search engine
44
name: meilisearch
5-
version: 0.1.13
5+
version: 0.1.14
66
icon: https://res.cloudinary.com/meilisearch/image/upload/v1597822872/Logo/logo_img.svg
77
home: https://github.com/meilisearch/meilisearch-kubernetes/charts
88
maintainers:

charts/meilisearch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ helm uninstall <your-service-name>
9494

9595
The `environment` block allows to specify all the environment variables declared on [MeiliSearch Configuration](https://docs.meilisearch.com/guides/advanced_guides/configuration.html#passing-arguments-via-the-command-line)
9696

97-
For production deployment, the `environment.MEILI_MASTER_KEY` is required
97+
For production deployment, the `environment.MEILI_MASTER_KEY` is required. If `MEILI_ENV` is set to "production" without setting `environment.MEILI_MASTER_KEY`, then this chart will automatically create a secure `environment.MEILI_MASTER_KEY` as a secret. To get the value of this secret, you can read it with this command: `kubectl get secret meilisearch-master-key --template={{.data.MEILI_MASTER_KEY}} | base64 --decode`.

charts/meilisearch/templates/_helpers.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ Create chart name and version as used by the chart label.
3030
{{- define "meilisearch.chart" -}}
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
3232
{{- end -}}
33+
34+
{{/*
35+
Checks for environment being set to "production" without a master key being set explicitly
36+
*/}}
37+
{{- define "isProductionWithoutMasterKey" -}}
38+
{{- if and (eq .Values.environment.MEILI_ENV "production") (not .Values.environment.MEILI_MASTER_KEY) -}}
39+
{{- "true" -}}
40+
{{- else -}}
41+
{{- "false" -}}
42+
{{- end -}}
43+
{{- end -}}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if eq (include "isProductionWithoutMasterKey" .) "true" }}
2+
{{- $secretName := printf "%s-%s" (include "meilisearch.fullname" . ) "master-key" }}
3+
{{- $secret := (lookup "v1" "Secret" .Release.Namespace $secretName) -}}
4+
apiVersion: v1
5+
kind: Secret
6+
metadata:
7+
name: {{ $secretName }}
8+
labels:
9+
app.kubernetes.io/name: {{ include "meilisearch.name" . }}
10+
helm.sh/chart: {{ include "meilisearch.chart" . }}
11+
app.kubernetes.io/instance: {{ .Release.Name }}
12+
app.kubernetes.io/managed-by: {{ .Release.Service }}
13+
data:
14+
{{- if $secret }}
15+
MEILI_MASTER_KEY: {{ $secret.data.MEILI_MASTER_KEY }}
16+
{{ else }}
17+
MEILI_MASTER_KEY: {{ randAlphaNum 20 | b64enc }}
18+
{{- end }}
19+
{{ end }}

charts/meilisearch/templates/statefulset.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ spec:
4747
envFrom:
4848
- configMapRef:
4949
name: {{ template "meilisearch.fullname" . }}-environment
50+
{{- if eq (include "isProductionWithoutMasterKey" .) "true" }}
51+
- secretRef:
52+
name: {{ template "meilisearch.fullname" . }}-master-key
53+
{{- end }}
5054
ports:
5155
- name: http
5256
containerPort: {{ .Values.container.containerPort }}

charts/meilisearch/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ fullnameOverride: ""
2424
environment:
2525
MEILI_NO_ANALYTICS: true
2626
MEILI_ENV: development
27+
# For production deployment, the environment MEILI_MASTER_KEY is required.
28+
# If MEILI_ENV is set to "production" without setting MEILI_MASTER_KEY, this
29+
# chart will automatically create a secure MEILI_MASTER_KEY and push it as a
30+
# secret. Otherwise the below value of MEILI_MASTER_KEY will be used instead.
31+
# MEILI_MASTER_KEY:
2732

2833
podAnnotations: {}
2934

0 commit comments

Comments
 (0)