Merge pull request #1385 from element-hq/gaelg/well-known-mas

Well Known: Import MAS ingress from client properties
This commit is contained in:
Gaël Goinvic authored and GitHub committed 2026-06-09 13:44:02 +02:00
commit e6ffb57719
8 files changed
+35 -14

No files matched your search

@@ -0,0 +1 @@
Automatically prune empty configuration if they were extracted from `additional` sections to high-level values.
@@ -0,0 +1 @@
Import Matrix Authentication Service ingress from Well-Known Delegation client configuration.
@@ -91,7 +91,7 @@ def additional_config_transformer(
# Sort tracked values so list indices are removed in descending order to avoid shifting
sorted_tracked = sort_tracked_values_for_filtering(tracked_source_paths)
for source_path in sorted_tracked:
remove_nested_value(filtered_config, source_path)
remove_nested_value(filtered_config, source_path, remove_empty_parent=True)
# Note: This runs after filtering so we check the remaining config
# Store warnings for future engine logging
@@ -332,7 +332,7 @@ def get_nested_value(config: dict[str, Any], path: str) -> Any:
return current
def remove_nested_value(config: dict[str, Any], path: str) -> None:
def remove_nested_value(config: dict[str, Any], path: str, remove_empty_parent: bool = False) -> None:
"""
Remove a config value by its dot-separated path.
Supports single-quoted keys containing dots (e.g., "a.'my.key'.b").
@@ -380,6 +380,10 @@ def remove_nested_value(config: dict[str, Any], path: str) -> None:
except ValueError:
pass
if remove_empty_parent and not current:
formatted_parts = [f"'{part}'" if "." in part else part for part in parts[:-1]]
remove_nested_value(config, ".".join(formatted_parts), remove_empty_parent)
def extract_hostname_from_url(_, url: str, **kwargs: Any) -> str:
"""
@@ -82,6 +82,19 @@ class WellKnownMigration(MigrationStrategy):
transformer=extract_hostname_from_url,
required=False,
),
# Extract org.matrix.msc2965.authentication and map to matrixAuthenticationService.ingress.host
TransformationSpec(
src_key="'org.matrix.msc2965.authentication'.issuer",
target_key="matrixAuthenticationService.ingress.host",
transformer=extract_hostname_from_url,
required=False,
),
TransformationSpec(
src_key="'org.matrix.msc2965.authentication'.account",
target_key="matrixAuthenticationService.ingress.host",
transformer=extract_hostname_from_url,
required=False,
),
]
)
@@ -529,6 +529,10 @@ def basic_well_known_client_config():
"base_url": "https://matrix.example.com",
"server_name": "test.example.com",
},
"org.matrix.msc2965.authentication": {
"account": "https://auth.example.com/account",
"issuer": "https://auth.example.com/",
},
# Add an untracked value to ensure the client entry is created
"m.custom": {"setting": "value"},
}
@@ -4,6 +4,8 @@
"""Tests for Element Web migration."""
import json
from ess_migration_tool.element_web import ElementWebMigration
from ess_migration_tool.models import GlobalOptions
@@ -20,13 +22,11 @@ def test_element_web_additional_config_excludes_default_server_config(config_val
transformer.transform_from_config(config, migration.transformations)
import json
# Element Web's additional config uses direct string format: {"filename": string} (not wrapped in {"config": ...})
additional_config_str = transformer.ess_config["elementWeb"]["additional"]["00-imported.json"]
additional_config = json.loads(additional_config_str)
# Verify that m.homeserver is empty (values extracted)
assert additional_config["default_server_config"]["m.homeserver"] == {}
assert "default_server_config" not in additional_config
assert "customTheme" in additional_config["setting_defaults"]
# Verify that synapse.ingress.host was set from the base_url
assert transformer.ess_config["synapse"]["ingress"]["host"] == "matrix.example.com"
@@ -409,7 +409,7 @@ def test_main_e2e_synapse_with_mas(
else:
pytest.fail(f"Unexpected secret file: {secret_file.name}")
mas_additional_config = yaml.safe_load(mas_config["additional"]["00-imported.yaml"]["config"])
assert "keys_dir" not in mas_additional_config["secrets"]
assert "secrets" not in mas_additional_config
def test_main_e2e_mas_with_custom_listeners_and_ess_managed_database(
@@ -994,10 +994,6 @@ def test_main_e2e_synapse_with_element_web(
"Expected underride warnings section for Element Web defaults"
)
assert "These settings have ESS defaults that your values will override" in log_output
# default_server_config is in underride_configs and should trigger a warning
assert "'default_server_config' found in elementWeb.additional" in log_output, (
"Expected underride warning for default_server_config"
)
assert "ESS default, your value overrides it" in log_output
# Verify that elementWeb.ingress.host was set from Synapse's web_client_location
@@ -1027,6 +1023,7 @@ def test_well_known_migration(
tmp_path,
monkeypatch,
synapse_config_with_signing_key,
basic_mas_config_with_keys,
write_config,
basic_well_known_client_config,
basic_well_known_server_config,
@@ -1041,6 +1038,7 @@ def test_well_known_migration(
basic_well_known_server_config,
basic_well_known_support_config,
)
mas_config_file = write_config(basic_mas_config_with_keys, "mas.yaml", "yaml")
# Run migration
output_dir = tmp_path / "output"
@@ -1064,6 +1062,8 @@ def test_well_known_migration(
str(synapse_file),
"--well-known-dir",
str(tmp_path),
"--mas-config",
str(mas_config_file),
"--output-dir",
str(output_dir),
"--database-mode",
@@ -1088,10 +1088,8 @@ def test_well_known_migration(
# Verify that transformed values are filtered out from additional config
client_config = json.loads(values["wellKnownDelegation"]["additional"]["client"])
# m.homeserver.base_url and m.homeserver.server_name should be filtered out
assert "m.homeserver" not in client_config or (
"base_url" not in client_config.get("m.homeserver", {})
and "server_name" not in client_config.get("m.homeserver", {})
)
assert "m.homeserver" not in client_config
assert "org.matrix.msc2965.authentication" not in client_config
server_config = json.loads(values["wellKnownDelegation"]["additional"]["server"])
assert "m.server" not in server_config