fix(coredns): derive the domain regex from INFINITO_DOMAIN when rendering

INFINITO_DOMAIN_RE carried an already escaped regex through the env
chain: EnvBuilder.setdefault prefers a value already in the process env,
quote_for_dotenv escapes every backslash, and load.sh unescapes it again.
One inherited value with a doubled backslash was enough to write
"infinito\\\\.test" into .env, the rendered Corefile then matched a
literal backslash, and getent hosts test.infinito.test failed with rc 2.

The renderer now substitutes DOMAIN_RE = re.escape(INFINITO_DOMAIN) at
render time, so no backslash travels through the env or .env at all. The
template placeholder is renamed because it is a derived render value, not
an env key, and INFINITO_DOMAIN_RE is removed from default.env and the
passthrough keys, leaving INFINITO_DOMAIN as the single source.

A renderer test renders the real template and requires a single-escaped
match with no doubled backslash and no leftover placeholder. Verified
live: the Corefile renders ^infinito\.test\.$, test.infinito.test
resolves to 172.30.0.10 and test.infinitoXtest does not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-11 20:53:19 +02:00
1 parent 128e177255
commit c7d162fa88
5 files changed
+43 -9

No files matched your search

@@ -0,0 +1,35 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from cli.administration.deploy.development.coredns import CoreDNSCorefileRenderer
from utils.cache.files import PROJECT_ROOT, read_text
TEMPLATE = "compose/coredns/Corefile.tmpl"
class TestCoreDNSCorefileRenderer(unittest.TestCase):
def test_the_domain_regex_is_derived_from_the_domain_escaped_once(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
(root / ".env").write_text(
'INFINITO_DOMAIN=infinito.test\nINFINITO_IP4="172.30.0.10"\n',
encoding="utf-8",
)
template = root / TEMPLATE
template.parent.mkdir(parents=True)
template.write_text(
read_text(str(PROJECT_ROOT / TEMPLATE)), encoding="utf-8"
)
out = CoreDNSCorefileRenderer(repo_root=root).render(show_preview=False)
corefile = read_text(str(out))
self.assertIn("match ^infinito\\.test\\.$", corefile)
self.assertIn("match ^(.*)\\.infinito\\.test\\.$", corefile)
self.assertNotIn("\\\\", corefile)
self.assertNotIn("${", corefile)
if __name__ == "__main__":
unittest.main()