fix(sys-token-store): let the users lookup read the store of the stack host

Lookups render on the controller and read FILE_TOKENS there, while sys-token-store writes the store on STACK_HOST and mirrors it to the controller only in swarm. A compose deploy run from another machine therefore resolved every token empty: on echoserver Friendica rendered an empty SMTP_AUTH_PASS (msmtp: authentication method PLAIN needs a password) and Stalwart minted new bot app passwords on every run.

get_merged_users and the applications carrier key now take the sys_token_store_users fact, which the play reads from the stack host, over the controller file; write.yml refreshes the fact after each write, and 01_load.yml slurps from STACK_HOST so every host reads the store that is written. Without the fact, as in tests and ad-hoc calls, the controller file still applies, and where controller and stack host share the file the merged users are identical.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-10-24 15:01:05 +02:00
1 parent 84090bb24e
commit d3b9ae59a9
6 files changed
+115 -8

No files matched your search

+51
View File
@@ -363,5 +363,56 @@ class TestGetMergedUsersWithOverrides(unittest.TestCase):
self.assertEqual(merged["foo"]["username"], "override-user")
class TestGetMergedUsersTokenSource(unittest.TestCase):
def setUp(self) -> None:
_reset_cache_for_tests()
def _merged(self, roles: Path, tokens_file: Path, **extra) -> dict:
return cache_users.get_merged_users(
variables={"FILE_TOKENS": str(tokens_file), **extra},
roles_dir=roles,
templar=None,
)
def _seed(self, tmp: Path) -> tuple[Path, Path]:
roles = _seed_minimal_user_role(tmp, "web-app-foo")
tokens_file = tmp / "tokens.yml"
tokens_file.write_text(
dump_yaml_str({"users": {"foo": {"tokens": {"web-app-foo": "from-file"}}}}),
encoding="utf-8",
)
return roles, tokens_file
def test_the_store_fact_of_the_play_wins_over_the_controller_file(self):
with tempfile.TemporaryDirectory() as tmp:
roles, tokens_file = self._seed(Path(tmp))
merged = self._merged(
roles,
tokens_file,
sys_token_store_users={
"foo": {"tokens": {"web-app-foo": "from-stack-host"}}
},
)
self.assertEqual(merged["foo"]["tokens"]["web-app-foo"], "from-stack-host")
def test_without_the_fact_the_controller_file_is_read(self):
with tempfile.TemporaryDirectory() as tmp:
roles, tokens_file = self._seed(Path(tmp))
merged = self._merged(roles, tokens_file)
self.assertEqual(merged["foo"]["tokens"]["web-app-foo"], "from-file")
def test_a_written_token_reaches_the_next_lookup(self):
with tempfile.TemporaryDirectory() as tmp:
roles, tokens_file = self._seed(Path(tmp))
before = self._merged(roles, tokens_file, sys_token_store_users={})
after = self._merged(
roles,
tokens_file,
sys_token_store_users={"foo": {"tokens": {"web-app-foo": "minted"}}},
)
self.assertNotIn("web-app-foo", before["foo"].get("tokens", {}))
self.assertEqual(after["foo"]["tokens"]["web-app-foo"], "minted")
if __name__ == "__main__":
unittest.main()