diff --git a/deploy/panel_installer/secondary.py b/deploy/panel_installer/secondary.py index 34f3baa..b414729 100644 --- a/deploy/panel_installer/secondary.py +++ b/deploy/panel_installer/secondary.py @@ -2,6 +2,7 @@ import argparse import grp import json import os +import stat import subprocess from contextlib import suppress from pathlib import Path @@ -60,7 +61,17 @@ def seed_catalog(): from coulobre.domain_names import canonical_domain from coulobre.node_files import read_root_file - engine.root_directory(PATH.parent) + directory = PATH.parent + mode = 0o2750 + engine.root_directory(directory, mode=mode) + info = directory.lstat() + group = grp.getgrnam("bind").gr_gid + if info.st_gid != group: + os.chown(directory, -1, group, follow_symlinks=False) + # mkdir honors the caller's umask, but BIND must be able to traverse + # this directory even when setup is run with a restrictive umask. + if info.st_gid != group or stat.S_IMODE(info.st_mode) != mode: + directory.chmod(mode) if PATH.exists(): engine.root_file(PATH, 0o644) return diff --git a/docs/deployment.md b/docs/deployment.md index a12c3b5..6104999 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -3893,7 +3893,9 @@ On an existing catalog primary, rerun the primary command from the current release using the same peer address. This grants the DNS apply service write access to the catalog directory while retaining its filesystem sandbox. It preserves the catalog, managed zones, and transfer key. The -secondary does not need this permission. +command also repairs the catalog directory's access for BIND if setup +previously ran with a restrictive umask. The secondary does not need the +DNS apply service's write permission. When upgrading a catalog primary from 1.2.0 or earlier, apply this step before resuming DNS provisioning. On an APT-managed primary, run diff --git a/tests/test_secondary_dns_installer.py b/tests/test_secondary_dns_installer.py index 70527f3..f9683c2 100644 --- a/tests/test_secondary_dns_installer.py +++ b/tests/test_secondary_dns_installer.py @@ -1,4 +1,5 @@ import os +import stat import tempfile import unittest from functools import partial @@ -113,16 +114,29 @@ class DNSCatalogSandboxTests(unittest.TestCase): self.run_command.call_args_list, ) + def test_primary_catalog_is_traversable_with_a_restrictive_umask(self): + previous = os.umask(0o077) + try: + secondary.setup("primary", self.peer) + finally: + os.umask(previous) + + self.assertEqual(stat.S_IMODE(self.seed.parent.stat().st_mode), 0o2750) + self.assertEqual(self.seed.parent.stat().st_gid, os.getgid()) + self.assertEqual(stat.S_IMODE(self.seed.stat().st_mode), 0o644) + def test_existing_primary_without_override_gets_one(self): self.config.write_text(secondary.configuration("primary", self.peer)) self.seed.parent.mkdir() catalog = dns_catalog.render_catalog(17, {"site.test"}) self.seed.write_text(catalog) + self.seed.parent.chmod(0o2700) secondary.setup("primary", self.peer) self.assertEqual(self.override.read_text(), self.override_text) self.assertEqual(self.seed.read_text(), catalog) + self.assertEqual(stat.S_IMODE(self.seed.parent.stat().st_mode), 0o2750) def test_existing_primary_keeps_zones_key_and_manual_override(self): self.config.write_text(secondary.configuration("primary", self.peer))