feat: add configurable PID1-owned DoH forwarding

Default managed SOCKS hostname DNS to verified HTTPS with literal-IP bootstrap and no plaintext fallback. Supervise the loopback forwarder with private anchored readiness and preserve foreign markers. Include configuration, deployment, documentation and offline checks.

Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
ZeusinaandGPT-6 Bot committed 2026-10-13 14:32:58 +03:00
1 parent ea886e5bc8
commit 367d956ae3
20 files changed
+2383 -37

No files matched your search

+43 -11
View File
@@ -202,14 +202,35 @@ asset checks cover sampled thumbnail/avatar routes, not the whole thumbnail pool
The current service/adaptive hardware acceptance gate is **pending**; the old
clean-run PASS below does not qualify these new modes.
Optional `SS_DNS_SERVER` is an unbracketed literal IPv4/IPv6 address only (for
example `8.8.8.8` or `2001:4860:4860::8888`); empty preserves existing resolver
behavior. No domain, port, zone, control characters or option strings are
accepted. Validation runs before service launch and reports opaque `configerror`
without echoing input. DNS applies only to this target's native `ss-server`.
The image build checks installed `ss-server -h` for native `-d <addr>` support;
the validated nonsecret address is passed as a separate `-d` argv value, not
eval or an assumed JSON key. Passwords still go only to private JSON configs.
**Managed DNS defaults to DoH**, independently of service/YouTube mode. PID 1
starts the stdlib Go forwarder on container loopback `127.0.0.1:5353` (UDP and
TCP), validates its private PID readiness acknowledgement, then starts ss-server
with `-d 127.0.0.1:5353`. No DNS port is published. Both client hostname traffic
and managed checks share this encrypted resolver path; it works for arbitrary
services, not only YouTube. HTTPS uses normal certificate verification, direct
literal-IP bootstrap and a socket mark excluding live/probe NFQUEUE rules;
there is no recursive SOCKS resolution or plaintext fallback. Endpoint errors
return SERVFAIL while the forwarder stays alive, rather than switching DNS modes.
The private `.env` controls `ZAPRET_AUTOTUNE_DNS_MODE=doh|native`,
`ZAPRET_AUTOTUNE_DOH_URL` (default `https://dns.google/dns-query`),
`ZAPRET_AUTOTUNE_DOH_BOOTSTRAP_IPS` (missing/empty selects `8.8.8.8,8.8.4.4`
**only for the exact default Google URL**; otherwise explicit 1–4 literal
IPs, comma-separated without spaces), and `ZAPRET_AUTOTUNE_DOH_TIMEOUT_SEC`
(default `5`, integer 1–30). Changing provider requires changing **both** URL
and bootstrap IPs. Compose/example leave bootstrap empty, so changing only the
URL cannot silently reuse Google bootstrap. URL must use HTTPS/443 with a path, without userinfo, query
or fragment. A path can contain a private provider token: do not print it.
Validation reports opaque errors before any services start. The subprocess
gets provider configuration through env, never endpoint argv/logging.
Only explicit `ZAPRET_AUTOTUNE_DNS_MODE=native` restores the old resolver
behavior, with no forwarder child. In that mode optional `SS_DNS_SERVER` accepts
only an unbracketed literal IPv4/IPv6 address; empty retains the base resolver.
It is ignored in DoH mode and is **not** a fallback. Native DNS can be plaintext.
The pinned ss-server's native `-d <addr>` is used, not an assumed JSON key;
passwords still go only to private JSON configs. No extra capability is added;
Compose sets container-local `ip_unprivileged_port_start=0` for port 5353.
Managed probes use `socks5h://127.0.0.1:1080`: Player, metadata, image,
media, recovery and warmup hostnames go through the owned SS listener rather than
curl's local DNS. Older private `socks5` overrides are validated and canonicalized
@@ -217,8 +238,13 @@ internally; credentials and unowned endpoints remain forbidden. Public legacy
discovery and root checker local `--resolve` pinning are unchanged.
This corrects a DNS path bypass, not a proven cause of earlier peer certificate
failures, and does not fix/prove all thumbnail routes. It is **not full asset
availability proof**. No DoH bridge, permanent Google IP pins or global host DNS
changes are supplied. PID 1 remains the sole startup/recovery owner.
availability proof**. No permanent service IP pins or global host DNS changes
are supplied. Clients must request remote DNS (browser SOCKS5 remote DNS or
`curl --socks5-hostname 127.0.0.1:11082` when that is the chosen host port).
Client-local resolution and IP-literal requests bypass this hostname DNS path;
the bridge does not encrypt unrelated container processes' DNS. The new DoH
integration still needs remote runtime acceptance; earlier clean-run PASS does
not qualify it. PID 1 remains the sole startup/recovery owner.
Compose has no automatic restart. PID 1 restarts the entire owned runtime only
for technical failures, with three starts per rolling six hours (including initial
@@ -283,7 +309,13 @@ Any startup command failure/timeout exits 78, never the retry code 75. These
bounds do not shorten the monitor's 90-minute bootstrap/recovery scan budget.
SIGTERM/SIGINT cancels and waits for the monitor before stopping target-local
zapret and Shadowsocks children. Nonretry monitor fatal exits stop the
zapret and Shadowsocks children, then terminates/joins DNS within five seconds
and removes only its anchored, validated readiness inode. PID 1 retains private
directory/file descriptors through child death, including SIGKILL. Preexisting,
replaced or symlink readiness evidence is preserved and fails closed rather
than being deleted for a restart. DNS remains available throughout rollback and
SS shutdown. A DNS child crash participates in the existing technical retry
budget; upstream outages do not kill that child. Nonretry monitor fatal exits stop the
entrypoint; technical exits and Shadowsocks failures restart from private configs
only after safe cleanup. Legacy monitor health is YouTube Player API status
through the owned SOCKS, not video playback/SABR; legacy GGC candidates are scoped