Skip to content

Add minimal DNS proxy with DoT/DoH in- and outbound - #1

Merged
t11z merged 3 commits into
mainfrom
claude/wonderful-edison-64t8sv
Oct 4, 2026
Merged

t11z merged 3 commits into
mainfrom
claude/wonderful-edison-64t8sv

Conversation

@t11z

@t11z t11z commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A small DNS forwarder in Rust, with no extra features.

  • Inbound: plain DNS over UDP and TCP, DoT (RFC 7858), and DoH (RFC 8484) over HTTP/1.1 and HTTP/2, GET and POST.
  • Outbound: DoT or DoH only. Upstreams are tried in order. One that fails is moved to the back for 30 s.
  • Left out on purpose: caching, ACME, HTTP/3, DNSSEC validation, rate limiting.

Security design

  • Allowlist per listener. Each listener needs an allow CIDR list and/or allow_hosts. An empty config is an error, so the proxy never becomes an open resolver by accident.
  • No plain-DNS bootstrap. Upstreams are reached via the IPs in addrs. Their hostnames are only used for SNI and certificate checks.
  • TLS: rustls with the ring provider, TLS 1.2 and 1.3. Certificates are checked against webpki-roots or a configured ca_file.
  • Own DNS wire parser. It checks every bound and is tested against random input. It reads only header, question, EDNS, and the A/AAAA answers needed for allow_hosts.
  • Response checks:
    • The answer must repeat the question and carry the expected ID.
    • DoT queries use a fresh random ID; DoH queries use ID 0.
  • UDP size cap: at most the client's EDNS size, never more than 1232 bytes. Larger answers are cut off with the TC bit set, so the client retries over TCP.
  • Resource limits: caps on connections and in-flight queries; timeouts for handshake, idle, headers and request bodies.
  • Privacy: query names are never logged. Failures are logged once per outage.
  • systemd unit:
    • runs as DynamicUser; its only capability is CAP_NET_BIND_SERVICE;
    • certificate and key come in via LoadCredential;
    • sandboxed with ProtectSystem=strict and a syscall filter.

Dynamic client IPs

  • allow_hosts:
    • DynDNS names are resolved in the background through the encrypted upstreams, never per packet.
    • The refresh interval follows the record's TTL. A rejected client triggers an early, rate-limited refresh.
    • Nothing is allowed until the first answer. NXDOMAIN clears a name's addresses at once. If lookups fail, the last addresses stay valid for up to 1 h (max_stale).
    • Default prefix: /32 for IPv4, /64 for IPv6, adjustable per host.
    • A warning is logged at startup when allow_hosts is used on plain udp/tcp listeners.
  • Secret DoH path: compared in constant time, documented as the token-based alternative.

Release and docs

  • Release workflow (.github/workflows/release.yml, runs when a tag vX.Y.Z is pushed):
    • builds static musl binaries for x86_64 and aarch64 with cargo-zigbuild;
    • stops if the tag and the Cargo.toml version disagree;
    • publishes SHA256SUMS and GitHub build provenance (gh attestation verify);
    • marks tags with a suffix as pre-releases;
    • pins all actions to commit SHAs. Build permissions are read-only; only the publish job can write.
  • Pages (docs/, .github/workflows/pages.yml): a one-page documentation site in the Nullthrone design system.
    • The tokens are copied unchanged from Claude Design. The components are rebuilt in plain CSS. No JavaScript.
    • Light and dark mode follow the OS setting.

Structure

src/dns.rs         wire parsing, SERVFAIL/TC, A/AAAA extraction
src/config.rs      TOML + validation
src/acl.rs         static networks + hostname rules
src/hosts.rs       allow_hosts registry and background refresher
src/upstream/      DoT (pool), DoH (h2), failover
src/server/        UDP, TCP+DoT (pipelined), DoH (hyper h1/h2)
dist/              systemd unit
docs/              GitHub Pages site (Nullthrone design system)
tests/e2e.rs       end-to-end tests with fake upstreams and a test CA

Test plan

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings
  • cargo test: 24 unit tests and 18 end-to-end tests, repeated runs without failures
  • Mutation check: with the reject trigger disabled, the matching test fails
  • dns-proxy --check passes on config.example.toml
  • actionlint finds no issues in all workflows
  • Built both musl targets locally with cargo-zigbuild (x86_64 and aarch64 ELF, statically linked). Ran the packaging and sha256sum -c steps locally.
  • Docs page rendered with Playwright in light, dark and 390 px width; no horizontal overflow
  • Release workflow is untested on GitHub until the first tag. The attestation and gh release steps only run there.
  • Pages: enable Settings → Pages → Source: GitHub Actions. The site deploys after the merge to main.
  • No live test against Quad9/Cloudflare: the sandbox blocks :853, and :443 goes through a TLS-intercepting proxy.
  • systemd unit untested; check SystemCallFilter=~@resources first.

🤖 Generated with Claude Code

https://claude.ai/code/session_011hHaUEqQpj7pg7F9XAM8Ce

claude added 3 commits October 4, 2026 15:24
Plain DNS (UDP/TCP), DNS over TLS and DNS over HTTPS (HTTP/1.1 + HTTP/2)
inbound; DoT and DoH upstreams outbound with ordered failover.

- Mandatory per-listener CIDR allowlist (no open resolver by default)
- Upstreams addressed via configured bootstrap IPs only; hostnames are
  used for SNI/certificate verification, never resolved
- rustls (ring), webpki-roots or custom CA file
- Small bounds-checked DNS wire parser; responses validated against the
  query (question + ID), random IDs for DoT, ID 0 for DoH
- UDP responses capped at EDNS size (max 1232), TC fallback
- Connection, in-flight, handshake, idle and body limits
- Hardened systemd unit (DynamicUser, CAP_NET_BIND_SERVICE only,
  LoadCredential for certificates, syscall filter)
- Unit tests and end-to-end tests with fake upstreams and a test CA

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011hHaUEqQpj7pg7F9XAM8Ce
Clients with dynamic public IPs can now be admitted via `allow_hosts`.
Names are resolved in the background through the encrypted upstreams
(never via the system resolver, never per packet); the packet path only
reads the last known addresses.

- A/AAAA lookups with TTL-driven refresh, clamped by [host_acl]
- Rejected clients trigger an early, rate-limited refresh
- Fail closed until the first lookup; NXDOMAIN/NODATA clears at once;
  on lookup failures the last addresses stay valid for max_stale
- IPv4 matches /32, IPv6 /64 by default (per-host v4_prefix/v6_prefix,
  bounded to avoid accidental wide ranges)
- Startup warning for allow_hosts on plain udp/tcp listeners
- Minimal A/AAAA answer parsing in dns.rs, bounds-checked and fuzzed
- Constant-time DoH path comparison so the path can carry a secret
- README: threat model for DynDNS admission and the secret-path option

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011hHaUEqQpj7pg7F9XAM8Ce
Release (on tags vX.Y.Z):
- Static musl binaries for x86_64 and aarch64 via cargo-zigbuild
- Refuses to run when the tag and Cargo.toml version disagree
- SHA256SUMS and GitHub build provenance attestations
- Pre-release for tags with a suffix; actions pinned to commit SHAs

Pages:
- Single-page documentation in docs/, deployed from main via GitHub
  Actions (requires Pages source "GitHub Actions")
- Styled with the Nullthrone design system: tokens vendored unchanged
  from Claude Design, components recreated in plain CSS, no JavaScript,
  light and dark via the OS preference

README: install from releases with verification, release process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011hHaUEqQpj7pg7F9XAM8Ce
@t11z
t11z merged commit 0a09bb7 into main Oct 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants