Support local DNS publishing over a restricted Unix socket

This commit is contained in:
parkel committed 2026-11-21 01:30:34 +01:00
1 parent ffdeb5fe69
commit 6e075c25f4
6 files changed
+134 -12

No files matched your search

+30 -5
View File
@@ -9,12 +9,14 @@ from pathlib import Path
import idna
from .domain_names import canonical_domain
from .node_requests import serve_apply_request
BASE_MANIFEST_VERSION = 1
MAIL_RECORD_MANIFEST_VERSION = 2
MANIFEST_KIND = "bind9_zone"
MAX_SOA_SERIAL = 2**32 - 1
TXT_CHUNK_SIZE = 255
DNS_REQUEST_LIMIT = 1024 * 1024
def dns_name(value):
@@ -254,19 +256,27 @@ class DnsZone:
txt_records=read_records(data, "txt_records", TxtRecord),
)
def manifest(self):
manifest = {
"version": BASE_MANIFEST_VERSION,
def manifest_identity(self):
version = (
MAIL_RECORD_MANIFEST_VERSION
if self.mx_records or self.txt_records
else BASE_MANIFEST_VERSION
)
return {
"version": version,
"kind": MANIFEST_KIND,
"domain": self.domain,
"serial": self.serial,
}
def manifest(self):
manifest = self.manifest_identity() | {
"nameservers": list(self.nameservers),
"responsible_name": self.responsible_name,
"addresses": [asdict(record) for record in self.addresses],
}
if self.mx_records or self.txt_records:
if manifest["version"] == MAIL_RECORD_MANIFEST_VERSION:
manifest.update(
version=MAIL_RECORD_MANIFEST_VERSION,
mx_records=[asdict(record) for record in self.mx_records],
txt_records=[asdict(record) for record in self.txt_records],
)
@@ -296,8 +306,23 @@ def main(argv=None):
render.add_argument("manifest", type=Path)
apply = commands.add_parser("apply", help="Install or update a primary BIND9 zone.")
apply.add_argument("manifest", type=Path)
commands.add_parser(
"apply-request",
help="Publish one BIND9 manifest from standard input and report JSON.",
)
args = parser.parse_args(argv)
if args.command == "apply-request":
from .dns_node_apply import apply_zone
return serve_apply_request(
BASE_MANIFEST_VERSION,
DnsZone.from_manifest,
apply_zone,
limit=DNS_REQUEST_LIMIT,
identity=DnsZone.manifest_identity,
)
try:
payload = json.loads(args.manifest.read_text(encoding="utf-8"))
zone = DnsZone.from_manifest(payload)