diff --git a/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 b/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 index a5bdbbe2..775e401a 100644 --- a/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 +++ b/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 @@ -13,7 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial ## The matrix-tools iamge, used in multiple components matrixTools: -{{ image(registry="ghcr.io", repository="element-hq/ess-helm/matrix-tools", tag="0.1.0") | indent(2) }} +{{ image(registry="ghcr.io", repository="element-hq/ess-helm/matrix-tools", tag="0.1.1") | indent(2) }} ## The server name of the Matrix Stack. This gets embedded in user IDs & room IDs ## It can not change after the initial deployment. diff --git a/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml b/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml index 0ed1cba1..77a651eb 100644 --- a/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml @@ -105,13 +105,13 @@ We have an init container to render & merge the config for several reasons: */}} - name: SYNAPSE_MACAROON value: >- - {{ printf "{{ readfile \"/secrets/%s/%s\" }}" (tpl (.macaroon.secret | default (printf "%s-synapse" $.Release.Name)) $) (.macaroon.secretKey | default "MACAROON") }} + {{ printf "{{ readfile \"/secrets/%s/%s\" | quote }}" (tpl (.macaroon.secret | default (printf "%s-synapse" $.Release.Name)) $) (.macaroon.secretKey | default "MACAROON") }} - name: SYNAPSE_POSTGRES_PASSWORD value: >- - {{ printf "{{ readfile \"/secrets/%s/%s\" }}" (tpl (.postgres.password.secret | default (printf "%s-synapse" $.Release.Name)) $) (.postgres.password.secretKey | default "POSTGRES_PASSWORD") }} + {{ printf "{{ readfile \"/secrets/%s/%s\" | quote }}" (tpl (.postgres.password.secret | default (printf "%s-synapse" $.Release.Name)) $) (.postgres.password.secretKey | default "POSTGRES_PASSWORD") }} - name: SYNAPSE_REGISTRATION_SHARED_SECRET value: >- - {{ printf "{{ readfile \"/secrets/%s/%s\" }}" (tpl (.registrationSharedSecret.secret | default (printf "%s-synapse" $.Release.Name)) $) (.registrationSharedSecret.secretKey | default "REGISTRATION_SHARED_SECRET") }} + {{ printf "{{ readfile \"/secrets/%s/%s\" | quote }}" (tpl (.registrationSharedSecret.secret | default (printf "%s-synapse" $.Release.Name)) $) (.registrationSharedSecret.secretKey | default "REGISTRATION_SHARED_SECRET") }} - name: APPLICATION_NAME value: >- {{ printf "{{ hostname | replace \"-synapse-\" \"\" }}" }} diff --git a/charts/matrix-stack/values.yaml b/charts/matrix-stack/values.yaml index 1e6890f7..2f8d5fa9 100644 --- a/charts/matrix-stack/values.yaml +++ b/charts/matrix-stack/values.yaml @@ -20,7 +20,7 @@ matrixTools: ## The tag of the container image to use. ## Defaults to the Chart's appVersion if not set - tag: 0.1.0 + tag: 0.1.1 ## Container digest to use. Used to pull the image instead of the image tag / Chart appVersion if set # digest: diff --git a/matrix-tools/README.md b/matrix-tools/README.md index 61a99810..279877b3 100644 --- a/matrix-tools/README.md +++ b/matrix-tools/README.md @@ -62,6 +62,7 @@ Similarly to `envsubstr`, it supports the use of environment variables in config - `hostname` returns the hostname of the machine. - `readfile` reads a file and returns its content as string. - `replace` replaces occurrences of a substring with another substring in the input string. + - `quote` quotes the input string with double quotes. ### TCP Wait diff --git a/matrix-tools/internal/pkg/renderer/renderer.go b/matrix-tools/internal/pkg/renderer/renderer.go index 31316d19..5dcceb92 100644 --- a/matrix-tools/internal/pkg/renderer/renderer.go +++ b/matrix-tools/internal/pkg/renderer/renderer.go @@ -11,6 +11,7 @@ import ( "io" "os" "regexp" + "strconv" "strings" "text/template" @@ -68,6 +69,10 @@ func replace(old, new, src string) string { return strings.Replace(src, old, new, -1) } +func quote(src string) string { + return strconv.Quote(src) +} + // RenderConfig takes a list of io.Reader objects representing yaml configuration files // and returns a single map[string]any containing the deeply merged data as yaml format // The files are merged in the order they are provided. @@ -91,6 +96,7 @@ func RenderConfig(sourceConfigs []io.Reader) (map[string]any, error) { "readfile": readfile, "hostname": os.Hostname, "replace": replace, + "quote": quote, } envVarNames := extractEnvVarNames(string(fileContent)) diff --git a/matrix-tools/internal/pkg/renderer/renderer_test.go b/matrix-tools/internal/pkg/renderer/renderer_test.go index bc905247..39071b9e 100644 --- a/matrix-tools/internal/pkg/renderer/renderer_test.go +++ b/matrix-tools/internal/pkg/renderer/renderer_test.go @@ -28,18 +28,21 @@ func TestRenderConfig(t *testing.T) { name: "Single File", readers: []io.Reader{ bytes.NewBuffer([]byte(`key: ${TEST_ENV} +quotedValue: ${SPECIAL_CHARS} secretKey: ${SECRET_KEY} hostname: ${THIS_HOSTNAME}`)), }, env: map[string]string{ "TEST_ENV": "value", + "SPECIAL_CHARS": "{{ \"!ayamltype\" | quote }}", "SECRET_KEY": "{{ readfile \"testdata/secret_key\" }}", "THIS_HOSTNAME": fmt.Sprintf("{{ hostname | replace \"%s\" \"\" }}", droppedFromHostname), }, expected: map[string]any{ - "key": "value", - "secretKey": "secret_value", - "hostname": hostname[0:2] + hostname[4:], + "key": "value", + "secretKey": "secret_value", + "quotedValue": "!ayamltype", + "hostname": hostname[0:2] + hostname[4:], }, err: false, }, diff --git a/newsfragments/137.added.md b/newsfragments/137.added.md new file mode 100644 index 00000000..fcdbe5ec --- /dev/null +++ b/newsfragments/137.added.md @@ -0,0 +1 @@ +Add the possibility to quote substituted env variable from synapse config.