⎈ fix: Authenticate Bundled Helm Databases and Warn on Plain-HTTP Ingress (#17047)

* fix: Enable Bundled Database Auth and Warn On Plain-HTTP Ingress

* fix: Render the Env ConfigMap When librechat.configEnv Is Unset

* fix: Respect User-Supplied Mongo and Redis Credentials Over Generated Ones

* docs: Add Upgrade Notice for Bundled MongoDB Auth Default

* fix: Order Supplied Credentials First and Split Bundled Credential Opt-Outs

* fix: Percent-Encode the Bundled MongoDB Root Username in MONGO_URI

* fix: Warn Per Ingress Host Without TLS Coverage and Document Credential Rotation

* docs: Document Password Persistence and Release the Auth Default as a Major Chart Version

* fix: Fail Render When a Supplied Redis Password Does Not Match the Bundled Redis

* fix: Validate Supplied MongoDB Root Password Against the Bundled Server

* docs: Include the Langfuse Fanout Deployment in the Rotation Restart

* fix: Derive Ingress URL Scheme Per Host and Document the MongoDB Replica Set Key

* fix: Validate configEnv Mongo Password and Keep Upgrade Passwords as Strings

* fix: Reject Supplied Database Passwords That Differ From the Bundled Subchart

* fix: Ignore Inherited Literals When a Secret Reference Overrides the Password

* fix: Skip Password Comparison When an Existing Secret Supplies Credentials

* fix: Deny Placeholder Expansion of the Bundled MongoDB Root Password
This commit is contained in:
Marco Beretta 2026-10-14 17:59:26 +02:00 • committed by GitHub
parent 219a48b55d
commit be53625d77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 172 additions and 10 deletions

View file

@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.0.17
version: 3.0.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to

View file

@ -4,6 +4,34 @@ This Librechat Helm Chart provides an easy, light weight template to deploy Libr
## Variables
In this Chart, LibreChat will only work with environment Variables. You can Specify Vars and Secret using an existing Secret (This can be generated by [creating an Env File and converting it to a Kubernetes Secret](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-secret-em-) `--from-env-file`)
## Bundled database credentials and TLS
The bundled MongoDB and Redis subcharts run with authentication enabled. Their generated passwords stay in the subchart Secrets and reach LibreChat through `secretKeyRef` (`MONGODB_ROOT_PASSWORD`, `REDIS_PASSWORD`); `MONGO_URI` is assembled in the Deployment. Set `librechat.configEnv.MONGO_URI` (or `REDIS_URI`) to use your own database. Set `mongodb.auth.enabled=false` or `redis.auth.enabled=false` only to restore the old unauthenticated behavior; custom root passwords must be URL-safe because they are placed in `MONGO_URI`.
If `MONGO_URI`, `REDIS_URI` or `REDIS_PASSWORD` comes from the Secret named by `global.librechat.existingSecretName`, set `librechat.injectBundledCredentials.mongodb=false` (for `MONGO_URI`) or `librechat.injectBundledCredentials.redis=false` (for `REDIS_URI` or `REDIS_PASSWORD`): the chart cannot see inside that Secret, and the generated values would otherwise override it. The two are independent, so overriding one database keeps the generated credentials for the other. Entries with the same names in `global.librechat.env` are respected and not duplicated. Supplying `REDIS_PASSWORD` (or `MONGODB_ROOT_PASSWORD`, in `configEnv` or `global.librechat.env`) while LibreChat still uses the bundled database fails the render unless `redis.auth.password` / `mongodb.auth.rootPassword` (or the matching `existingSecret`) is set too, because the bundled server would otherwise keep its own generated password. Literal values that differ from the subchart's password fail the render as well. The credentials are read when a pod starts, so after rotating a database password restart every Deployment that reads it: `kubectl rollout restart deployment/<release>-librechat`, plus `deployment/<release>-librechat-langfuse-fanout` when `langfuseFanout.enabled=true` and it uses the bundled Redis (or use a rollout controller such as Reloader).
### Keeping the generated passwords across upgrades
With the defaults the subcharts generate the passwords on first install, and the MongoDB subchart refuses later upgrades that do not repeat them ("PASSWORDS ERROR"). Read the current values and pass them on every `helm upgrade`, or point `mongodb.auth.existingSecret` and `redis.auth.existingSecret` at Secrets you manage:
```
kubectl get secret <release>-mongodb -o jsonpath='{.data.mongodb-root-password}' | base64 -d
helm upgrade <release> ... --set-string mongodb.auth.rootPassword=<password>
```
Redis needs `--set-string redis.auth.password=<password>` the same way (`redis-password` in the `<release>-redis` Secret). With `mongodb.architecture=replicaset`, also keep the replica set key: read `mongodb-replica-set-key` from the same Secret and pass it as `--set-string mongodb.auth.replicaSetKey=<key>`.
### Upgrading from an unauthenticated bundled MongoDB
Releases installed before auth became the default have a data volume with no root user, and the persisted data is not re-initialized on upgrade, so LibreChat cannot authenticate after `helm upgrade`. Pick one path:
1. Keep the old behavior: `--set mongodb.auth.enabled=false`.
2. Create the root user first: on the running pre-upgrade pod, run `mongosh admin --eval 'db.createUser({user: "<rootUser>", pwd: "<password>", roles: ["root"]})'` (`<rootUser>` is `mongodb.auth.rootUser`, `root` by default), then upgrade with `--set-string mongodb.auth.rootPassword=<password>` (URL-safe) and the same `mongodb.auth.rootUser` if you changed it. Keep the same password on every later upgrade. An upgrade without `mongodb.auth.rootPassword` is refused by the MongoDB subchart ("PASSWORDS ERROR") because no Secret exists yet.
The chart does not detect this case at render time (it cannot tell a fresh install from an unauthenticated volume), so `NOTES.txt` prints a notice on every upgrade with auth enabled.
The ingress is enabled by default. Set `ingress.tls` (a `secretName` and `hosts`) for any non-local install; `helm install` prints a warning for every ingress host that no `ingress.tls` entry covers.
## Setup
1. Generate Variables

View file

@ -1,8 +1,30 @@
{{- if and .Release.IsUpgrade .Values.mongodb.enabled .Values.mongodb.auth.enabled }}
UPGRADE NOTICE: the bundled MongoDB now runs with authentication enabled by default.
If this release was installed with the previous unauthenticated default, its existing data volume has no root user
and LibreChat will fail to connect. Either set mongodb.auth.enabled=false to keep the old behavior, or create the
root user in the existing database first (see the chart readme, "Upgrading from an unauthenticated bundled MongoDB").
{{ end -}}
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- $covered := list }}
{{- $tlsAll := false }}
{{- range .Values.ingress.tls }}
{{- if .hosts }}{{ $covered = concat $covered .hosts }}{{ else }}{{ $tlsAll = true }}{{ end }}
{{- end }}
{{- $plain := list }}
{{- range .Values.ingress.hosts }}
{{- if not (or $tlsAll (has .host $covered)) }}{{ $plain = append $plain .host }}{{ end }}
{{- end }}
{{- if $plain }}
WARNING: no ingress.tls entry covers {{ join ", " $plain }}, so traffic (including credentials and session cookies) is served over plain HTTP.
Set ingress.tls with a secretName and hosts, or terminate TLS at your load balancer.
{{- end }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
http{{ if or $tlsAll (has $host.host $covered) }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}

View file

@ -143,6 +143,76 @@ Bundled Redis URI used when the Redis subchart is enabled.
{{- printf "redis://%s-master.%s.svc.cluster.local:6379" (include "common.names.fullname" .Subcharts.redis) (.Release.Namespace | lower) -}}
{{- end }}
{{/*
Whether global.librechat.env already defines an env var. Args: dict "root" . "name" NAME.
*/}}
{{- define "librechat.userEnvHas" -}}
{{- range .root.Values.global.librechat.env -}}
{{- if eq .name $.name -}}true{{- end -}}
{{- end -}}
{{- end }}
{{/*
Whether the chart wires LibreChat to the bundled MongoDB with generated credentials.
Skipped when the operator supplies MONGO_URI (configEnv or global.librechat.env),
turns subchart auth off, or sets librechat.injectBundledCredentials.mongodb=false (needed when
MONGO_URI comes from the Secret named by global.librechat.existingSecretName, which
the chart cannot inspect).
*/}}
{{- define "librechat.bundledMongoAuth" -}}
{{- if and .Values.mongodb.enabled .Values.mongodb.auth.enabled (ne (toString (default dict .Values.librechat.injectBundledCredentials).mongodb) "false") (not (get (default dict .Values.librechat.configEnv) "MONGO_URI")) (not (include "librechat.userEnvHas" (dict "root" . "name" "MONGO_URI"))) -}}
true
{{- end -}}
{{- end }}
{{/*
Whether the chart wires LibreChat to the bundled Redis with its generated password.
Same opt-outs as the MongoDB helper (librechat.injectBundledCredentials.redis), for REDIS_URI and REDIS_PASSWORD.
*/}}
{{- define "librechat.bundledRedisAuth" -}}
{{- if and .Values.redis.enabled .Values.redis.auth.enabled (ne (toString (default dict .Values.librechat.injectBundledCredentials).redis) "false") (not (get (default dict .Values.librechat.configEnv) "REDIS_URI")) (not (get (default dict .Values.librechat.configEnv) "REDIS_PASSWORD")) (not (include "librechat.userEnvHas" (dict "root" . "name" "REDIS_URI"))) (not (include "librechat.userEnvHas" (dict "root" . "name" "REDIS_PASSWORD"))) -}}
true
{{- end -}}
{{- end }}
{{/*
Literal value an operator supplied for an env var through librechat.configEnv or a
global.librechat.env entry with a value. Empty when absent or sourced from a Secret.
Args: dict "root" . "name" NAME.
*/}}
{{- define "librechat.suppliedEnvValue" -}}
{{- $v := toString (default "" (get (default dict .root.Values.librechat.configEnv) .name)) -}}
{{- range .root.Values.global.librechat.env -}}
{{- if eq .name $.name -}}{{- $v = toString (default "" .value) -}}{{- end -}}
{{- end -}}
{{- $v -}}
{{- end }}
{{/*
Fail when the operator supplies REDIS_PASSWORD (or MONGODB_ROOT_PASSWORD) but LibreChat still
connects to the bundled authenticated database without the subchart knowing that password. Either set redis.auth.password
or redis.auth.existingSecret, point REDIS_URI at another server, or opt out with
librechat.injectBundledCredentials.redis=false.
*/}}
{{- define "librechat.validateBundledPasswords" -}}
{{- $suppliedPassword := or (get (default dict .Values.librechat.configEnv) "REDIS_PASSWORD") (include "librechat.userEnvHas" (dict "root" . "name" "REDIS_PASSWORD")) -}}
{{- $suppliedURI := or (get (default dict .Values.librechat.configEnv) "REDIS_URI") (include "librechat.userEnvHas" (dict "root" . "name" "REDIS_URI")) -}}
{{- if and .Values.redis.enabled .Values.redis.auth.enabled $suppliedPassword (not $suppliedURI) (ne (toString (default dict .Values.librechat.injectBundledCredentials).redis) "false") (not .Values.redis.auth.password) (not .Values.redis.auth.existingSecret) -}}
{{- fail "REDIS_PASSWORD is set for LibreChat but the bundled Redis generates its own password. Set redis.auth.password (or redis.auth.existingSecret) to the same value, set REDIS_URI to your own server, or set librechat.injectBundledCredentials.redis=false." -}}
{{- end -}}
{{- if and (include "librechat.bundledMongoAuth" .) (or (get (default dict .Values.librechat.configEnv) "MONGODB_ROOT_PASSWORD") (include "librechat.userEnvHas" (dict "root" . "name" "MONGODB_ROOT_PASSWORD"))) (not .Values.mongodb.auth.rootPassword) (not .Values.mongodb.auth.existingSecret) -}}
{{- fail "MONGODB_ROOT_PASSWORD is set for LibreChat but the bundled MongoDB generates its own password. Set mongodb.auth.rootPassword (or mongodb.auth.existingSecret) to the same value, set MONGO_URI to your own server, or set librechat.injectBundledCredentials.mongodb=false." -}}
{{- end -}}
{{- $redisLiteral := include "librechat.suppliedEnvValue" (dict "root" . "name" "REDIS_PASSWORD") -}}
{{- if and .Values.redis.enabled .Values.redis.auth.enabled (not $suppliedURI) (ne (toString (default dict .Values.librechat.injectBundledCredentials).redis) "false") $redisLiteral .Values.redis.auth.password (not .Values.redis.auth.existingSecret) (ne $redisLiteral (toString .Values.redis.auth.password)) -}}
{{- fail "REDIS_PASSWORD for LibreChat differs from redis.auth.password. Use the same value for both." -}}
{{- end -}}
{{- $mongoLiteral := include "librechat.suppliedEnvValue" (dict "root" . "name" "MONGODB_ROOT_PASSWORD") -}}
{{- if and (include "librechat.bundledMongoAuth" .) $mongoLiteral .Values.mongodb.auth.rootPassword (not .Values.mongodb.auth.existingSecret) (ne $mongoLiteral (toString .Values.mongodb.auth.rootPassword)) -}}
{{- fail "MONGODB_ROOT_PASSWORD for LibreChat differs from mongodb.auth.rootPassword. Use the same value for both." -}}
{{- end -}}
{{- end }}
{{/*
RAG Selector labels
*/}}

View file

@ -5,20 +5,20 @@ metadata:
data:
{{- $configEnv := default dict .Values.librechat.configEnv }}
{{- $adminPanelUrl := .Values.librechat.adminPanelUrl }}
{{- $configAdminPanelUrl := dig "configEnv" "ADMIN_PANEL_URL" "" .Values.librechat }}
{{- $configAdminPanelUrl := get $configEnv "ADMIN_PANEL_URL" }}
{{- if (index .Values "librechat-rag-api" "enabled") }}
RAG_API_URL: http://{{ include "rag.fullname" (index .Subcharts "librechat-rag-api") | lower }}.{{ .Release.Namespace | lower }}.svc.cluster.local:8000
{{- end }}
{{- if and (not (dig "configEnv" "MEILI_HOST" "" .Values.librechat)) .Values.meilisearch.enabled }}
{{- if and (not (get $configEnv "MEILI_HOST")) .Values.meilisearch.enabled }}
MEILI_HOST: http://{{ include "meilisearch.fullname" .Subcharts.meilisearch }}.{{ .Release.Namespace | lower }}.svc.cluster.local:7700
{{- end }}
{{- if and (not (dig "configEnv" "MONGO_URI" "" .Values.librechat)) .Values.mongodb.enabled }}
{{- if and (not (get $configEnv "MONGO_URI")) .Values.mongodb.enabled (not (include "librechat.bundledMongoAuth" .)) }}
MONGO_URI: mongodb://{{ include "mongodb.service.nameOverride" .Subcharts.mongodb }}.{{ .Release.Namespace | lower }}.svc.cluster.local:27017/LibreChat
{{- end }}
{{- if and (not (dig "configEnv" "USE_REDIS" "" .Values.librechat)) .Values.redis.enabled }}
{{- if and (not (get $configEnv "USE_REDIS")) .Values.redis.enabled }}
USE_REDIS: "true"
{{- end }}
{{- if and (not (dig "configEnv" "REDIS_URI" "" .Values.librechat)) .Values.redis.enabled }}
{{- if and (not (get $configEnv "REDIS_URI")) .Values.redis.enabled }}
REDIS_URI: {{ include "librechat.bundledRedisURI" . }}
{{- end }}
{{- if and $adminPanelUrl (not $configAdminPanelUrl) }}

View file

@ -103,10 +103,31 @@ spec:
name: {{ .Values.global.librechat.existingSecretName }}
optional: false
{{- end }}
{{- with .Values.global.librechat.env }}
{{- include "librechat.validateBundledPasswords" . }}
{{- if or (include "librechat.bundledMongoAuth" .) (include "librechat.bundledRedisAuth" .) .Values.global.librechat.env }}
env:
{{- with .Values.global.librechat.env }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if include "librechat.bundledMongoAuth" . }}
{{- if not (include "librechat.userEnvHas" (dict "root" . "name" "MONGODB_ROOT_PASSWORD")) }}
- name: MONGODB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" .Subcharts.mongodb | quote }}
key: mongodb-root-password
{{- end }}
- name: MONGO_URI
value: mongodb://{{ .Values.mongodb.auth.rootUser | default "root" | urlquery | replace "+" "%20" }}:$(MONGODB_ROOT_PASSWORD)@{{ include "mongodb.service.nameOverride" .Subcharts.mongodb }}.{{ .Release.Namespace | lower }}.svc.cluster.local:27017/LibreChat?authSource=admin
{{- end }}
{{- if include "librechat.bundledRedisAuth" . }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "redis.secretName" .Subcharts.redis | quote }}
key: {{ include "redis.secretPasswordKey" .Subcharts.redis | quote }}
{{- end }}
{{- end }}
volumes:
{{- if or .Values.librechat.configYamlContent .Values.librechat.existingConfigYaml }}
- name: config-yaml

View file

@ -72,6 +72,13 @@ spec:
name: {{ . | quote }}
key: {{ $.Values.langfuseFanout.redis.passwordSecret.key | quote }}
{{- end }}
{{- if and (not .Values.langfuseFanout.redis.passwordSecret.name) (not .Values.langfuseFanout.redis.uri) .Values.redis.enabled .Values.redis.auth.enabled }}
- name: LANGFUSE_FANOUT_REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "redis.secretName" .Subcharts.redis | quote }}
key: {{ include "redis.secretPasswordKey" .Subcharts.redis | quote }}
{{- end }}
- name: LANGFUSE_FANOUT_REDIS_KEY_PREFIX
value: {{ .Values.langfuseFanout.redis.keyPrefix | quote }}
- name: LANGFUSE_FANOUT_PUBLIC_URL

View file

@ -43,6 +43,12 @@ librechat:
# Example: https://admin.example.com/admin
adminPanelUrl: ""
# Inject MONGO_URI / REDIS_PASSWORD built from the bundled subchart Secrets. Set a
# key to false when that database's settings come from global.librechat.existingSecretName.
injectBundledCredentials:
mongodb: true
redis: true
configEnv:
# Set unique, persistent values in global.librechat.existingSecretName before production use.
# If omitted, LibreChat generates temporary values in .env.temp when the container filesystem is persistent.
@ -194,6 +200,8 @@ ingress:
paths:
- path: /
pathType: ImplementationSpecific
# Set tls for any non-local install; without it the ingress serves plain HTTP
# and NOTES.txt prints a warning.
tls: []
# - secretName: chart-example-tls
# hosts:
@ -373,8 +381,11 @@ mongodb:
# See https://github.com/bitnami/charts/issues/35164
image:
repository: bitnamilegacy/mongodb
# Credentials are generated into the subchart Secret and injected into
# MONGO_URI via secretKeyRef. Set librechat.configEnv.MONGO_URI to use your
# own database, or auth.enabled=false to restore the unauthenticated setup.
auth:
enabled: false
enabled: true
databases:
- LibreChat
# persistence:
@ -397,5 +408,6 @@ meilisearch:
redis:
enabled: false
architecture: standalone
# The generated password is injected as REDIS_PASSWORD via secretKeyRef.
auth:
enabled: false
enabled: true

View file

@ -135,6 +135,7 @@ describe('Environment Variable Extraction', () => {
expect(isSensitiveEnvVar('CREDS_IV')).toBe(true);
expect(isSensitiveEnvVar('MEILI_MASTER_KEY')).toBe(true);
expect(isSensitiveEnvVar('MONGO_URI')).toBe(true);
expect(isSensitiveEnvVar('MONGODB_ROOT_PASSWORD')).toBe(true);
expect(isSensitiveEnvVar('REDIS_URI')).toBe(true);
expect(isSensitiveEnvVar('REDIS_PASSWORD')).toBe(true);
});

View file

@ -15,6 +15,7 @@ const SENSITIVE_ENV_VARS = new Set([
'CREDS_IV',
'MEILI_MASTER_KEY',
'MONGO_URI',
'MONGODB_ROOT_PASSWORD',
'REDIS_URI',
'REDIS_PASSWORD',
]);