Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow username to be specified in persistence secrets #601

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions charts/temporal/templates/_admintools-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
- name: CASSANDRA_KEYSPACE
value: {{ $driverConfig.keyspace }}
- name: CASSANDRA_USER
value: {{ $driverConfig.user }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $global $store) }}
key: {{ include "temporal.persistence.secretKeyUser" (list $global $store) }}
- name: CASSANDRA_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $global $store) }}
key: {{ include "temporal.persistence.secretKey" (list $global $store) }}
key: {{ include "temporal.persistence.secretKeyPassword" (list $global $store) }}
{{- else if eq $driver "sql" -}}
- name: SQL_PLUGIN
value: {{ include "temporal.persistence.sql.driver" (list $global $store) }}
Expand All @@ -31,12 +34,15 @@
- name: SQL_DATABASE
value: {{ include "temporal.persistence.sql.database" (list $global $store) }}
- name: SQL_USER
value: {{ $driverConfig.user }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $global $store) }}
key: {{ include "temporal.persistence.secretKeyUser" (list $global $store) }}
- name: SQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $global $store) }}
key: {{ include "temporal.persistence.secretKey" (list $global $store) }}
key: {{ include "temporal.persistence.secretKeyPassword" (list $global $store) }}
{{- with $driverConfig.tls }}
- name: SQL_TLS
value: {{ .enabled | quote }}
Expand Down Expand Up @@ -67,12 +73,15 @@
- name: ES_PORT
value: {{ $driverConfig.port | quote }}
- name: ES_USER
value: {{ $driverConfig.username | quote }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $global $store) }}
key: {{ include "temporal.persistence.secretKeyUser" (list $global $store) }}
- name: ES_PWD
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $global $store) }}
key: {{ include "temporal.persistence.secretKey" (list $global $store) }}
key: {{ include "temporal.persistence.secretKeyPassword" (list $global $store) }}
- name: ES_VERSION
value: {{ $driverConfig.version }}
- name: ES_VISIBILITY_INDEX
Expand Down
68 changes: 58 additions & 10 deletions charts/temporal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,25 @@ Source: https://stackoverflow.com/a/52024583/3027614
{{- end -}}
{{- end -}}

{{- define "temporal.persistence.cassandra.secretKey" -}}
{{- define "temporal.persistence.cassandra.secretKeyUser" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- $storeConfig := index $global.Values.server.config.persistence $store -}}
{{- $driverConfig := $storeConfig.cassandra -}}
{{- with $driverConfig.secretKey -}}
{{- with $driverConfig.secretKeyUser -}}
{{- print . -}}
{{- else -}}
{{/* Cassandra user is optional, but we will create an empty secret for it */}}
{{- print "user" -}}
{{- end -}}
{{- end -}}

{{- define "temporal.persistence.cassandra.secretKeyPassword" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- $storeConfig := index $global.Values.server.config.persistence $store -}}
{{- $driverConfig := $storeConfig.cassandra -}}
{{- with $driverConfig.secretKeyPassword -}}
{{- print . -}}
{{- else -}}
{{/* Cassandra password is optional, but we will create an empty secret for it */}}
Expand Down Expand Up @@ -342,13 +355,31 @@ Source: https://stackoverflow.com/a/52024583/3027614
{{- end -}}
{{- end -}}

{{- define "temporal.persistence.sql.secretKey" -}}
{{- define "temporal.persistence.sql.secretKeyUser" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- $storeConfig := index $global.Values.server.config.persistence $store -}}
{{- $driverConfig := $storeConfig.sql -}}
{{- if $driverConfig.secretKey -}}
{{- print $driverConfig.secretKey -}}
{{- if $driverConfig.secretKeyUser -}}
{{- print $driverConfig.secretKeyUser -}}
{{- else if or $driverConfig.existingSecret $driverConfig.user -}}
{{- print "username" -}}
{{- else if and $global.Values.mysql.enabled (and (eq (include "temporal.persistence.driver" (list $global $store)) "sql") (eq (include "temporal.persistence.sql.driver" (list $global $store)) "mysql8")) -}}
{{- print "mysql-username" -}}
{{- else if and $global.Values.postgresql.enabled (and (eq (include "temporal.persistence.driver" (list $global $store)) "sql") (eq (include "temporal.persistence.sql.driver" (list $global $store)) "postgres12")) -}}
{{- print "postgresql-username" -}}
{{- else -}}
{{- fail (printf "Please specify sql username or existing secret for %s store" $store) -}}
{{- end -}}
{{- end -}}

{{- define "temporal.persistence.sql.secretKeyPassword" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- $storeConfig := index $global.Values.server.config.persistence $store -}}
{{- $driverConfig := $storeConfig.sql -}}
{{- if $driverConfig.secretKeyPassword -}}
{{- print $driverConfig.secretKeyPassword -}}
{{- else if or $driverConfig.existingSecret $driverConfig.password -}}
{{- print "password" -}}
{{- else if and $global.Values.mysql.enabled (and (eq (include "temporal.persistence.driver" (list $global $store)) "sql") (eq (include "temporal.persistence.sql.driver" (list $global $store)) "mysql8")) -}}
Expand All @@ -373,12 +404,23 @@ Source: https://stackoverflow.com/a/52024583/3027614
{{- end -}}
{{- end -}}

{{- define "temporal.persistence.elasticsearch.secretKey" -}}
{{- define "temporal.persistence.elasticsearch.secretKeyUser" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- $driverConfig := $global.Values.elasticsearch -}}
{{- if $driverConfig.secretKey -}}
{{- print $driverConfig.secretKey -}}
{{- if $driverConfig.secretKeyUser -}}
{{- print $driverConfig.secretKeyUser -}}
{{- else -}}
{{- "password" -}}
{{- end -}}
{{- end -}}

{{- define "temporal.persistence.elasticsearch.secretKeyPassword" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- $driverConfig := $global.Values.elasticsearch -}}
{{- if $driverConfig.secretKeyPassword -}}
{{- print $driverConfig.secretKeyPassword -}}
{{- else -}}
{{- "password" -}}
{{- end -}}
Expand All @@ -390,10 +432,16 @@ Source: https://stackoverflow.com/a/52024583/3027614
{{- include (printf "temporal.persistence.%s.secretName" (include "temporal.persistence.driver" (list $global $store))) (list $global $store) -}}
{{- end -}}

{{- define "temporal.persistence.secretKey" -}}
{{- define "temporal.persistence.secretKeyUser" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- include (printf "temporal.persistence.%s.secretKeyUser" (include "temporal.persistence.driver" (list $global $store))) (list $global $store) -}}
{{- end -}}

{{- define "temporal.persistence.secretKeyPassword" -}}
{{- $global := index . 0 -}}
{{- $store := index . 1 -}}
{{- include (printf "temporal.persistence.%s.secretKey" (include "temporal.persistence.driver" (list $global $store))) (list $global $store) -}}
{{- include (printf "temporal.persistence.%s.secretKeyPassword" (include "temporal.persistence.driver" (list $global $store))) (list $global $store) -}}
{{- end -}}

{{/*
Expand Down
7 changes: 4 additions & 3 deletions charts/temporal/templates/server-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ data:
cassandra:
hosts: "{{ include "temporal.persistence.cassandra.hosts" (list $ "default") }}"
port: {{ include "temporal.persistence.cassandra.port" (list $ "default") }}
user: {{ `{{ .Env.TEMPORAL_STORE_USER | quote }}` }}
password: {{ `{{ .Env.TEMPORAL_STORE_PASSWORD | quote }}` }}
{{- with (omit $server.config.persistence.default.cassandra "hosts" "port" "password" "existingSecret") }}
{{- with (omit $server.config.persistence.default.cassandra "hosts" "port" "user" "password" "existingSecret") }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- else if eq (include "temporal.persistence.driver" (list $ "default")) "sql" }}
Expand All @@ -34,7 +35,7 @@ data:
databaseName: "{{ $server.config.persistence.default.sql.database }}"
connectAddr: "{{ include "temporal.persistence.sql.host" (list $ "default") }}:{{ include "temporal.persistence.sql.port" (list $ "default") }}"
connectProtocol: "tcp"
user: {{ include "temporal.persistence.sql.user" (list $ "default") }}
user: {{ `{{ .Env.TEMPORAL_STORE_USER | quote }}` }}
password: {{ `{{ .Env.TEMPORAL_STORE_PASSWORD | quote }}` }}
{{- with (omit $server.config.persistence.default.sql "driver" "driverName" "host" "port" "connectAddr" "connectProtocol" "database" "databaseName" "user" "password" "existingSecret") }}
{{- toYaml . | nindent 12 }}
Expand Down Expand Up @@ -66,7 +67,7 @@ data:
databaseName: "{{ $server.config.persistence.visibility.sql.database }}"
connectAddr: "{{ include "temporal.persistence.sql.host" (list $ "visibility") }}:{{ include "temporal.persistence.sql.port" (list $ "visibility") }}"
connectProtocol: "tcp"
user: "{{ include "temporal.persistence.sql.user" (list $ "visibility") }}"
user: {{ `{{ .Env.TEMPORAL_VISIBILITY_STORE_USER | quote }}` }}
password: {{ `{{ .Env.TEMPORAL_VISIBILITY_STORE_PASSWORD | quote }}` }}
{{- with (omit $server.config.persistence.visibility.sql "driver" "driverName" "host" "port" "connectAddr" "connectProtocol" "database" "databaseName" "user" "password" "existingSecret") }}
{{- toYaml . | nindent 12 }}
Expand Down
14 changes: 12 additions & 2 deletions charts/temporal/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,26 @@ spec:
fieldPath: status.podIP
- name: SERVICES
value: {{ $service }}
- name: TEMPORAL_STORE_USER
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ "default") }}
key: {{ include "temporal.persistence.secretKeyUser" (list $ "default") }}
- name: TEMPORAL_STORE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ "default") }}
key: {{ include "temporal.persistence.secretKey" (list $ "default") }}
key: {{ include "temporal.persistence.secretKeyPassword" (list $ "default") }}
- name: TEMPORAL_VISIBILITY_STORE_USER
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ "visibility") }}
key: {{ include "temporal.persistence.secretKeyUser" (list $ "visibility") }}
- name: TEMPORAL_VISIBILITY_STORE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ "visibility") }}
key: {{ include "temporal.persistence.secretKey" (list $ "visibility") }}
key: {{ include "temporal.persistence.secretKeyPassword" (list $ "visibility") }}
{{- if $.Values.server.versionCheckDisabled }}
- name: TEMPORAL_VERSION_CHECK_DISABLED
value: "1"
Expand Down
3 changes: 3 additions & 0 deletions charts/temporal/templates/server-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ metadata:
type: Opaque
data:
{{- if eq $driver "cassandra" }}
username: {{ $driverConfig.user | b64enc | quote }}
password: {{ $driverConfig.password | b64enc | quote }}
{{- else if eq $driver "sql" }}
username: {{ include "temporal.persistence.sql.user" (list $ $store) | b64enc | quote }}
password: {{ include "temporal.persistence.sql.password" (list $ $store) | b64enc | quote }}
{{- else if eq $driver "elasticsearch" }}
username: {{ $driverConfig.user | b64enc | quote }}
password: {{ $driverConfig.password | b64enc | quote }}
{{- end }}
---
Expand Down