From d7ef3be57959c905e69602a9f21cb03ee729541b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20K=C3=B6hler?= <9337156+axdotl@users.noreply.github.com> Date: Mon, 13 Sep 2021 15:55:10 +0200 Subject: [PATCH] [bitnami/mongodb] Configurable admin/root user name (#7229) * Configurable admin/root user name * Adjust exporter uri * Update bitnami/mongodb/values.yaml Co-authored-by: Juan Ariza Toledano * Adding readme metadata Co-authored-by: Juan Ariza Toledano --- bitnami/mongodb/Chart.yaml | 2 +- bitnami/mongodb/README.md | 1 + bitnami/mongodb/templates/_helpers.tpl | 2 +- bitnami/mongodb/templates/arbiter/statefulset.yaml | 2 ++ bitnami/mongodb/templates/hidden/statefulset.yaml | 2 ++ bitnami/mongodb/templates/replicaset/scripts-configmap.yaml | 2 ++ bitnami/mongodb/templates/replicaset/statefulset.yaml | 4 ++++ bitnami/mongodb/templates/standalone/dep-sts.yaml | 4 ++++ bitnami/mongodb/values.schema.json | 6 ++++++ bitnami/mongodb/values.yaml | 3 +++ 10 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bitnami/mongodb/Chart.yaml b/bitnami/mongodb/Chart.yaml index dc9f1b95f..1ab5f8b8e 100644 --- a/bitnami/mongodb/Chart.yaml +++ b/bitnami/mongodb/Chart.yaml @@ -26,4 +26,4 @@ name: mongodb sources: - https://github.com/bitnami/bitnami-docker-mongodb - https://mongodb.org -version: 10.25.2 +version: 10.26.0 diff --git a/bitnami/mongodb/README.md b/bitnami/mongodb/README.md index 0b1d54161..362cedccc 100644 --- a/bitnami/mongodb/README.md +++ b/bitnami/mongodb/README.md @@ -97,6 +97,7 @@ Refer to the [chart documentation for more information on each of these architec | `architecture` | MongoDB® architecture (`standalone` or `replicaset`) | `standalone` | | `useStatefulSet` | Set to true to use a StatefulSet instead of a Deployment (only when `architecture=standalone`) | `false` | | `auth.enabled` | Enable authentication | `true` | +| `auth.rootUser` | MongoDB® root user | `root` | | `auth.rootPassword` | MongoDB® root password | `""` | | `auth.username` | MongoDB® custom user (mandatory if `auth.database` is set) | `""` | | `auth.password` | MongoDB® custom user password | `""` | diff --git a/bitnami/mongodb/templates/_helpers.tpl b/bitnami/mongodb/templates/_helpers.tpl index b2e1bb7ac..4ce6c5eee 100644 --- a/bitnami/mongodb/templates/_helpers.tpl +++ b/bitnami/mongodb/templates/_helpers.tpl @@ -346,7 +346,7 @@ Validate values of MongoDB® exporter URI string - auth.enabled and/or tls.en */}} {{- define "mongodb.mongodb_exporter.uri" -}} {{- $uriTlsArgs := ternary "tls=true&tlsCertificateKeyFile=/certs/mongodb.pem&tlsCAFile=/certs/mongodb-ca-cert" "" .Values.tls.enabled -}} - {{- $uriAuth := ternary "root:$(echo $MONGODB_ROOT_PASSWORD | sed -r \"s/@/%40/g;s/:/%3A/g\")@" "" .Values.auth.enabled -}} + {{- $uriAuth := ternary "$MONGODB_ROOT_USER:$(echo $MONGODB_ROOT_PASSWORD | sed -r \"s/@/%40/g;s/:/%3A/g\")@" "" .Values.auth.enabled -}} {{- printf "mongodb://%slocalhost:27017/admin?%s" $uriAuth $uriTlsArgs -}} {{- end -}} diff --git a/bitnami/mongodb/templates/arbiter/statefulset.yaml b/bitnami/mongodb/templates/arbiter/statefulset.yaml index d1b594b45..810e5070f 100644 --- a/bitnami/mongodb/templates/arbiter/statefulset.yaml +++ b/bitnami/mongodb/templates/arbiter/statefulset.yaml @@ -166,6 +166,8 @@ spec: - name: MONGODB_ADVERTISED_HOSTNAME value: "$(MY_POD_NAME).$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.{{ .Values.clusterDomain }}" {{- if .Values.auth.enabled }} + - name: MONGODB_INITIAL_PRIMARY_ROOT_USER + value: {{ .Values.auth.rootUser | quote }} - name: MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD valueFrom: secretKeyRef: diff --git a/bitnami/mongodb/templates/hidden/statefulset.yaml b/bitnami/mongodb/templates/hidden/statefulset.yaml index 8f500650b..ca732e8c2 100644 --- a/bitnami/mongodb/templates/hidden/statefulset.yaml +++ b/bitnami/mongodb/templates/hidden/statefulset.yaml @@ -401,6 +401,8 @@ spec: {{- end }} env: {{- if .Values.auth.enabled }} + - name: MONGODB_ROOT_USER + value: {{ .Values.auth.rootUser | quote }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: diff --git a/bitnami/mongodb/templates/replicaset/scripts-configmap.yaml b/bitnami/mongodb/templates/replicaset/scripts-configmap.yaml index afbbd4152..a57780cbf 100644 --- a/bitnami/mongodb/templates/replicaset/scripts-configmap.yaml +++ b/bitnami/mongodb/templates/replicaset/scripts-configmap.yaml @@ -87,6 +87,7 @@ data: else echo "Pod name doesn't match initial primary pod name, configuring node as a secondary" export MONGODB_REPLICA_SET_MODE="secondary" + export MONGODB_INITIAL_PRIMARY_ROOT_USER="$MONGODB_ROOT_USER" export MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD="$MONGODB_ROOT_PASSWORD" export MONGODB_INITIAL_PRIMARY_PORT_NUMBER="$MONGODB_PORT_NUMBER" export MONGODB_ROOT_PASSWORD="" MONGODB_USERNAME="" MONGODB_DATABASE="" MONGODB_PASSWORD="" @@ -118,6 +119,7 @@ data: echo "Advertised Hostname: $MONGODB_ADVERTISED_HOSTNAME" echo "Configuring node as a hidden node" export MONGODB_REPLICA_SET_MODE="hidden" + export MONGODB_INITIAL_PRIMARY_ROOT_USER="$MONGODB_ROOT_USER" export MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD="$MONGODB_ROOT_PASSWORD" export MONGODB_INITIAL_PRIMARY_PORT_NUMBER="$MONGODB_PORT_NUMBER" export MONGODB_ROOT_PASSWORD="" MONGODB_USERNAME="" MONGODB_DATABASE="" MONGODB_PASSWORD="" diff --git a/bitnami/mongodb/templates/replicaset/statefulset.yaml b/bitnami/mongodb/templates/replicaset/statefulset.yaml index b7d19a405..ed9f5da90 100644 --- a/bitnami/mongodb/templates/replicaset/statefulset.yaml +++ b/bitnami/mongodb/templates/replicaset/statefulset.yaml @@ -257,6 +257,8 @@ spec: name: {{ include "mongodb.secretName" . }} key: mongodb-password {{- end }} + - name: MONGODB_ROOT_USER + value: {{ .Values.auth.rootUser | quote }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: @@ -435,6 +437,8 @@ spec: {{- end }} env: {{- if .Values.auth.enabled }} + - name: MONGODB_ROOT_USER + value: {{ .Values.auth.rootUser | quote }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: diff --git a/bitnami/mongodb/templates/standalone/dep-sts.yaml b/bitnami/mongodb/templates/standalone/dep-sts.yaml index f6ad6fb54..9f1b209b6 100644 --- a/bitnami/mongodb/templates/standalone/dep-sts.yaml +++ b/bitnami/mongodb/templates/standalone/dep-sts.yaml @@ -211,6 +211,8 @@ spec: name: {{ include "mongodb.secretName" . }} key: mongodb-password {{- end }} + - name: MONGODB_ROOT_USER + value: {{ .Values.auth.rootUser | quote }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: @@ -373,6 +375,8 @@ spec: /bin/mongodb_exporter --web.listen-address ":{{ .Values.metrics.containerPort }}" --mongodb.uri "{{ include "mongodb.mongodb_exporter.uri" . }}" {{ .Values.metrics.extraFlags }} env: {{- if .Values.auth.enabled }} + - name: MONGODB_ROOT_USER + value: {{ .Values.auth.rootUser | quote }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: diff --git a/bitnami/mongodb/values.schema.json b/bitnami/mongodb/values.schema.json index be27a3029..be8e54b45 100644 --- a/bitnami/mongodb/values.schema.json +++ b/bitnami/mongodb/values.schema.json @@ -18,6 +18,12 @@ "title": "Enable Authentication", "form": true }, + "rootUser": { + "type": "string", + "title": "MongoDB® admin user", + "form": true, + "description": "Name of the admin user. Default is root" + }, "rootPassword": { "type": "string", "title": "MongoDB® admin password", diff --git a/bitnami/mongodb/values.yaml b/bitnami/mongodb/values.yaml index 5d11a380f..22cb4762b 100644 --- a/bitnami/mongodb/values.yaml +++ b/bitnami/mongodb/values.yaml @@ -133,6 +133,9 @@ auth: ## ref: https://docs.mongodb.com/manual/tutorial/enable-authentication/ ## enabled: true + ## @param auth.rootUser MongoDB® root user + ## + rootUser: root ## @param auth.rootPassword MongoDB® root password ## ref: https://github.com/bitnami/bitnami-docker-mongodb/blob/master/README.md#setting-the-root-password-on-first-run ##