Skip to content

Commit 97fcd03

Browse files
Andrea-GallicchioAndrea Gallicchio
andauthored
feat: Add support for existingSecret for htpasswd authentication (#180)
* Add support for existingSecret for htpasswd authentication Add support for referencing an existing Kubernetes secret for htpasswd authentication, avoiding plain text passwords in `values.yaml`. - Add `secrets.existingSecretHtpasswd` to reference an existing secret - Add `secrets.existingSecretHtpasswdKey` to specify the key name (defaults to "htpasswd") - Update templates to support both generated and existing secrets - Add README documentation ```yaml secrets: existingSecretHtpasswd: "my-htpasswd-secret" existingSecretHtpasswdKey: "htpasswd" # Optional ``` Create the secret: ```bash kubectl create secret generic my-htpasswd-secret \ --from-file=htpasswd=/path/to/htpasswd ``` If both `secrets.htpasswd` and `secrets.existingSecretHtpasswd` are set, the existing secret takes precedence. * Improve template readability and remove misleading checksum annotation Address review feedback from Copilot suggestions: - Remove checksum annotation for existingSecretHtpasswd that only tracked secret name/key but not actual content, which was misleading - Refactor inline conditionals for subPath and secretName to multi-line if-else blocks for better template readability - Add documentation note about manual pod restart requirement when updating external secrets --------- Co-authored-by: Andrea Gallicchio <andrea.gallicchio@extern.aroundhome.de>
1 parent 39bdb0f commit 97fcd03

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ and their default values.
134134
| `fullnameOverride` | Set resource fullname override | `""` |
135135
| `useSecretHtpasswd` | Use htpasswd from `.Values.secrets.htpasswd`. This require helm v3.2.0 or above. | `false` |
136136
| `secrets.htpasswd` | user and password list to generate htpasswd. | `[]` |
137+
| `secrets.existingSecretHtpasswd` | Existing secret containing htpasswd file (alternative to `secrets.htpasswd`) | `""` |
138+
| `secrets.existingSecretHtpasswdKey` | Key in the existing secret that contains the htpasswd file content | `"htpasswd"` |
137139
| `ingress.enabled` | Enable/Disable Ingress | `false` |
138140
| `ingress.className` | Ingress Class Name (k8s `>=1.18` required) | `""` |
139141
| `ingress.labels` | Ingress Labels | `{}` |
@@ -191,6 +193,47 @@ secrets:
191193
This config will create a htpasswd file with user "verdaccio", If in config
192194
'htpasswd' auth is used. You can login using this credentials.
193195
196+
### Use existing secret for htpasswd
197+
198+
Instead of providing plain text credentials in `values.yaml`, you can reference an
199+
existing Kubernetes secret containing the htpasswd file. This is more secure as it
200+
avoids storing passwords in plain text in your values files.
201+
202+
When `secrets.existingSecretHtpasswd` is set, the chart will use the specified
203+
secret instead of generating one from `secrets.htpasswd`. The secret must contain
204+
a key with the htpasswd file content (default key: `htpasswd`, configurable via
205+
`secrets.existingSecretHtpasswdKey`).
206+
207+
#### Example
208+
209+
```yaml
210+
secrets:
211+
# Reference an existing secret instead of providing plain text credentials
212+
existingSecretHtpasswd: "my-htpasswd-secret"
213+
existingSecretHtpasswdKey: "htpasswd" # Optional, defaults to "htpasswd"
214+
```
215+
216+
The existing secret should contain the htpasswd file content in the specified key.
217+
You can create such a secret using:
218+
219+
```bash
220+
kubectl create secret generic my-htpasswd-secret \
221+
--from-file=htpasswd=/path/to/htpasswd
222+
```
223+
224+
> **Note**: If both `secrets.htpasswd` and `secrets.existingSecretHtpasswd` are set,
225+
> `secrets.existingSecretHtpasswd` takes precedence and no secret will be generated
226+
> from `secrets.htpasswd`.
227+
228+
> **Important**: When using an existing secret, pods will **not** automatically restart
229+
> when the secret content is updated. This is a limitation of Kubernetes - it doesn't
230+
> track changes to external secrets. You need to manually trigger a pod restart after
231+
> updating the secret:
232+
>
233+
> ```bash
234+
> kubectl rollout restart deployment/<release-name>-verdaccio
235+
> ```
236+
194237
### Custom ConfigMap
195238

196239
When creating a new chart with this chart as a dependency, CustomConfigMap can

charts/verdaccio/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
description: A lightweight private node.js proxy registry
33
name: verdaccio
4-
version: 4.28.0
4+
version: 4.29.0
55
appVersion: 6.2.3
66
home: https://verdaccio.org
77
icon: https://cdn.verdaccio.dev/logos/default.png

charts/verdaccio/templates/deployment.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ spec:
3232
metadata:
3333
annotations:
3434
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
35+
{{- if and .Values.secrets.htpasswd (not .Values.secrets.existingSecretHtpasswd) }}
3536
checksum/htpasswd-secret: {{ toJson .Values.secrets.htpasswd | sha256sum }}
37+
{{- end }}
3638
{{- if .Values.secretEnvVars }}
3739
checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
3840
{{- end }}
@@ -129,10 +131,14 @@ spec:
129131
- mountPath: /verdaccio/storage
130132
name: storage
131133
readOnly: false
132-
{{- if .Values.secrets.htpasswd }}
134+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
133135
- mountPath: /verdaccio/storage/htpasswd
134136
name: htpasswd
137+
{{- if .Values.secrets.existingSecretHtpasswd }}
138+
subPath: {{ .Values.secrets.existingSecretHtpasswdKey | default "htpasswd" }}
139+
{{- else }}
135140
subPath: htpasswd
141+
{{- end }}
136142
readOnly: true
137143
{{- end }}
138144
- mountPath: /verdaccio/conf
@@ -146,10 +152,14 @@ spec:
146152
- name: config
147153
configMap:
148154
name: {{ .Values.existingConfigMap | default (include "verdaccio.fullname" .) }}
149-
{{- if .Values.secrets.htpasswd }}
155+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
150156
- name: htpasswd
151157
secret:
158+
{{- if .Values.secrets.existingSecretHtpasswd }}
159+
secretName: {{ .Values.secrets.existingSecretHtpasswd }}
160+
{{- else }}
152161
secretName: {{ include "verdaccio.fullname" . }}-htpasswd
162+
{{- end }}
153163
{{- end }}
154164
{{- if .Values.cachingNginx.enabled }}
155165
- name: config-volume

charts/verdaccio/templates/htpasswd-secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.secrets.htpasswd }}
1+
{{- if and .Values.secrets.htpasswd (not .Values.secrets.existingSecretHtpasswd) }}
22
apiVersion: v1
33
kind: Secret
44
type: Opaque

charts/verdaccio/templates/statefulset.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ spec:
2525
metadata:
2626
annotations:
2727
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
28+
{{- if and .Values.secrets.htpasswd (not .Values.secrets.existingSecretHtpasswd) }}
2829
checksum/htpasswd-secret: {{ toJson .Values.secrets.htpasswd | sha256sum }}
30+
{{- end }}
2931
{{- if .Values.secretEnvVars }}
3032
checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
3133
{{- end }}
@@ -122,10 +124,14 @@ spec:
122124
- mountPath: /verdaccio/storage
123125
name: storage
124126
readOnly: false
125-
{{- if .Values.secrets.htpasswd }}
127+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
126128
- mountPath: /verdaccio/storage/htpasswd
127129
name: htpasswd
130+
{{- if .Values.secrets.existingSecretHtpasswd }}
131+
subPath: {{ .Values.secrets.existingSecretHtpasswdKey | default "htpasswd" }}
132+
{{- else }}
128133
subPath: htpasswd
134+
{{- end }}
129135
readOnly: true
130136
{{- end }}
131137
- mountPath: /verdaccio/conf
@@ -139,10 +145,14 @@ spec:
139145
- name: config
140146
configMap:
141147
name: {{ .Values.existingConfigMap | default (include "verdaccio.fullname" .) }}
142-
{{- if .Values.secrets.htpasswd }}
148+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
143149
- name: htpasswd
144150
secret:
151+
{{- if .Values.secrets.existingSecretHtpasswd }}
152+
secretName: {{ .Values.secrets.existingSecretHtpasswd }}
153+
{{- else }}
145154
secretName: {{ include "verdaccio.fullname" . }}-htpasswd
155+
{{- end }}
146156
{{- end }}
147157
{{- if .Values.cachingNginx.enabled }}
148158
- name: config-volume

charts/verdaccio/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ secrets:
264264
# password: "test"
265265
# - username: "blah"
266266
# password: "blah"
267+
# Existing secret containing htpasswd file
268+
# If set, the secret will be used instead of generating one from secrets.htpasswd
269+
# The secret must contain a key with the htpasswd file content (default key: "htpasswd")
270+
existingSecretHtpasswd: ""
271+
# Key in the existing secret that contains the htpasswd file content
272+
existingSecretHtpasswdKey: "htpasswd"
267273

268274
# Annotations to set on the deployment
269275
annotations: {}

0 commit comments

Comments
 (0)