diff --git a/packages/ess-migration-tool/newsfragments/1394.bugfix.md b/packages/ess-migration-tool/newsfragments/1394.bugfix.md new file mode 100644 index 00000000..78cba114 --- /dev/null +++ b/packages/ess-migration-tool/newsfragments/1394.bugfix.md @@ -0,0 +1 @@ +Fix an issue where secret conflict resolution would end up with the wrong secrets being configured in the values files, and secrets being duplicated in the secrets files. \ No newline at end of file diff --git a/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py b/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py index 3a123330..bf3f85e5 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py @@ -199,14 +199,14 @@ class DiscoveredSecretTracking: owning_strategy = source.strategy if source.takes_precedence: - found_precedence = True # This strategy wants to own this secret - if owning_strategy is not None: + if found_precedence: # More than one strategy wants to own it - this is a conflict logger.error( f"Multiple strategies claim precedence for secret {secret_key}: " - f"{owning_strategy} and {source.strategy.name}. " + f"{owning_strategy.name} and {source.strategy.name}. " ) + found_precedence = True owning_strategy = source.strategy # If no strategy has takes_precedence, diff --git a/packages/ess-migration-tool/src/ess_migration_tool/migration.py b/packages/ess-migration-tool/src/ess_migration_tool/migration.py index 5301266e..8fc03ab1 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/migration.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/migration.py @@ -315,7 +315,7 @@ class ConfigValueTransformer: owner = secret_discovery.secret_tracking.get_secret_owner(secret_key) if owner and owner != secret_discovery.strategy: # This secret is owned by another strategy, skip it - logger.debug(f"Skipping {secret_key} for {secret_discovery.strategy} - owned by {owner}") + logger.debug(f"Skipping {secret_key} for {secret_discovery.strategy.name} - owned by {owner.name}") continue # Base64 encode the secret value for Kubernetes Secret diff --git a/packages/ess-migration-tool/tests/test_secret_conflict_resolution.py b/packages/ess-migration-tool/tests/test_secret_conflict_resolution.py index af47a498..091b263d 100644 --- a/packages/ess-migration-tool/tests/test_secret_conflict_resolution.py +++ b/packages/ess-migration-tool/tests/test_secret_conflict_resolution.py @@ -177,3 +177,35 @@ def test_synapse_signing_key_not_optional(): assert signing_key_config is not None assert not signing_key_config.optional + + +def test_conflict_with_precedence_conflict(caplog): + """Test that conflict is detected when sources have different values from different strategies.""" + tracking = DiscoveredSecretTracking() + global_options = GlobalOptions() + with caplog.at_level(logging.DEBUG, logger="migration"): + synapse = SynapseSecretDiscovery(global_options) + mas = MASSecretDiscovery(global_options) + tracking.add_source("synapse.signingKey", synapse, "value1", "path1", takes_precedence=True) + tracking.add_source("synapse.signingKey", mas, "value2", "path2", takes_precedence=True) + + owner = tracking.get_secret_owner("synapse.signingKey") + + assert owner.name == "Matrix Authentication Service" ## last one found + assert "Multiple strategies claim precedence for secret" in caplog.text + + +def test_conflict_without_precedence_conflict(caplog): + """Test that conflict is detected when sources have different values from different strategies.""" + tracking = DiscoveredSecretTracking() + global_options = GlobalOptions() + with caplog.at_level(logging.DEBUG, logger="migration"): + synapse = SynapseSecretDiscovery(global_options) + mas = MASSecretDiscovery(global_options) + tracking.add_source("synapse.signingKey", synapse, "value1", "path1", takes_precedence=True) + tracking.add_source("synapse.signingKey", mas, "value2", "path2") + + owner = tracking.get_secret_owner("synapse.signingKey") + + assert owner.name == "Synapse" + assert "Multiple strategies claim precedence for secret" not in caplog.text