Skip to content

Commit cd6ab34

Browse files
committedNov 17, 2023
Support external secrets for service tokens and xsrf
Signed-off-by: Daren Desjardins <[email protected]>
1 parent 96428e0 commit cd6ab34

8 files changed

+68
-6
lines changed
 

‎README.md

+10
Large diffs are not rendered by default.

‎templates/core/core-dpl.yaml

+13-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ spec:
9292
- name: CORE_SECRET
9393
valueFrom:
9494
secretKeyRef:
95-
name: {{ template "harbor.core" . }}
95+
name: {{ default (include "harbor.core" .) .Values.core.existingSecret }}
9696
key: secret
9797
- name: JOBSERVICE_SECRET
9898
valueFrom:
9999
secretKeyRef:
100-
name: "{{ template "harbor.jobservice" . }}"
100+
name: {{ default (include "harbor.jobservice" .) .Values.jobservice.existingSecret }}
101+
{{- if .Values.jobservice.existingSecret }}
102+
key: {{ .Values.jobservice.existingSecretKey }}
103+
{{- else }}
101104
key: JOBSERVICE_SECRET
105+
{{- end }}
102106
{{- if .Values.existingSecretAdminPassword }}
103107
- name: HARBOR_ADMIN_PASSWORD
104108
valueFrom:
@@ -130,6 +134,13 @@ spec:
130134
name: {{ .Values.registry.credentials.existingSecret }}
131135
key: REGISTRY_PASSWD
132136
{{- end }}
137+
{{- if .Values.core.existingXsrfSecret }}
138+
- name: CSRF_KEY
139+
valueFrom:
140+
secretKeyRef:
141+
name: {{ .Values.core.existingXsrfSecret }}
142+
key: {{ .Values.core.existingXsrfSecretKey }}
143+
{{- end }}
133144
{{- with .Values.core.extraEnvVars }}
134145
{{- toYaml . | nindent 10 }}
135146
{{- end }}

‎templates/core/core-secret.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ data:
99
{{- if not .Values.existingSecretSecretKey }}
1010
secretKey: {{ .Values.secretKey | b64enc | quote }}
1111
{{- end }}
12+
{{- if not .Values.core.existingSecret }}
1213
secret: {{ .Values.core.secret | default (randAlphaNum 16) | b64enc | quote }}
14+
{{- end }}
1315
{{- if not .Values.core.secretName }}
1416
{{- $ca := genCA "harbor-token-ca" 365 }}
1517
tls.key: {{ .Values.core.tokenKey | default $ca.Key | b64enc | quote }}
@@ -24,7 +26,9 @@ data:
2426
{{- if not .Values.registry.credentials.existingSecret }}
2527
REGISTRY_CREDENTIAL_PASSWORD: {{ .Values.registry.credentials.password | b64enc | quote }}
2628
{{- end }}
29+
{{- if not .Values.core.existingXsrfSecret }}
2730
CSRF_KEY: {{ .Values.core.xsrfKey | default (randAlphaNum 32) | b64enc | quote }}
31+
{{- end }}
2832
{{- if .Values.core.configureUserSettings }}
2933
CONFIG_OVERWRITE_JSON: {{ .Values.core.configureUserSettings | b64enc | quote }}
3034
{{- end }}

‎templates/jobservice/jobservice-dpl.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ spec:
8787
- name: CORE_SECRET
8888
valueFrom:
8989
secretKeyRef:
90-
name: {{ template "harbor.core" . }}
90+
name: {{ default (include "harbor.core" .) .Values.core.existingSecret }}
9191
key: secret
92+
{{- if .Values.jobservice.existingSecret }}
93+
- name: JOBSERVICE_SECRET
94+
valueFrom:
95+
secretKeyRef:
96+
name: {{ .Values.jobservice.existingSecret }}
97+
key: {{ .Values.jobservice.existingSecretKey }}
98+
{{- end }}
9299
{{- if .Values.internalTLS.enabled }}
93100
- name: INTERNAL_TLS_ENABLED
94101
value: "true"

‎templates/jobservice/jobservice-secrets.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ metadata:
66
{{ include "harbor.labels" . | indent 4 }}
77
type: Opaque
88
data:
9+
{{- if not .Values.jobservice.existingSecret }}
910
JOBSERVICE_SECRET: {{ .Values.jobservice.secret | default (randAlphaNum 16) | b64enc | quote }}
11+
{{- end }}
1012
{{- if not .Values.registry.credentials.existingSecret }}
1113
REGISTRY_CREDENTIAL_PASSWORD: {{ .Values.registry.credentials.password | b64enc | quote }}
1214
{{- end }}

‎templates/registry/registry-dpl.yaml

+13-2
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,27 @@ spec:
200200
name: {{ .Values.persistence.imageChartStorage.s3.existingSecret }}
201201
{{- end }}
202202
env:
203+
{{- if .Values.registry.existingSecret }}
204+
- name: REGISTRY_HTTP_SECRET
205+
valueFrom:
206+
secretKeyRef:
207+
name: {{ .Values.registry.existingSecret }}
208+
key: {{ .Values.registry.existingSecretKey }}
209+
{{- end }}
203210
- name: CORE_SECRET
204211
valueFrom:
205212
secretKeyRef:
206-
name: {{ template "harbor.core" . }}
213+
name: {{ default (include "harbor.core" .) .Values.core.existingSecret }}
207214
key: secret
208215
- name: JOBSERVICE_SECRET
209216
valueFrom:
210217
secretKeyRef:
211-
name: {{ template "harbor.jobservice" . }}
218+
name: {{ default (include "harbor.jobservice" .) .Values.jobservice.existingSecret }}
219+
{{- if .Values.jobservice.existingSecret }}
220+
key: {{ .Values.jobservice.existingSecretKey }}
221+
{{- else }}
212222
key: JOBSERVICE_SECRET
223+
{{- end }}
213224
{{- if has "registry" .Values.proxy.components }}
214225
- name: HTTP_PROXY
215226
value: "{{ .Values.proxy.httpProxy }}"

‎templates/registry/registry-secret.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ metadata:
66
{{ include "harbor.labels" . | indent 4 }}
77
type: Opaque
88
data:
9+
{{- if not .Values.registry.existingSecret }}
910
REGISTRY_HTTP_SECRET: {{ .Values.registry.secret | default (randAlphaNum 16) | b64enc | quote }}
11+
{{- end }}
1012
{{- if not .Values.redis.external.existingSecret }}
1113
REGISTRY_REDIS_PASSWORD: {{ include "harbor.redis.password" . | b64enc | quote }}
1214
{{- end }}

‎values.yaml

+16-1
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,13 @@ core:
483483
# the scenario of high concurrent pushing to same project, no improvment for other scenes.
484484
quotaUpdateProvider: db # Or redis
485485
# Secret is used when core server communicates with other components.
486-
# If a secret key is not specified, Helm will generate one.
486+
# If a secret key is not specified, Helm will generate one. Alternatively set existingSecret to use an existing secret
487487
# Must be a string of 16 chars.
488488
secret: ""
489489
# Fill in the name of a kubernetes secret if you want to use your own
490+
# If using existingSecret, the key must be secret
491+
existingSecret: ""
492+
# Fill the name of a kubernetes secret if you want to use your own
490493
# TLS certificate and private key for token encryption/decryption.
491494
# The secret must contain keys named:
492495
# "tls.key" - the private key
@@ -501,6 +504,10 @@ core:
501504
tokenCert: |
502505
# The XSRF key. Will be generated automatically if it isn't specified
503506
xsrfKey: ""
507+
# If using existingSecret, the key is defined by core.existingXsrfSecretKey
508+
existingXsrfSecret: ""
509+
# If using existingSecret, the key
510+
existingXsrfSecretKey: CSRF_KEY
504511
## The priority class to run the pod as
505512
priorityClassName:
506513
# The time duration for async update artifact pull_time and repository
@@ -559,6 +566,10 @@ jobservice:
559566
# If a secret key is not specified, Helm will generate one.
560567
# Must be a string of 16 chars.
561568
secret: ""
569+
# Use an existing secret resource
570+
existingSecret: ""
571+
# Key within the existing secret for the job service secret
572+
existingSecretKey: JOBSERVICE_SECRET
562573
## The priority class to run the pod as
563574
priorityClassName:
564575

@@ -609,6 +620,10 @@ registry:
609620
# If a secret key is not specified, Helm will generate one.
610621
# Must be a string of 16 chars.
611622
secret: ""
623+
# Use an existing secret resource
624+
existingSecret: ""
625+
# Key within the existing secret for the registry service secret
626+
existingSecretKey: REGISTRY_HTTP_SECRET
612627
# If true, the registry returns relative URLs in Location headers. The client is responsible for resolving the correct URL.
613628
relativeurls: false
614629
credentials:

0 commit comments

Comments
 (0)
Please sign in to comment.