Merge pull request #1394 from element-hq/gaelg/debug-logs-fixes

Secrets conflicts resolution: fix debug logs
This commit is contained in:
Gaël Goinvic authored and GitHub committed 2026-06-10 15:03:13 +02:00
commit 94f0741c86
4 files changed
+37 -4

No files matched your search

@@ -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.
@@ -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,
@@ -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
@@ -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