mirror of
https://github.com/element-hq/ess-helm.git
synced 2026-11-29 13:22:58 -08:00
migration: Add support for MAS config
This commit is contained in:
6 files changed
+156
-13
No files matched your search
@@ -95,6 +95,12 @@ Examples:
|
||||
),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--mas-config",
|
||||
required=False,
|
||||
help=("Path to Matrix Authentication Service config.yaml configuration file. "),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--output-dir",
|
||||
default="output",
|
||||
@@ -165,6 +171,12 @@ Examples:
|
||||
config_path=args.synapse_config,
|
||||
)
|
||||
|
||||
if args.mas_config:
|
||||
input_processor.load_migration_input(
|
||||
name="matrixAuthenticationService",
|
||||
config_path=args.mas_config,
|
||||
)
|
||||
|
||||
# Run migration
|
||||
reporter.report_step(MIGRATING_STEP)
|
||||
engine = MigrationEngine(input_processor=input_processor, pretty_logger=pretty_logger)
|
||||
|
||||
+13
-11
@@ -40,18 +40,20 @@ class MigrationEngine:
|
||||
(SynapseMigration(), SynapseSecretDiscovery(), SynapseExtraFileDiscovery()),
|
||||
(MASMigration(), MASSecretDiscovery(), MASExtraFileDiscovery()),
|
||||
]:
|
||||
self.migrators.append(
|
||||
MigrationService(
|
||||
input=self.input_processor.input_for_component(migration.component_root_key),
|
||||
ess_config=self.ess_config,
|
||||
pretty_logger=self.pretty_logger,
|
||||
migration=migration,
|
||||
configmaps=self.configmaps,
|
||||
secrets=self.secrets,
|
||||
secret_discovery_strategy=secret_discovery_strategy,
|
||||
extra_files_strategy=extra_file_strategy,
|
||||
migration_input = self.input_processor.input_for_component(migration.component_root_key)
|
||||
if migration_input:
|
||||
self.migrators.append(
|
||||
MigrationService(
|
||||
input=migration_input,
|
||||
ess_config=self.ess_config,
|
||||
pretty_logger=self.pretty_logger,
|
||||
migration=migration,
|
||||
secrets=self.secrets,
|
||||
secret_discovery_strategy=secret_discovery_strategy,
|
||||
configmaps=self.configmaps,
|
||||
extra_files_strategy=extra_file_strategy,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def run_migration(self) -> dict[str, Any]:
|
||||
"""
|
||||
|
||||
@@ -32,14 +32,14 @@ class InputProcessor:
|
||||
|
||||
inputs: list[MigrationInput] = field(default_factory=list)
|
||||
|
||||
def input_for_component(self, component_root_key: str) -> MigrationInput:
|
||||
def input_for_component(self, component_root_key: str) -> MigrationInput | None:
|
||||
"""
|
||||
Return the migration input for a component.
|
||||
"""
|
||||
for _input in self.inputs:
|
||||
if _input.name == component_root_key:
|
||||
return _input
|
||||
raise MigrationError(f"Component {component_root_key} does not have an migration input service")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def load_yaml_file(path: str) -> dict[str, Any]:
|
||||
|
||||
@@ -105,3 +105,33 @@ def synapse_config_with_ca_federation_list(tmp_path, basic_synapse_config):
|
||||
]
|
||||
|
||||
return config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def basic_mas_config():
|
||||
"""Basic MAS configuration for testing."""
|
||||
return {
|
||||
"http": {"public_base": "https://auth.example.com", "bind": {"address": "0.0.0.0", "port": 8080}},
|
||||
"database": {"uri": "postgresql://mas:mas_password@postgres:5432/mas?sslmode=prefer"},
|
||||
"secrets": {
|
||||
"encryption": "my_encryption_key",
|
||||
},
|
||||
"matrix": {
|
||||
"homeserver": "test.example.com",
|
||||
"secret": "synapse_shared_secret_abcdef",
|
||||
"endpoint": "http://synapse:8008",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def write_mas_config(tmp_path):
|
||||
"""Helper fixture to write a MAS config file."""
|
||||
|
||||
def _write_config(config_data):
|
||||
mas_config_file = tmp_path / "mas.yaml"
|
||||
with open(mas_config_file, "w") as f:
|
||||
yaml.dump(config_data, f)
|
||||
return mas_config_file
|
||||
|
||||
return _write_config
|
||||
@@ -154,3 +154,77 @@ def test_main_e2e_synapse_only(
|
||||
"/etc/synapse/extra/ca-second.pem",
|
||||
"/etc/synapse/extra/another-ca.pem",
|
||||
]
|
||||
|
||||
|
||||
def test_main_e2e_synapse_with_mas(
|
||||
tmp_path, synapse_config_with_signing_key, basic_mas_config, write_synapse_config, write_mas_config
|
||||
):
|
||||
"""Test the complete end-to-end migration workflow with Synapse and MAS."""
|
||||
# Write configuration files
|
||||
synapse_config_file = write_synapse_config(synapse_config_with_signing_key)
|
||||
mas_config_file = write_mas_config(basic_mas_config)
|
||||
|
||||
# Create output directory
|
||||
output_dir = tmp_path / "output"
|
||||
output_dir.mkdir()
|
||||
|
||||
# Mock sys.argv to simulate CLI arguments
|
||||
test_args = [
|
||||
"migration",
|
||||
"--synapse-config",
|
||||
str(synapse_config_file),
|
||||
"--mas-config",
|
||||
str(mas_config_file),
|
||||
"--output-dir",
|
||||
str(output_dir),
|
||||
]
|
||||
|
||||
# Run the main function with mocked sys.argv
|
||||
with patch.object(sys, "argv", test_args):
|
||||
exit_code = __main__.main()
|
||||
|
||||
# Verify successful execution
|
||||
assert exit_code == 0
|
||||
|
||||
# Check that output files were created
|
||||
values_file = output_dir / "values.yaml"
|
||||
assert values_file.exists(), "values.yaml should be created"
|
||||
|
||||
# Load and verify the generated values
|
||||
with open(values_file) as f:
|
||||
generated_values = yaml.safe_load(f)
|
||||
|
||||
# Verify Synapse configuration was migrated
|
||||
assert "synapse" in generated_values
|
||||
synapse_config = generated_values["synapse"]
|
||||
assert synapse_config["enabled"] is True
|
||||
|
||||
# Verify MAS configuration was migrated
|
||||
assert "matrixAuthenticationService" in generated_values
|
||||
mas_config = generated_values["matrixAuthenticationService"]
|
||||
assert mas_config["enabled"] is True
|
||||
|
||||
# Verify MAS secrets were handled (using credential schema)
|
||||
assert "synapseSharedSecret" in mas_config
|
||||
|
||||
# Verify synapseSharedSecret uses credential schema
|
||||
synapse_shared_secret_config = mas_config["synapseSharedSecret"]
|
||||
assert "secret" in synapse_shared_secret_config
|
||||
assert synapse_shared_secret_config["secret"] == "imported-matrix-authentication-service"
|
||||
assert "secretKey" in synapse_shared_secret_config
|
||||
assert synapse_shared_secret_config["secretKey"] == "matrixAuthenticationService.synapseSharedSecret"
|
||||
|
||||
# Check for Secret files (should be created for both Synapse and MAS secrets)
|
||||
secret_files = list(output_dir.glob("*secret.yaml"))
|
||||
# Should have at least two secret files (one for Synapse, one for MAS)
|
||||
assert len(secret_files) >= 2, "Secret files should be created for both Synapse and MAS secrets"
|
||||
|
||||
# Verify the secret file content
|
||||
for secret_file in secret_files:
|
||||
with open(secret_file) as f:
|
||||
secret_content = yaml.safe_load(f)
|
||||
assert secret_content["apiVersion"] == "v1"
|
||||
assert secret_content["kind"] == "Secret"
|
||||
assert "metadata" in secret_content
|
||||
assert "name" in secret_content["metadata"]
|
||||
assert "data" in secret_content
|
||||
@@ -0,0 +1,25 @@
|
||||
# Copyright 2026 Element Creations Ltd
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import logging
|
||||
|
||||
from scripts.migration.secrets import SecretDiscovery
|
||||
|
||||
from ..mas import MASSecretDiscovery
|
||||
|
||||
|
||||
def test_discover_secrets_from_mas_config(basic_mas_config):
|
||||
"""Test MAS config with PostgreSQL database URI using transformer."""
|
||||
mas_config = basic_mas_config.copy()
|
||||
# The basic_mas_config already has database.uri with password
|
||||
|
||||
mas_secrets = MASSecretDiscovery()
|
||||
discovery = SecretDiscovery(mas_secrets, logging.getLogger(), "mas.yaml")
|
||||
discovery.discover_secrets(mas_config)
|
||||
|
||||
# Should have discovered the password from database URI using transformer
|
||||
assert "matrixAuthenticationService.postgres.password" in discovery.discovered_secrets
|
||||
assert discovery.discovered_secrets["matrixAuthenticationService.postgres.password"].value == "mas_password"
|
||||
assert "matrixAuthenticationService.encryptionSecret" in discovery.discovered_secrets
|
||||
assert discovery.discovered_secrets["matrixAuthenticationService.encryptionSecret"].value == "my_encryption_key"
|
||||
Reference in new issue
Block a user