Skip to content

Commit 0f0553f

Browse files
authored
helm: make multi tenant easy: use tenant id from nginx $remote_user (#8404)
Fixes #8380 Co-authored-by: a5r0n <[email protected]>
1 parent 2e11ff0 commit 0f0553f

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

docs/sources/installation/helm/reference.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ null
803803
<tr>
804804
<td>gateway.basicAuth.htpasswd</td>
805805
<td>string</td>
806-
<td>Uses the specified username and password to compute a htpasswd using Sprig's `htpasswd` function. The value is templated using `tpl`. Override this to use a custom htpasswd, e.g. in case the default causes high CPU load.</td>
806+
<td>Uses the specified users from the `loki.tenants` list to create the htpasswd file if `loki.tenants` is not set, the `gateway.basicAuth.username` and `gateway.basicAuth.password` are used The value is templated using `tpl`. Override this to use a custom htpasswd, e.g. in case the default causes high CPU load.</td>
807807
<td><pre lang="json">
808-
"{{ htpasswd (required \"'gateway.basicAuth.username' is required\" .Values.gateway.basicAuth.username) (required \"'gateway.basicAuth.password' is required\" .Values.gateway.basicAuth.password) }}"
808+
"{{ if .Values.loki.tenants }}\n {{- range $t := .Values.loki.tenants }}\n{{ htpasswd (required \"All tenants must have a 'name' set\" $t.name) (required \"All tenants must have a 'password' set\" $t.password) }}\n {{- end }}\n{{ else }} {{ htpasswd (required \"'gateway.basicAuth.username' is required\" .Values.gateway.basicAuth.username) (required \"'gateway.basicAuth.password' is required\" .Values.gateway.basicAuth.password) }} {{ end }}"
809809
</pre>
810810
</td>
811811
</tr>
@@ -1054,9 +1054,9 @@ See values.yaml
10541054
<tr>
10551055
<td>gateway.nginxConfig.httpSnippet</td>
10561056
<td>string</td>
1057-
<td>Allows appending custom configuration to the http block</td>
1057+
<td>Allows appending custom configuration to the http block, passed through the `tpl` function to allow templating</td>
10581058
<td><pre lang="json">
1059-
""
1059+
"{{ if .Values.loki.tenants }}proxy_set_header X-Scope-OrgID $remote_user;{{ end }}"
10601060
</pre>
10611061
</td>
10621062
</tr>
@@ -1935,6 +1935,15 @@ null
19351935
<td><pre lang="json">
19361936
{}
19371937
</pre>
1938+
</td>
1939+
</tr>
1940+
<tr>
1941+
<td>loki.tenants</td>
1942+
<td>list</td>
1943+
<td>Tenants list to be created on nginx htpasswd file, with name and password keys</td>
1944+
<td><pre lang="json">
1945+
[]
1946+
</pre>
19381947
</td>
19391948
</tr>
19401949
<tr>

production/helm/loki/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ http {
556556
resolver {{ .Values.global.dnsService }}.{{ .Values.global.dnsNamespace }}.svc.{{ .Values.global.clusterDomain }}.;
557557

558558
{{- with .Values.gateway.nginxConfig.httpSnippet }}
559-
{{ . | nindent 2 }}
559+
{{- tpl . $ | nindent 2 }}
560560
{{- end }}
561561

562562
server {

production/helm/loki/values.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ loki:
202202
203203
# Should authentication be enabled
204204
auth_enabled: true
205+
# -- Tenants list to be created on nginx htpasswd file, with name and password keys
206+
tenants: []
205207

206208
# -- Check https://grafana.com/docs/loki/latest/configuration/#server for more info on the server configuration.
207209
server:
@@ -1171,12 +1173,18 @@ gateway:
11711173
username: null
11721174
# -- The basic auth password for the gateway
11731175
password: null
1174-
# -- Uses the specified username and password to compute a htpasswd using Sprig's `htpasswd` function.
1176+
# -- Uses the specified users from the `loki.tenants` list to create the htpasswd file
1177+
# if `loki.tenants` is not set, the `gateway.basicAuth.username` and `gateway.basicAuth.password` are used
11751178
# The value is templated using `tpl`. Override this to use a custom htpasswd, e.g. in case the default causes
11761179
# high CPU load.
11771180
htpasswd: >-
1181+
{{ if .Values.loki.tenants }}
1182+
{{- range $t := .Values.loki.tenants }}
1183+
{{ htpasswd (required "All tenants must have a 'name' set" $t.name) (required "All tenants must have a 'password' set" $t.password) }}
1184+
{{- end }}
1185+
{{ else }}
11781186
{{ htpasswd (required "'gateway.basicAuth.username' is required" .Values.gateway.basicAuth.username) (required "'gateway.basicAuth.password' is required" .Values.gateway.basicAuth.password) }}
1179-
1187+
{{ end }}
11801188
# -- Existing basic auth secret to use. Must contain '.htpasswd'
11811189
existingSecret: null
11821190
# Configures the readiness probe for the gateway
@@ -1194,8 +1202,9 @@ gateway:
11941202
'"$http_user_agent" "$http_x_forwarded_for"';
11951203
# -- Allows appending custom configuration to the server block
11961204
serverSnippet: ""
1197-
# -- Allows appending custom configuration to the http block
1198-
httpSnippet: ""
1205+
# -- Allows appending custom configuration to the http block, passed through the `tpl` function to allow templating
1206+
httpSnippet: >-
1207+
{{ if .Values.loki.tenants }}proxy_set_header X-Scope-OrgID $remote_user;{{ end }}
11991208
# -- Override Read URL
12001209
customReadUrl: null
12011210
# -- Override Write URL

0 commit comments

Comments
 (0)