Files
fancy-dns/deploy/config.example.yaml
T
developer 504512f247 Add a Zones console: create and manage local zones, records and delegations
The console could not see local zones at all. `blocklist.local_zones` compiled
a store that nothing read back: there was no API for a zone, its records, its
delegations or the file a record came from, and no way to change one without
editing YAML and reloading. The Domains page is the blocklist's inline rules,
not local data, so nothing in the console covered the half of the server that
answers authoritatively from disk. There is now a Zones page and the endpoints
behind it: `GET /api/zones`, `POST`/`PUT`/`DELETE /api/zones/records`,
`POST`/`DELETE /api/zones/delegations` and `DELETE /api/zones?zone=`.

**The console owns one directory and nothing else.** `blocklist.managed_zones`
holds one `<apex>.zone` per zone, with that zone's SOA, apex NS set and the
records added there, and it is compiled by the same `localzone.Load` as the
operator's files — so a record added from the console is served on the next
query, with no reload and no restart. Files in `blocklist.local_zones` are
listed and shown read-only and are never rewritten; the key defaults to empty,
so a deployment that never sets it gets a zone browser and no zone writes.
Which file a record came from is now part of the store (`zone.files`, keyed by
the index the store already uses), so the snapshot can say "console" or "your
file" per record; the query path does not read it.

**The writer proves its own output.** A record is validated by the project's own
master-file parser, so `www` means `www.<zone>` and a bare CNAME target is
completed exactly as it would be in a zone file; the file is rendered, and the
rendering is re-parsed and compared with the records it meant to write before
the file is renamed into place. A writer bug that dropped a record would
otherwise present as a zone that silently stopped answering. A zone that cannot
answer is refused rather than created: no SOA means no NXDOMAIN or NODATA
authority, and no apex NS means nothing is delegated and no server is named. The
SOA's primary follows the apex NS set — a zone whose SOA names a server outside
its own NS set hands out a referral no resolver can follow — and the serial
moves on every write.

**A delegation takes the names under it, so a record below a cut is refused.**
The store answers those names as delegated without reading the zone file, which
would make the record data that looks alive and never answers. `DELETE
/api/zones?zone=` exists for the same reason from the other side: a zone the
console created is a real zone, so it says NXDOMAIN for what it does not hold,
and deleting a record is not what gives a name back to upstream. It is
refused for a zone that also has records outside the managed directory, because
removing that file would remove none of the zone.

**Two bugs the work turned up.** `engine.applyConfig` published local-record
metrics only when `blocklist.local_zones` was non-empty, so a zone the console
created was served but never counted; the gate is now the store's own record
count. And the record-value renderer fell back to `RR.String()` for every type
it did not know, which is the whole line rather than the RDATA — it wrote a
name and a TTL into the value column for DHCID, LOC, SSHFP and SVCB, and would
have fed that back as a record value on the next edit.

Every write recompiles the store and flushes the cache. Which names changed is
not knowable from the API, and a cached upstream answer for a name the zone now
answers is simply wrong, so the flush is blunt on purpose.

The wire shapes are type aliases in `internal/api` rather than copies, so there
is one set of json tags, and `TestZoneEndpointKeySets` pins the key set at every
level with a record and a delegation actually present — an empty list only
proves the envelope. `TestZoneWritesNeedAManagedDirectory` pins the read-only
default, and `TestZoneConsoleRoundTrip` walks the whole thing: a record added
through the API is answered authoritatively on the next query, a cut stops the
parent answering below it, and deleting the zone hands the name back.

Verified against a running instance built from this tree: records and
wildcards answer with `aa`, relative names are qualified, a record below a cut
is refused with a message that says why, and the file on disk is a zone file
an operator can read. The console page is typechecked and built; the browser was
not available in this round, so it has not been looked at.
2026-09-28 07:45:16 +00:00

232 lines
6.2 KiB
YAML

# fancy-dns — example configuration.
#
# Every value below is a default; delete what you do not need. The admin API
# rewrites this file when you save from the console, so keep it in git and
# review the diff.
version: 0
server:
# In-flight upstream resolutions. Excess queries get SERVFAIL rather than
# queueing without bound.
max_concurrent: 1024
timeouts:
udp: 2s
tcp: 4s
tls: 4s
query: 5s
upstream: 2s
list_fetch: 60s
dns:
udp: ["0.0.0.0:53", "[::]:53"]
tcp: ["0.0.0.0:53", "[::]:53"]
# Advertised EDNS0 buffer size for our own answers.
max_udp_size: 1232
serve_stale: 0s
edns0:
# Forward the client's EDNS-Client-Subnet so upstream picks a nearby
# anycast location.
client_subnet: true
ipv4_bits: 24
ipv6_bits: 56
preserve: true
dot:
enabled: false
listen: ["0.0.0.0:853"]
cert_file: /etc/fancy-dns/tls/fullchain.pem
key_file: /etc/fancy-dns/tls/privkey.pem
min_version: "1.2"
doh:
enabled: false
listen: ["0.0.0.0:443"]
base_path: /dns-query
cert_file: /etc/fancy-dns/tls/fullchain.pem
key_file: /etc/fancy-dns/tls/privkey.pem
min_version: "1.2"
allow_post: true
transport:
mode: auto
upstream:
# parallel: race them, take the first good answer. random: try N at random.
# failover: walk the list in order.
policy: parallel
max_attempts: 3
healthcheck_interval: 30s
breaker_threshold: 5
breaker_cooldown: 30s
servers:
- addr: 9.9.9.9:53
proto: udp
health_name: dns.quad9.net
- addr: 149.112.112.112:53
proto: udp
health_name: dns.quad9.net
- addr: 1.1.1.1:53
proto: tls
server_name: cloudflare-dns.com
- addr: 9.9.9.9:853
proto: tls
server_name: dns.quad9.net
# The memory envelope. A cgroup kill is an outage; a cache miss is not, so the
# runtime gets a soft ceiling to work towards instead of finding out the hard
# way. Set limit to your container's memory limit, minus the reserve.
memory:
# Soft heap ceiling (GOMEMLIMIT). 0 = unbounded. The Go heap excludes
# goroutine stacks, runtime metadata and the bbolt mmap for the cache
# snapshot and the query log, which is what the reserve is for.
limit: "0"
reserve: "256MiB"
# Byte budget for the in-memory LRU. 0 derives it from the limit (60%).
# cache.size alone does not bound memory: one cached ANY or TXT answer can
# be tens of kilobytes, so 500k entries is anywhere from 150MB to several GB
# depending on what the traffic asked for.
cache_max_bytes: "0"
cache:
enabled: true
size: 200000
shards: 32
min_ttl: 0s
max_ttl: 1h
# Keep expired answers around this long so a dead upstream costs latency,
# not availability.
serve_stale: 30m
prefetch: true
negative_ttl: 30m
persist:
enabled: true
path: data/cache.db
interval: 30s
max_entries: 500000
load_on_start: true
prewarm: []
blocklist:
enabled: true
# nxdomain | zero | redirect | drop | refused
default_action: nxdomain
response_ip: 0.0.0.0
response_ipv6: "::"
response_ttl: 60s
# RPZ-style policy zones and/or local authoritative data, as master files.
local_zones: []
# The one directory the admin console may WRITE zone data into: one
# <apex>.zone per zone, holding the SOA, the apex NS set and whatever the
# console created. Files in local_zones are read-only to the console, and
# are never rewritten by it. Empty keeps the console's Zones page
# read-only, so nothing is written behind your back.
managed_zones: ""
# Inline rules. "*.example.com" covers subdomains, "**.example.com" covers
# the apex too, a bare name matches only itself.
block_entries: []
allow_entries: []
lists:
- name: haas
format: plain
url: https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
path: data/lists/hosts
enabled: true
refresh: 24h
categories: [ads, tracking]
- name: easylist
format: adblock
url: https://easylist.to/easylist/easylist.txt
path: data/lists/easylist.txt
enabled: false
refresh: 24h
categories: [ads]
- name: local-rpz
format: rpz
path: zones/local.rpz.zone
enabled: true
refresh: 0s
acl:
# allow | deny | block_only
default_policy: allow
default_rate_limit: 0
groups:
- name: guests
comment: Blocklists apply, but the kitchen-sink allowlist does not.
match:
cidrs: ["192.168.90.0/24"]
policy: block_only
rate_limit: 50
- name: printers
comment: No recursion at all; they only need DHCP.
match:
cidrs: ["192.168.91.0/24"]
policy: deny
qlog:
enabled: true
path: data/queries.db
max_entries: 200000
flush_interval: 1s
# 1.0 logs every query. Lower it on a busy instance: the per-domain
# counters are what the dashboard actually needs.
sample_rate: 1.0
log_blocked: true
log_cached: false
log_errors: true
live_buffer: 2000
top_domains: 5000
top_ttl: 5m
cluster:
enabled: false
# node_id: dns-1
# advertise: http://10.0.0.10:8080
peer_ttl: 15s
valkey:
addrs: ["valkey:6379"]
prefix: fancydns
pool_size: 10
dial_timeout: 2s
read_timeout: 2s
# Only the lease holder fetches lists, so N instances do not hit a
# mirror N times.
leader_ttl: 30s
api:
enabled: true
listen: ["127.0.0.1:8080"]
# tls_listen: ["0.0.0.0:8443"]
base_path: /api
ui: true
allow_config_write: true
allow_blocklist_write: true
# Only these proxies may set X-Forwarded-For; anything else is ignored, so a
# client cannot spoof its identity past the ACL or the rate limiter.
trusted_proxies: []
cors_origins: []
auth:
# none | apikey | basic | oidc
mode: apikey
api_keys: ["CHANGE-ME-long-random-string"]
read_only_api_keys: []
trust_loopback: true
session_ttl: 12h
# For mode: oidc, configure a registered public PKCE client and the API
# audience included in its access tokens. Users need the admin role to write.
oidc_issuer: https://users.k6n.net
oidc_audience: https://fancy-dns.example.net
oidc_client_id: fancy-dns
oidc_write_roles: [admin]
rate_limit:
per_minute: 600
failures: 10
lockout: 5m
metrics:
enabled: true
path: /metrics
protect: true
log:
level: info
format: text