From 0ceeaa02ca99e09cab80e12647ef2ae0e933d9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Goinvic?= Date: Fri, 12 Sep 2025 12:32:18 +0200 Subject: [PATCH] matrix-rtc: add option to simplify networking configuration --- .../ci/fragments/matrix-rtc-manual-ip.yaml | 7 ++++ .../ci/fragments/matrix-rtc-no-stun.yaml | 7 ++++ .../matrix-rtc-no-stun-manual-ip-values.yaml | 32 +++++++++++++++ ...atrix-rtc-no-stun-no-manual-ip-values.yaml | 32 +++++++++++++++ .../matrix-rtc/sfu/config-overrides.yaml.tpl | 10 +++++ .../matrix-rtc/sfu/config-underrides.yaml.tpl | 3 -- charts/matrix-stack/source/matrix-rtc.json | 6 +++ charts/matrix-stack/source/matrix-rtc.yaml.j2 | 6 +++ .../templates/matrix-rtc/_sfu_helpers.tpl | 10 +++++ charts/matrix-stack/values.schema.json | 6 +++ charts/matrix-stack/values.yaml | 6 +++ docs/advanced.md | 41 +++++++++++++++++-- newsfragments/733.added.md | 1 + tests/manifests/test_matrix_rtc.py | 18 -------- tests/manifests/test_pod_env.py | 4 ++ 15 files changed, 165 insertions(+), 24 deletions(-) create mode 100644 charts/matrix-stack/ci/fragments/matrix-rtc-manual-ip.yaml create mode 100644 charts/matrix-stack/ci/fragments/matrix-rtc-no-stun.yaml create mode 100644 charts/matrix-stack/ci/matrix-rtc-no-stun-manual-ip-values.yaml create mode 100644 charts/matrix-stack/ci/matrix-rtc-no-stun-no-manual-ip-values.yaml create mode 100644 newsfragments/733.added.md diff --git a/charts/matrix-stack/ci/fragments/matrix-rtc-manual-ip.yaml b/charts/matrix-stack/ci/fragments/matrix-rtc-manual-ip.yaml new file mode 100644 index 00000000..3a682ed7 --- /dev/null +++ b/charts/matrix-stack/ci/fragments/matrix-rtc-manual-ip.yaml @@ -0,0 +1,7 @@ +# Copyright 2025 New Vector Ltd +# +# SPDX-License-Identifier: AGPL-3.0-only + +matrixRTC: + sfu: + manualIP: 198.51.100.2 diff --git a/charts/matrix-stack/ci/fragments/matrix-rtc-no-stun.yaml b/charts/matrix-stack/ci/fragments/matrix-rtc-no-stun.yaml new file mode 100644 index 00000000..b6e76703 --- /dev/null +++ b/charts/matrix-stack/ci/fragments/matrix-rtc-no-stun.yaml @@ -0,0 +1,7 @@ +# Copyright 2025 New Vector Ltd +# +# SPDX-License-Identifier: AGPL-3.0-only + +matrixRTC: + sfu: + useStunToDiscoverPublicIP: false \ No newline at end of file diff --git a/charts/matrix-stack/ci/matrix-rtc-no-stun-manual-ip-values.yaml b/charts/matrix-stack/ci/matrix-rtc-no-stun-manual-ip-values.yaml new file mode 100644 index 00000000..317c351e --- /dev/null +++ b/charts/matrix-stack/ci/matrix-rtc-no-stun-manual-ip-values.yaml @@ -0,0 +1,32 @@ +# Copyright 2024-2025 New Vector Ltd +# +# SPDX-License-Identifier: AGPL-3.0-only +# +# source_fragments: matrix-rtc-host-mode.yaml matrix-rtc-manual-ip.yaml matrix-rtc-minimal.yaml +# DO NOT EDIT DIRECTLY. Edit the fragment files to add / modify / remove values + +# initSecrets, postgres don't have any required properties to be set and defaults to enabled +deploymentMarkers: + enabled: false +elementWeb: + enabled: false +matrixAuthenticationService: + enabled: false +matrixRTC: + ingress: + host: mrtc.ess.localhost + sfu: + exposedServices: + rtcMuxedUdp: + portType: HostPort + rtcTcp: + portType: HostPort + rtcUdp: + enabled: true + portType: HostPort + hostNetwork: true + manualIP: 198.51.100.2 +synapse: + enabled: false +wellKnownDelegation: + enabled: false diff --git a/charts/matrix-stack/ci/matrix-rtc-no-stun-no-manual-ip-values.yaml b/charts/matrix-stack/ci/matrix-rtc-no-stun-no-manual-ip-values.yaml new file mode 100644 index 00000000..e563c177 --- /dev/null +++ b/charts/matrix-stack/ci/matrix-rtc-no-stun-no-manual-ip-values.yaml @@ -0,0 +1,32 @@ +# Copyright 2024-2025 New Vector Ltd +# +# SPDX-License-Identifier: AGPL-3.0-only +# +# source_fragments: matrix-rtc-host-mode.yaml matrix-rtc-minimal.yaml matrix-rtc-no-stun.yaml +# DO NOT EDIT DIRECTLY. Edit the fragment files to add / modify / remove values + +# initSecrets, postgres don't have any required properties to be set and defaults to enabled +deploymentMarkers: + enabled: false +elementWeb: + enabled: false +matrixAuthenticationService: + enabled: false +matrixRTC: + ingress: + host: mrtc.ess.localhost + sfu: + exposedServices: + rtcMuxedUdp: + portType: HostPort + rtcTcp: + portType: HostPort + rtcUdp: + enabled: true + portType: HostPort + hostNetwork: true + useStunToDiscoverPublicIP: false +synapse: + enabled: false +wellKnownDelegation: + enabled: false diff --git a/charts/matrix-stack/configs/matrix-rtc/sfu/config-overrides.yaml.tpl b/charts/matrix-stack/configs/matrix-rtc/sfu/config-overrides.yaml.tpl index 92afa508..738861d5 100644 --- a/charts/matrix-stack/configs/matrix-rtc/sfu/config-overrides.yaml.tpl +++ b/charts/matrix-stack/configs/matrix-rtc/sfu/config-overrides.yaml.tpl @@ -23,6 +23,16 @@ logging: # WebRTC configuration rtc: + use_external_ip: {{ .useStunToDiscoverPublicIP }} +{{- if .manualIP }} + # To workaround https://github.com/livekit/livekit/issues/2088 + # Any IP address is acceptable, it doesn't need to be a correct one, + # it just needs to be present to get LiveKit to skip checking all local interfaces + # We assign here a TEST-NET IP which is + # overridden by the NODE_IP env var at runtime + node_ip: 198.51.100.1 +{{- end }} + {{- with .exposedServices }} {{- with .rtcTcp }} {{- if .enabled }} diff --git a/charts/matrix-stack/configs/matrix-rtc/sfu/config-underrides.yaml.tpl b/charts/matrix-stack/configs/matrix-rtc/sfu/config-underrides.yaml.tpl index 4492b95d..57299bd3 100644 --- a/charts/matrix-stack/configs/matrix-rtc/sfu/config-underrides.yaml.tpl +++ b/charts/matrix-stack/configs/matrix-rtc/sfu/config-underrides.yaml.tpl @@ -7,9 +7,6 @@ SPDX-License-Identifier: AGPL-3.0-only {{- $root := .root -}} {{- with required "matrix-rtc/sfu/config.yaml.tpl missing context" .context -}} -rtc: - use_external_ip: true - # turn server turn: enabled: false diff --git a/charts/matrix-stack/source/matrix-rtc.json b/charts/matrix-stack/source/matrix-rtc.json index 85779fcd..a35061b5 100644 --- a/charts/matrix-stack/source/matrix-rtc.json +++ b/charts/matrix-stack/source/matrix-rtc.json @@ -122,6 +122,12 @@ "hostNetwork": { "type": "boolean" }, + "useStunToDiscoverPublicIP": { + "type": "boolean" + }, + "manualIP": { + "type": "string" + }, "additional": { "$ref": "file://common/additional.json" }, diff --git a/charts/matrix-stack/source/matrix-rtc.yaml.j2 b/charts/matrix-stack/source/matrix-rtc.yaml.j2 index 3a8b7019..a8a41bb5 100644 --- a/charts/matrix-stack/source/matrix-rtc.yaml.j2 +++ b/charts/matrix-stack/source/matrix-rtc.yaml.j2 @@ -43,6 +43,12 @@ replicas: 1 sfu: enabled: true + # Use STUN to resolve the server public IP + useStunToDiscoverPublicIP: true + + # Specify a manual IP address for the server public IP + manualIP: "" + # LiveKit Logging level logging: # log level, valid values: debug, info, warn, error diff --git a/charts/matrix-stack/templates/matrix-rtc/_sfu_helpers.tpl b/charts/matrix-stack/templates/matrix-rtc/_sfu_helpers.tpl index c2127876..21ab23b0 100644 --- a/charts/matrix-stack/templates/matrix-rtc/_sfu_helpers.tpl +++ b/charts/matrix-stack/templates/matrix-rtc/_sfu_helpers.tpl @@ -34,6 +34,16 @@ env: [] {{- $root := .root -}} {{- with required "element-io.matrix-rtc-sfu.renderConfigOverrideEnv missing context" .context -}} env: +{{- with .manualIP }} +- name: NODE_IP + value: "{{ . }}" +{{- end }} +{{- if and (not .useStunToDiscoverPublicIP) (not .manualIP) }} +- name: NODE_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP +{{- end }} - name: "LIVEKIT_KEY" value: "{{ (.livekitAuth).key | default "matrix-rtc" }}" - name: LIVEKIT_SECRET diff --git a/charts/matrix-stack/values.schema.json b/charts/matrix-stack/values.schema.json index 1ef34bf4..a36b0bfe 100644 --- a/charts/matrix-stack/values.schema.json +++ b/charts/matrix-stack/values.schema.json @@ -1615,6 +1615,12 @@ "hostNetwork": { "type": "boolean" }, + "useStunToDiscoverPublicIP": { + "type": "boolean" + }, + "manualIP": { + "type": "string" + }, "additional": { "type": "object", "additionalProperties": { diff --git a/charts/matrix-stack/values.yaml b/charts/matrix-stack/values.yaml index 1270b033..79e43bf6 100644 --- a/charts/matrix-stack/values.yaml +++ b/charts/matrix-stack/values.yaml @@ -644,6 +644,12 @@ matrixRTC: sfu: enabled: true + # Use STUN to resolve the server public IP + useStunToDiscoverPublicIP: true + + # Specify a manual IP address for the server public IP + manualIP: "" + # LiveKit Logging level logging: # log level, valid values: debug, info, warn, error diff --git a/docs/advanced.md b/docs/advanced.md index 16c51e6e..4f27385d 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -87,7 +87,7 @@ Element Web configuration is written in JSON. The documentation can be found in To configure Element Web, create a values file with the JSON config to inject as a string under “additional”: -``` +```yml elementWeb: additional: user-config.json: | @@ -100,7 +100,7 @@ elementWeb: Synapse configuration is written in YAML. The documentation can be found [here](https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html). -``` +```yml synapse: additional: user-config.yaml: @@ -113,7 +113,7 @@ synapse: Matrix Authentication Service configuration is written in YAML. The documentation can be found [here](https://element-hq.github.io/matrix-authentication-service/reference/configuration.html). -``` +```yml matrixAuthenticationService: additional: user-config.yaml: @@ -121,3 +121,38 @@ matrixAuthenticationService: # Add your settings below, taking care of the spacing indentation some: settings ``` + +### Configuring Matrix RTC + +Matrix RTC SFU configuration is written in YAML. The documentation can be found [here](https://docs.livekit.io/home/self-hosting/deployment/). + +```yml +matrixRTC: + sfu: + additional: + user-config.yaml: + config: | + # Add your settings below, taking care of the spacing indentation + some: settings +``` + +#### Networking + +Matrix RTC SFU will by default advertise the IP resolved after a STUN Request to the Google STUN Servers. + +If you want to disable this behaviour, set `useStunToDiscoverPublicIP` to `false` : + +```yml +matrixRTC: + sfu: + useStunToDiscoverPublicIP: false +``` + +Without STUN, Matrix RTC will advertise the Host IP as the publicly reachable IP. If your host is behind NAT, +you can configured a manual IP address for the server public IP by setting `manualIP`: + +```yml +matrixRTC: + sfu: + manualIP: "" +``` diff --git a/newsfragments/733.added.md b/newsfragments/733.added.md new file mode 100644 index 00000000..dc86ccf5 --- /dev/null +++ b/newsfragments/733.added.md @@ -0,0 +1 @@ +MatrixRTC: Add `sfu.useStunToDiscoverPublicIP` and `sfu.manualIP` values to simplify networking configuration. diff --git a/tests/manifests/test_matrix_rtc.py b/tests/manifests/test_matrix_rtc.py index e082fec5..aa340221 100644 --- a/tests/manifests/test_matrix_rtc.py +++ b/tests/manifests/test_matrix_rtc.py @@ -25,24 +25,6 @@ async def test_log_level_overrides(values, make_templates): raise RuntimeError("Could not find config-overrides.yaml") -@pytest.mark.parametrize("values_file", ["matrix-rtc-minimal-values.yaml"]) -@pytest.mark.asyncio_cooperative -async def test_external_ip_underrides(values, make_templates): - for template in await make_templates(values): - if ( - template["kind"] == "ConfigMap" - and "matrix-rtc-sfu" in template["metadata"]["name"] - and "config-underrides.yaml" in template["data"] - ): - log_yaml = yaml.safe_load(template["data"]["config-underrides.yaml"]) - use_external_ip = log_yaml["rtc"]["use_external_ip"] - assert type(use_external_ip) is bool - assert use_external_ip - break - else: - raise RuntimeError("Could not find config-underrides.yaml") - - async def get_sfu_udp_port_range_services(start_port, end_point, values, make_templates): values["matrixRTC"]["sfu"]["exposedServices"]["rtcUdp"]["portRange"]["startPort"] = start_port values["matrixRTC"]["sfu"]["exposedServices"]["rtcUdp"]["portRange"]["endPort"] = end_point diff --git a/tests/manifests/test_pod_env.py b/tests/manifests/test_pod_env.py index 2f510a4d..7c4d4ea9 100644 --- a/tests/manifests/test_pod_env.py +++ b/tests/manifests/test_pod_env.py @@ -37,6 +37,8 @@ async def test_sets_extra_env(values, make_templates): ) for env in container.get("env", []): + if "valueFrom" in env: + continue assert type(env["value"]) is str, ( f"{template_id(template)} has container {container['name']} " f"which has an non-string value: {env}" @@ -96,6 +98,8 @@ async def test_built_in_env_cant_be_overwritten(values, make_templates): # containers each setting different env vars. We'll have provided a 'from-user' env var override # for all of those env vars and so 'from-user' will legitimately be present on some containers if env_var["name"] in env_keys_from_chart: + if "valueFrom" in env_var: + continue assert env_var["value"] != "from-user", ( f"{template_id(template)}/{container['name']} allowed env var " f"{env_var['name']} to be overwritten"