From c7f398a4c40c3bbd073ece218b1a317fb1f18a66 Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Mon, 24 Mar 2025 14:28:58 +0000 Subject: [PATCH 1/3] Synapse: make it possible to provide additional args to the Synapse process --- charts/matrix-stack/source/synapse.json | 6 ++++++ charts/matrix-stack/source/synapse.yaml.j2 | 3 +++ charts/matrix-stack/templates/synapse/_synapse_pod.tpl | 3 +++ charts/matrix-stack/values.schema.json | 6 ++++++ charts/matrix-stack/values.yaml | 3 +++ newsfragments/309.changed.md | 1 + 6 files changed, 22 insertions(+) create mode 100644 newsfragments/309.changed.md diff --git a/charts/matrix-stack/source/synapse.json b/charts/matrix-stack/source/synapse.json index 73730857..b9f471e7 100644 --- a/charts/matrix-stack/source/synapse.json +++ b/charts/matrix-stack/source/synapse.json @@ -89,6 +89,12 @@ } } }, + "extraArgs": { + "type": "array", + "items": { + "type": "string" + } + }, "ingress": { "$ref": "file://synapse/ingress_with_additional_paths.json" }, diff --git a/charts/matrix-stack/source/synapse.yaml.j2 b/charts/matrix-stack/source/synapse.yaml.j2 index 54a6d124..09a525b8 100644 --- a/charts/matrix-stack/source/synapse.yaml.j2 +++ b/charts/matrix-stack/source/synapse.yaml.j2 @@ -93,6 +93,9 @@ logging: {{- sub_schema_values.tolerations() }} {{- sub_schema_values.topologySpreadConstraints() }} +## Extra command line arguments to provide to Synapse +extraArgs: [] + redis: {{- sub_schema_values.image(registry='docker.io', repository='library/redis', tag='7.4-alpine') | indent(2) }} {{- sub_schema_values.labels() | indent(2) }} diff --git a/charts/matrix-stack/templates/synapse/_synapse_pod.tpl b/charts/matrix-stack/templates/synapse/_synapse_pod.tpl index 696dbcf3..d7b73496 100644 --- a/charts/matrix-stack/templates/synapse/_synapse_pod.tpl +++ b/charts/matrix-stack/templates/synapse/_synapse_pod.tpl @@ -149,6 +149,9 @@ We have an init container to render & merge the config for several reasons: - {{ include "element-io.synapse.process.app" (dict "root" $root "context" $processType) }} - "-c" - /conf/homeserver.yaml +{{- range .extraArgs }} + - {{ . | quote }} +{{- end }} env: {{- include "element-io.synapse.pythonEnv" (dict "root" $root "context" .) | nindent 8 }} {{- include "element-io.synapse.env" (dict "root" $root "context" .) | nindent 8 }} diff --git a/charts/matrix-stack/values.schema.json b/charts/matrix-stack/values.schema.json index 034fea0d..48452c84 100644 --- a/charts/matrix-stack/values.schema.json +++ b/charts/matrix-stack/values.schema.json @@ -2776,6 +2776,12 @@ }, "additionalProperties": false }, + "extraArgs": { + "type": "array", + "items": { + "type": "string" + } + }, "ingress": { "type": "object", "properties": { diff --git a/charts/matrix-stack/values.yaml b/charts/matrix-stack/values.yaml index 337766e9..46d686e2 100644 --- a/charts/matrix-stack/values.yaml +++ b/charts/matrix-stack/values.yaml @@ -1681,6 +1681,9 @@ synapse: ## # whenUnsatisfiable: DoNotSchedule/ScheduleAnyway topologySpreadConstraints: [] + ## Extra command line arguments to provide to Synapse + extraArgs: [] + redis: # Details of the image to be used image: diff --git a/newsfragments/309.changed.md b/newsfragments/309.changed.md new file mode 100644 index 00000000..f30ca305 --- /dev/null +++ b/newsfragments/309.changed.md @@ -0,0 +1 @@ +Make it possible to provide additional command line arguments to Synapse. From d243a2a8b92972a2416c253620c838f21f24feb9 Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Mon, 24 Mar 2025 14:35:25 +0000 Subject: [PATCH 2/3] Run integration tests with Synapse's --no-secrets-in-config set --- .../ci/fragments/synapse-pytest-base-extras.yaml | 6 +++++- .../ci/pytest-matrix-authentication-service-values.yaml | 3 +++ charts/matrix-stack/ci/pytest-synapse-values.yaml | 3 +++ newsfragments/309.internal.md | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 newsfragments/309.internal.md diff --git a/charts/matrix-stack/ci/fragments/synapse-pytest-base-extras.yaml b/charts/matrix-stack/ci/fragments/synapse-pytest-base-extras.yaml index 200e524c..1466d514 100644 --- a/charts/matrix-stack/ci/fragments/synapse-pytest-base-extras.yaml +++ b/charts/matrix-stack/ci/fragments/synapse-pytest-base-extras.yaml @@ -21,10 +21,14 @@ synapse: podSecurityContext: runAsGroup: 0 + extraArgs: + # Validate that any Synapse config that has a _path equivalent uses it + - --no-secrets-in-config + haproxy: podSecurityContext: runAsGroup: 0 postgres: podSecurityContext: - runAsGroup: 0 \ No newline at end of file + runAsGroup: 0 diff --git a/charts/matrix-stack/ci/pytest-matrix-authentication-service-values.yaml b/charts/matrix-stack/ci/pytest-matrix-authentication-service-values.yaml index cc0f38fb..225fc3ed 100644 --- a/charts/matrix-stack/ci/pytest-matrix-authentication-service-values.yaml +++ b/charts/matrix-stack/ci/pytest-matrix-authentication-service-values.yaml @@ -36,6 +36,9 @@ synapse: checkConfigHook: annotations: has-no-service-monitor: "true" + extraArgs: + # Validate that any Synapse config that has a _path equivalent uses it + - --no-secrets-in-config ingress: host: synapse.{{ $.Values.serverName }} tlsSecret: '{{ $.Release.Name }}-synapse-web-tls' diff --git a/charts/matrix-stack/ci/pytest-synapse-values.yaml b/charts/matrix-stack/ci/pytest-synapse-values.yaml index 989373f0..0d054da4 100644 --- a/charts/matrix-stack/ci/pytest-synapse-values.yaml +++ b/charts/matrix-stack/ci/pytest-synapse-values.yaml @@ -33,6 +33,9 @@ synapse: checkConfigHook: annotations: has-no-service-monitor: "true" + extraArgs: + # Validate that any Synapse config that has a _path equivalent uses it + - --no-secrets-in-config extraEnv: - name: DEBUG_RENDERING value: "1" diff --git a/newsfragments/309.internal.md b/newsfragments/309.internal.md new file mode 100644 index 00000000..757fb42d --- /dev/null +++ b/newsfragments/309.internal.md @@ -0,0 +1 @@ +Validate the chart uses path options in Synapse where possible. From 0bde265a29f36a39b33cf4a17a40817dab7411a2 Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Mon, 24 Mar 2025 14:37:05 +0000 Subject: [PATCH 3/3] Synapse: reference MAS shared secrets by path and not via env vars that get rendered --- .../templates/synapse/_helpers.tpl | 32 ------------------- .../templates/synapse/_synapse_config.tpl | 20 ++++++++++-- newsfragments/309.changed.1.md | 1 + 3 files changed, 19 insertions(+), 34 deletions(-) create mode 100644 newsfragments/309.changed.1.md diff --git a/charts/matrix-stack/templates/synapse/_helpers.tpl b/charts/matrix-stack/templates/synapse/_helpers.tpl index 5ec6335e..1868a288 100644 --- a/charts/matrix-stack/templates/synapse/_helpers.tpl +++ b/charts/matrix-stack/templates/synapse/_helpers.tpl @@ -163,38 +163,6 @@ app.kubernetes.io/version: {{ .image.tag }} ) ) }} -{{- if $root.Values.matrixAuthenticationService.enabled }} -- name: MAS_SHARED_SECRET - value: >- - {{ - printf "{{ readfile \"/secrets/%s\" | quote }}" ( - include "element-io.ess-library.init-secret-path" ( - dict "root" $root - "context" (dict - "secretPath" "matrixAuthenticationService.synapseSharedSecret" - "initSecretKey" "MAS_SYNAPSE_SHARED_SECRET" - "defaultSecretName" (printf "%s-matrix-authentication-service" $root.Release.Name) - "defaultSecretKey" "SYNAPSE_SHARED_SECRET" - ) - ) - ) - }} -- name: MAS_OIDC_CLIENT_SECRET - value: >- - {{ - printf "{{ readfile \"/secrets/%s\" | quote }}" ( - include "element-io.ess-library.init-secret-path" ( - dict "root" $root - "context" (dict - "secretPath" "matrixAuthenticationService.synapseOIDCClientSecret" - "initSecretKey" "MAS_SYNAPSE_OIDC_CLIENT_SECRET" - "defaultSecretName" (printf "%s-matrix-authentication-service" $root.Release.Name) - "defaultSecretKey" "SYNAPSE_OIDC_CLIENT_SECRET" - ) - ) - ) - }} -{{- end }} - name: APPLICATION_NAME value: >- {{ printf "{{ hostname | replace \"-synapse-\" \"\" }}" }} diff --git a/charts/matrix-stack/templates/synapse/_synapse_config.tpl b/charts/matrix-stack/templates/synapse/_synapse_config.tpl index 5aa0864e..efff3a0e 100644 --- a/charts/matrix-stack/templates/synapse/_synapse_config.tpl +++ b/charts/matrix-stack/templates/synapse/_synapse_config.tpl @@ -107,9 +107,25 @@ experimental_features: client_id: 0000000000000000000SYNAPSE client_auth_method: client_secret_basic # client. in the MAS secret - client_secret: ${MAS_OIDC_CLIENT_SECRET} + client_secret_path: /secrets/{{ + include "element-io.ess-library.init-secret-path" ( + dict "root" $root "context" (dict + "secretPath" "matrixAuthenticationService.synapseOIDCClientSecret" + "initSecretKey" "MAS_SYNAPSE_OIDC_CLIENT_SECRET" + "defaultSecretName" (printf "%s-matrix-authentication-service" $root.Release.Name) + "defaultSecretKey" "SYNAPSE_OIDC_CLIENT_SECRET" + ) + ) }} # serverSecret in the MAS secret - admin_token: ${MAS_SHARED_SECRET} + admin_token_path: /secrets/{{ + include "element-io.ess-library.init-secret-path" ( + dict "root" $root "context" (dict + "secretPath" "matrixAuthenticationService.synapseSharedSecret" + "initSecretKey" "MAS_SYNAPSE_SHARED_SECRET" + "defaultSecretName" (printf "%s-matrix-authentication-service" $root.Release.Name) + "defaultSecretKey" "SYNAPSE_SHARED_SECRET" + ) + ) }} introspection_endpoint: "http://{{ $root.Release.Name }}-matrix-authentication-service.{{ $root.Release.Namespace }}.svc.cluster.local:8080/oauth2/introspect" # QR Code Login. Requires MAS diff --git a/newsfragments/309.changed.1.md b/newsfragments/309.changed.1.md new file mode 100644 index 00000000..332ce69b --- /dev/null +++ b/newsfragments/309.changed.1.md @@ -0,0 +1 @@ +Have Synapse load Matrix Authentication Service shared secrets from files.