Restore the import DNS exception and close temporary rules on every exit #159
Loading…
Reference in a new issue
No description provided.
Delete branch "import-dns-exception"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Upstream removed the
dns_request_exception("-I")call in 2019 (e6a7818) but left the"-D"indownloaded()dangling — every import since has logged eight failed rule deletions, and with the firewall active and no tunnel up, imports couldn't resolve anything: the default ruleset's OUTPUT policy is DROP with no port-53 exception (LAN resolvers only work withblock_lan=0). Surfaced while live-verifying #157 (#158).Digging into the cleanup path also exposed a second, hidden leak: the per-IP api rules
allow_ipinserts were only ever deleted incopy_certs— a failed import left them behind permanently.Fix
allow_ip, which every import passes through before its first resolution — custom imports included (they resolveremotehostnames from config files and were the original reason for the exception).revoke_api_accesson the thread (per-IP rules + DNS exception, idempotent), called from all three exits:copy_certs(success),fail()(handled failures),report_failure(crashes)."-D"in the service'sdownloaded()is gone, as aredns_request_exception's deaddns_1/dns_2parameters (onlyportwas ever read).Known accepted edge: concurrent imports share one rule copy (
add_rulededups via-C), so the first to finish can close port 53 under a sibling still resolving — the loser reports a network error and the scheduler retries next cycle. Refcounting rules across threads wasn't worth it.Verification
pytestgreen (356 passed) plus the ruff/compileall gates.TestApiAccessLifecycle: handled failure and crash both close exactly what was opened (DNS pair + per-IP pair, in order); the success-side close is pinned against the realcopy_certssince every other test stubs it.iptables: failed to applylines — and one "adding exception for DNS requests" before "removing".Related fixes (found along the way, technically out of scope)
Closes #158.
🤖 Generated with Claude Code
Upstream removed the dns_request_exception("-I") call in 2019 (e6a7818) and left the delete in downloaded() dangling: every import since has logged eight failed rule removals, and with the firewall up and no tunnel, nothing could resolve -- not the api hosts, not the hostnames a custom config carries (#158). The insert now lives at the top of allow_ip, which every import passes through before its first resolution, custom imports included. Cleanup moves onto the thread as revoke_api_access, called from all three exits: copy_certs on success, fail() for handled failures and report_failure for crashes. That also closes a second leak the one-exit cleanup hid -- the per-IP api rules were only ever deleted on success, so a failed import left them behind. Concurrent imports share one rule copy (add_rule dedups via -C), so the first to finish can close port 53 under a sibling still resolving; the loser fails as a network error and the scheduler retries next cycle -- accepted over refcounting rules across threads. dns_request_exception's dns_1/dns_2 parameters were dead (only port is read) and are gone. Closes #158. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>