mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-05 17:28:21 +00:00
feat(diagnostics): probe daemon.json dns upstreams
A Tor node rewrites resolv.conf to the local dnsmasq alone, so the rescue bundle of run 32118850138 could not prove whether the pinned upstream (172.30.0.53) was alive while that dnsmasq sat silent on a dead :53. Probe the daemon.json dns servers too, deduped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8e6e687a80
commit
6b7489bb1d
2 files changed
+63
No files matched your search
@@ -133,6 +133,48 @@ class CollectTests(unittest.TestCase):
|
||||
self.assertTrue((out / "resolve-ghcr-io-via-10-0-0-2.txt").is_file())
|
||||
self.assertTrue((out / "resolve-ghcr-io.txt").is_file())
|
||||
|
||||
def test_daemon_json_dns_servers_are_probed_and_deduped(self):
|
||||
mod = _load()
|
||||
|
||||
def fake_run(cmd, **_kw):
|
||||
if cmd == ["cat", "/etc/resolv.conf"]:
|
||||
return _cp(cmd, stdout=b"nameserver 127.0.0.1\n")
|
||||
if cmd == ["cat", "/etc/docker/daemon.json"]:
|
||||
return _cp(cmd, stdout=b'{"dns": ["172.30.0.53", "127.0.0.1"]}')
|
||||
return _cp(cmd)
|
||||
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
out = Path(td)
|
||||
with (
|
||||
mock.patch.object(
|
||||
mod.shutil, "which", side_effect=lambda b: b == "dig"
|
||||
),
|
||||
mock.patch.object(mod, "run", side_effect=fake_run) as runner,
|
||||
):
|
||||
mod.collect_resolver_probes(out)
|
||||
self.assertTrue((out / "resolve-ghcr-io-via-172-30-0-53.txt").is_file())
|
||||
loopback_digs = [
|
||||
c.args[0]
|
||||
for c in runner.call_args_list
|
||||
if c.args[0][:1] == ["dig"]
|
||||
and "@127.0.0.1" in c.args[0]
|
||||
and "ghcr.io" in c.args[0]
|
||||
]
|
||||
self.assertEqual(len(loopback_digs), 1, loopback_digs)
|
||||
|
||||
def test_a_broken_daemon_json_adds_no_probes(self):
|
||||
mod = _load()
|
||||
with mock.patch.object(
|
||||
mod, "run", return_value=_cp([], rc=0, stdout=b"not json")
|
||||
):
|
||||
self.assertEqual(mod.daemon_json_dns(), [])
|
||||
with mock.patch.object(mod, "run", return_value=_cp([], rc=1)):
|
||||
self.assertEqual(mod.daemon_json_dns(), [])
|
||||
with mock.patch.object(
|
||||
mod, "run", return_value=_cp([], rc=0, stdout=b'{"dns": "1.1.1.1"}')
|
||||
):
|
||||
self.assertEqual(mod.daemon_json_dns(), [])
|
||||
|
||||
def test_a_distro_without_a_query_tool_still_gets_the_per_name_verdicts(self):
|
||||
mod = _load()
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
|
||||
@@ -24,6 +24,7 @@ Usage:
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
@@ -151,6 +152,25 @@ def collect_host(out: Path, app_id: str, context: str, stamp: str) -> None:
|
||||
collect_service_state(out)
|
||||
|
||||
|
||||
def daemon_json_dns() -> list[str]:
|
||||
"""Nameservers pinned under the ``dns`` key of /etc/docker/daemon.json.
|
||||
|
||||
A Tor node's resolv.conf names only the local dnsmasq, so probing its
|
||||
entries alone cannot say whether the pinned upstream was still alive when
|
||||
that dnsmasq went silent. Anything unreadable or keyless yields [].
|
||||
"""
|
||||
proc = run(["cat", "/etc/docker/daemon.json"])
|
||||
if proc.returncode != 0:
|
||||
return []
|
||||
try:
|
||||
dns = json.loads(proc.stdout.decode(errors="replace")).get("dns")
|
||||
except ValueError:
|
||||
return []
|
||||
if not isinstance(dns, list):
|
||||
return []
|
||||
return [str(server) for server in dns]
|
||||
|
||||
|
||||
def collect_resolver_probes(out: Path) -> None:
|
||||
"""Resolve each probed name, once through the stack and once per nameserver.
|
||||
|
||||
@@ -175,6 +195,7 @@ def collect_resolver_probes(out: Path) -> None:
|
||||
for parts in (line.split() for line in list_lines(["cat", "/etc/resolv.conf"]))
|
||||
if parts[:1] == ["nameserver"] and len(parts) > 1
|
||||
]
|
||||
servers += [server for server in daemon_json_dns() if server not in servers]
|
||||
for host in _PROBE_HOSTS:
|
||||
capture(out, f"resolve-{source_name(host)}", ["getent", "hosts", host])
|
||||
if not tool:
|
||||
|
||||
Reference in new issue
Block a user