Skip to content

Commit 47c516a

Browse files
author
Andrea Gallicchio
committed
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.
1 parent 39bdb0f commit 47c516a

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

README.md

Lines changed: 34 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,38 @@ 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+
194228
### Custom ConfigMap
195229

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

charts/verdaccio/templates/deployment.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ 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 }}
38+
{{- if .Values.secrets.existingSecretHtpasswd }}
39+
checksum/htpasswd-secret: {{ .Values.secrets.existingSecretHtpasswd }}-{{ .Values.secrets.existingSecretHtpasswdKey | default "htpasswd" }}
40+
{{- end }}
3641
{{- if .Values.secretEnvVars }}
3742
checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
3843
{{- end }}
@@ -129,10 +134,10 @@ spec:
129134
- mountPath: /verdaccio/storage
130135
name: storage
131136
readOnly: false
132-
{{- if .Values.secrets.htpasswd }}
137+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
133138
- mountPath: /verdaccio/storage/htpasswd
134139
name: htpasswd
135-
subPath: htpasswd
140+
subPath: {{ if .Values.secrets.existingSecretHtpasswd }}{{ .Values.secrets.existingSecretHtpasswdKey | default "htpasswd" }}{{ else }}htpasswd{{ end }}
136141
readOnly: true
137142
{{- end }}
138143
- mountPath: /verdaccio/conf
@@ -146,10 +151,10 @@ spec:
146151
- name: config
147152
configMap:
148153
name: {{ .Values.existingConfigMap | default (include "verdaccio.fullname" .) }}
149-
{{- if .Values.secrets.htpasswd }}
154+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
150155
- name: htpasswd
151156
secret:
152-
secretName: {{ include "verdaccio.fullname" . }}-htpasswd
157+
secretName: {{ if .Values.secrets.existingSecretHtpasswd }}{{ .Values.secrets.existingSecretHtpasswd }}{{ else }}{{ include "verdaccio.fullname" . }}-htpasswd{{ end }}
153158
{{- end }}
154159
{{- if .Values.cachingNginx.enabled }}
155160
- 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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ 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 }}
31+
{{- if .Values.secrets.existingSecretHtpasswd }}
32+
checksum/htpasswd-secret: {{ .Values.secrets.existingSecretHtpasswd }}-{{ .Values.secrets.existingSecretHtpasswdKey | default "htpasswd" }}
33+
{{- end }}
2934
{{- if .Values.secretEnvVars }}
3035
checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
3136
{{- end }}
@@ -122,10 +127,10 @@ spec:
122127
- mountPath: /verdaccio/storage
123128
name: storage
124129
readOnly: false
125-
{{- if .Values.secrets.htpasswd }}
130+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
126131
- mountPath: /verdaccio/storage/htpasswd
127132
name: htpasswd
128-
subPath: htpasswd
133+
subPath: {{ if .Values.secrets.existingSecretHtpasswd }}{{ .Values.secrets.existingSecretHtpasswdKey | default "htpasswd" }}{{ else }}htpasswd{{ end }}
129134
readOnly: true
130135
{{- end }}
131136
- mountPath: /verdaccio/conf
@@ -139,10 +144,10 @@ spec:
139144
- name: config
140145
configMap:
141146
name: {{ .Values.existingConfigMap | default (include "verdaccio.fullname" .) }}
142-
{{- if .Values.secrets.htpasswd }}
147+
{{- if or .Values.secrets.htpasswd .Values.secrets.existingSecretHtpasswd }}
143148
- name: htpasswd
144149
secret:
145-
secretName: {{ include "verdaccio.fullname" . }}-htpasswd
150+
secretName: {{ if .Values.secrets.existingSecretHtpasswd }}{{ .Values.secrets.existingSecretHtpasswd }}{{ else }}{{ include "verdaccio.fullname" . }}-htpasswd{{ end }}
146151
{{- end }}
147152
{{- if .Values.cachingNginx.enabled }}
148153
- 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)