diff --git a/cli/administration/deploy/development/coredns.py b/cli/administration/deploy/development/coredns.py index 2baa519bf5..d587daa3d6 100644 --- a/cli/administration/deploy/development/coredns.py +++ b/cli/administration/deploy/development/coredns.py @@ -2,6 +2,7 @@ from __future__ import annotations import itertools import os +import re import tempfile from dataclasses import dataclass from pathlib import Path @@ -114,7 +115,9 @@ class CoreDNSCorefileRenderer: self._log("Rendering Corefile (atomic write)") try: - rendered = Template(read_text(tmpl_file)).safe_substitute(env) + rendered = Template(read_text(tmpl_file)).safe_substitute( + env, DOMAIN_RE=re.escape(env["INFINITO_DOMAIN"]) + ) with os.fdopen(fd, "w", encoding="utf-8") as fout: fout.write(rendered) diff --git a/compose/coredns/Corefile.tmpl b/compose/coredns/Corefile.tmpl index 6bffd62f6d..96b788ca26 100644 --- a/compose/coredns/Corefile.tmpl +++ b/compose/coredns/Corefile.tmpl @@ -1,23 +1,23 @@ .:53 { template IN A { - match ^${INFINITO_DOMAIN_RE}\.$ + match ^${DOMAIN_RE}\.$ answer "{{ .Name }} 60 IN A ${INFINITO_IP4}" fallthrough } template IN A { - match ^(.*)\.${INFINITO_DOMAIN_RE}\.$ + match ^(.*)\.${DOMAIN_RE}\.$ answer "{{ .Name }} 60 IN A ${INFINITO_IP4}" fallthrough } template IN AAAA { - match ^${INFINITO_DOMAIN_RE}\.$ + match ^${DOMAIN_RE}\.$ fallthrough } template IN AAAA { - match ^(.*)\.${INFINITO_DOMAIN_RE}\.$ + match ^(.*)\.${DOMAIN_RE}\.$ fallthrough } diff --git a/default.env b/default.env index 9b47201978..93cc0f4c87 100644 --- a/default.env +++ b/default.env @@ -175,9 +175,6 @@ INFINITO_DOCKER_VOLUME=docker # Top-level project domain rendered into vhost/cert/test fixtures; CI/dev default, overridden in real deploys. INFINITO_DOMAIN=infinito.test -# INFINITO_DOMAIN escaped for inclusion in regex patterns (literal `.`); keep in sync with INFINITO_DOMAIN. -INFINITO_DOMAIN_RE=infinito\.test - # Repo-relative path of the filesystem userland install script (ext4, btrfs, zfs). INFINITO_FILESYSTEM_INSTALL_SCRIPT=scripts/install/filesystem.sh diff --git a/tests/unit/python/cli/administration/deploy/development/test_coredns.py b/tests/unit/python/cli/administration/deploy/development/test_coredns.py new file mode 100644 index 0000000000..ccf2926aab --- /dev/null +++ b/tests/unit/python/cli/administration/deploy/development/test_coredns.py @@ -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() diff --git a/utils/env/handlers/passthrough.py b/utils/env/handlers/passthrough.py index 5a06d21c25..b0a30ff3d0 100644 --- a/utils/env/handlers/passthrough.py +++ b/utils/env/handlers/passthrough.py @@ -21,7 +21,6 @@ STATIC_KEYS = ( "INFINITO_DNS_HOSTS_FILE", "INFINITO_DNS_IP", "INFINITO_DOMAIN", - "INFINITO_DOMAIN_RE", "INFINITO_TOR_SOCKS_PORT", "INFINITO_CONTAINER", "INFINITO_CONTAINER_CA_ENABLED",