Skip to content

Commit 69a1003

Browse files
authored
BasicAuth for frontend (#114)
1 parent ec93b61 commit 69a1003

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

charts/blockscout-stack/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## 4.4.0
4+
5+
### Feature
6+
7+
- Add Basic Authentication support for frontend ingress. Supports two modes: referencing an existing Secret (`existingSecret`) or generating one from username/password in values
8+
39
## 4.3.0
410

511
### Feature

charts/blockscout-stack/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ type: application
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
1818

19-
version: 4.3.1
19+
version: 4.4.0
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to
2323
# follow Semantic Versioning. They should reflect the version the application is using.
2424
# It is recommended to use it with quotes.
25-
appVersion: "9.3.0"
25+
appVersion: "9.3.5"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if and .Values.frontend.enabled .Values.frontend.ingress.enabled .Values.frontend.ingress.basicAuth.enabled (not .Values.frontend.ingress.basicAuth.existingSecret) }}
2+
{{- $username := required "frontend.ingress.basicAuth.username is required when generating a basic auth secret" .Values.frontend.ingress.basicAuth.username }}
3+
{{- $password := required "frontend.ingress.basicAuth.password is required when generating a basic auth secret" .Values.frontend.ingress.basicAuth.password }}
4+
{{- $secretName := default (printf "%s-frontend-basic-auth" (include "blockscout-stack.fullname" .)) .Values.frontend.ingress.basicAuth.secretName }}
5+
{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace $secretName }}
6+
apiVersion: v1
7+
kind: Secret
8+
metadata:
9+
name: {{ $secretName }}
10+
labels:
11+
{{- include "blockscout-stack.labels" . | nindent 4 }}
12+
type: Opaque
13+
data:
14+
{{- if and $existingSecret $existingSecret.data (index $existingSecret.data "auth") }}
15+
auth: {{ index $existingSecret.data "auth" }}
16+
{{- else }}
17+
auth: {{ htpasswd $username $password | b64enc | quote }}
18+
{{- end }}
19+
{{- end }}

charts/blockscout-stack/templates/frontend-ingress.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@ metadata:
1919
name: {{ $fullName }}-frontend-ingress
2020
labels:
2121
{{- include "blockscout-stack.labels" . | nindent 4 }}
22+
{{- $annotations := dict }}
2223
{{- with .Values.frontend.ingress.annotations }}
24+
{{- $annotations = merge $annotations . }}
25+
{{- end }}
26+
{{- if .Values.frontend.ingress.basicAuth.enabled }}
27+
{{- $authSecretName := "" }}
28+
{{- if .Values.frontend.ingress.basicAuth.existingSecret }}
29+
{{- $authSecretName = .Values.frontend.ingress.basicAuth.existingSecret }}
30+
{{- else }}
31+
{{- $authSecretName = default (printf "%s-frontend-basic-auth" (include "blockscout-stack.fullname" .)) .Values.frontend.ingress.basicAuth.secretName }}
32+
{{- end }}
33+
{{- $_ := set $annotations "nginx.ingress.kubernetes.io/auth-type" "basic" }}
34+
{{- $_ := set $annotations "nginx.ingress.kubernetes.io/auth-secret" $authSecretName }}
35+
{{- $_ := set $annotations "nginx.ingress.kubernetes.io/auth-realm" (.Values.frontend.ingress.basicAuth.realm | default "Authentication Required") }}
36+
{{- end }}
37+
{{- if $annotations }}
2338
annotations:
24-
{{- toYaml . | nindent 4 }}
39+
{{- toYaml $annotations | nindent 4 }}
2540
{{- end }}
2641
spec:
2742
{{- if and .Values.frontend.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}

charts/blockscout-stack/values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,25 @@ frontend:
274274
paths:
275275
- path: /
276276

277+
## Basic authentication for frontend ingress (nginx ingress controller)
278+
## ref: https://kubernetes.github.io/ingress-nginx/examples/auth/basic/
279+
##
280+
basicAuth:
281+
enabled: false
282+
## Use an existing Secret containing key "auth" with htpasswd-formatted credentials.
283+
## Recommended for production / GitOps workflows.
284+
existingSecret: ""
285+
## Override the generated Secret name (only used when existingSecret is empty).
286+
## Default: "<release>-frontend-basic-auth"
287+
secretName: ""
288+
## Credentials for chart-generated Secret (only when existingSecret is empty).
289+
## WARNING: storing passwords in values.yaml exposes them to Git history and CI logs.
290+
## Use existingSecret or external secret management for production.
291+
username: ""
292+
password: ""
293+
## Authentication realm shown in the browser prompt
294+
realm: "Authentication Required"
295+
277296
resources:
278297
limits:
279298
memory: "1Gi"

0 commit comments

Comments
 (0)