testsAndMisc/docs/superpowers/evidence/setup-searxng-2026-08-09.json
Krzysztof kuhy Rudnicki 8f2c46de7c
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Add setup_searxng.sh: self-hosted SearXNG at searx.kuhy.duckdns.org
Deploys a SearXNG metasearch instance behind the existing shared Caddy edge.
Graded A+ (score 120, 10/10) by the MDN Observatory API, and "Vanilla" in the
sense that every change is settings-only -- no template or static-file edits.
Public but deliberately not submitted to the searx.space directory.

Both containers run network_mode: host because Docker bridge networking has
zero egress on this box (nftables' default-drop forward chain is terminal at
NF_INET_FORWARD regardless of Docker's legacy-iptables ACCEPTs), so a stock
bridge compose cannot reach a single search engine.

Non-obvious things established empirically against the pinned image, all of
which cost a debugging cycle and are commented at their use sites:

- granian binds :: (all interfaces) by default, NOT the 127.0.0.1 its own docs
  claim; with host networking that would have LAN-exposed the instance.
  GRANIAN_HOST/PORT are the only things pinning it. settings.yml's
  server.bind_address is inert (read only under __main__).
- Caddy's `> Header "v"` is a substring-replace, not a header setter -- it
  silently set nothing. The bare name is "set"; `+` appends and would duplicate
  the headers SearXNG already sends (X-Content-Type-Options, Referrer-Policy).
- server.public_instance force-enables link_token, a browser-proof challenge no
  scripted client can pass, which makes the JSON API unusable. Dropped it and
  kept limiter/image_proxy via their own keys.
- Without limiter.toml there are no trusted_proxies, so botdetection 429s every
  request including the homepage.
- The entrypoint chowns config to uid 977 and needs DAC_OVERRIDE to read it, so
  cap_drop breaks startup and mode 600 breaks the worker's read (640 is right).
- `compose up -d` is a no-op when only a bind-mounted config file changed, so an
  explicit restart is required or every check tests the previous config.
- All curl checks must send browser-shaped headers; bare curl gets 429, which
  had the status command reporting a healthy instance as broken.

Engine pruning is measured, not guessed: brave/duckduckgo/startpage CAPTCHA on
100% of queries, flickr is the 1.0s tail, and pinterest was failing because
this host's own /etc/hosts blackholes it -- a local cause that would otherwise
have been misdiagnosed as a dead upstream.

Measured latency, reported honestly: front page median 19ms, but search median
486ms (233-623ms). Sub-200ms search is not achievable by any configuration --
a metasearch cannot return faster than the slowest upstream it queries. The
~200ms figure on searx.space measures initial front-page response, which is met.

Image pinned by digest: the workarounds above are only known-true for 2026.8.4.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cb77nxXGwFYFM4fyXEQkzG
2026-08-09 17:21:51 +02:00

111 lines
10 KiB
JSON

{
"intent": "Self-host a SearXNG metasearch instance at searx.kuhy.duckdns.org behind the existing shared Caddy edge, configured to earn an A+ Mozilla Observatory grade while remaining 'Vanilla' (settings-only changes, no template/static edits). Publicly reachable but deliberately NOT submitted to the searx.space directory. JSON API enabled for local programmatic/MCP use.",
"scope": [
"NEW: linux_configuration/scripts/single_use/features/setup_searxng.sh (idempotent setup|status|help)",
"Generated at runtime (outside repo): ~/searxng/docker-compose.yml, ~/searxng/core-config/{settings.yml,limiter.toml}, ~/gitea/sites/searx.caddy",
"Non-goal: searx.space listing (user opted out), so 'Vanilla' is a build constraint rather than a graded outcome",
"Non-goal: sub-200ms search latency -- physically unachievable for a metasearch (see verification)",
"Does NOT add a second Caddy, a second DuckDNS updater, or hand-edit /etc/nftables.conf"
],
"changes": [
"Both containers run network_mode: host. Docker BRIDGE networking has zero egress on this host (nftables 'chain forward { policy drop; }' is terminal at NF_INET_FORWARD regardless of Docker's legacy-iptables ACCEPTs), so a stock bridge compose cannot reach a single search engine.",
"GRANIAN_HOST=127.0.0.1 / GRANIAN_PORT=8090 pin the bind. VERIFIED EMPIRICALLY that granian binds :: (all interfaces) by default in this image despite its own docs claiming 127.0.0.1 -- with host networking that would have LAN-exposed it. server.bind_address in settings.yml is inert (read only under __main__/Flask dev server).",
"Caddy snippet sets 5 security headers using the BARE header name ('set' semantics). The '>' prefix is NOT a header setter -- it adapts to {\"replace\":{\"\":[{\"search_regexp\":...}]}} and silently sets nothing; '+' appends and would duplicate. SearXNG sends X-Content-Type-Options and Referrer-Policy itself (its Referrer-Policy is 'no-referrer'), so 'set' is required to override rather than duplicate.",
"limiter.toml written explicitly: without it SearXNG logs 'missing config file' and runs with no trusted_proxies, so botdetection 429s every request including the homepage.",
"server.public_instance deliberately NOT set: it force-enables link_token (a browser-proof challenge no scripted client can satisfy), which makes the requested JSON API unusable. limiter and image_proxy are kept via their own keys.",
"botdetection pass_ip scoped to loopback ONLY, so local tools can use format=json while public traffic (real client IP via X-Forwarded-For) stays rate-limited.",
"start_stack does an explicit docker restart: 'compose up -d' is a no-op when only a bind-mounted config file changed, so without it every verification silently tests the previous config.",
"reclaim_config_ownership: the entrypoint chowns core-config to uid 977, which would make the second setup run fail with 'Permission denied'. settings.yml is 640 not 600 (600 broke the worker's read).",
"No cap_drop on the searxng container -- it needs DAC_OVERRIDE/FOWNER to chown and read config before dropping to uid 977. valkey keeps cap_drop: [ALL] (verified clean).",
"All curl-based checks send browser-shaped headers (UA + gzip Accept-Encoding + Sec-Fetch-*). Bare curl gets 429 from botdetection, so the status check previously reported a perfectly healthy instance as broken.",
"Engine pruning is measured, not guessed: brave/duckduckgo/startpage disabled (CAPTCHA on 100% of queries), flickr (1.0s median), pinterest (blackholed to 0.0.0.0 by this host's own /etc/hosts -- a LOCAL failure that would otherwise be misdiagnosed as a dead upstream)."
],
"verification": [
{
"command": "shellcheck + shfmt -d setup_searxng.sh",
"result": "pass",
"evidence": "Both clean, no findings. bash -n syntax OK."
},
{
"command": "setup_searxng.sh setup (run end to end, repeatedly)",
"result": "pass",
"evidence": "12 [ OK ] lines. Idempotent across 6 consecutive runs; secret_key preserved (verified c72ff7f5e187... survived re-runs)."
},
{
"command": "setup_searxng.sh status",
"result": "pass",
"evidence": "18/18 checks OK: both containers running + loopback-only, valkey PONG, snippet present, DNS resolves, external HTTPS 200, all 5 headers exactly 1, live search 29 results."
},
{
"command": "curl -sI https://searx.kuhy.duckdns.org/ | grep -ci '^<header>:' (x5)",
"result": "pass",
"evidence": "content-security-policy=1 strict-transport-security=1 x-content-type-options=1 referrer-policy=1 permissions-policy=1. referrer-policy value is 'strict-origin-when-cross-origin' (ours) overriding SearXNG's 'no-referrer', proving 'set' semantics work."
},
{
"command": "loopback binding assertion on both containers",
"result": "pass",
"evidence": "searxng 127.0.0.1:8090, searxng-valkey 127.0.0.1:6379. Guard rejects *, 0.0.0.0 AND [::], and demands positive evidence first (fails closed)."
},
{
"command": "real search through public HTTPS with browser headers",
"result": "pass",
"evidence": "HTTP 200, 28 results in 0.90s for 'arch linux'. Post-prune: 20 results/query with unresponsive_engines=[] across 3 queries."
},
{
"command": "JSON API scoping (the decisive check)",
"result": "pass",
"evidence": "Loopback client -> 200 with real JSON results. Simulated public scripted client (X-Forwarded-For set, no Sec-Fetch-*) -> 429. Exactly the intended split."
},
{
"command": "CSP compatibility audit of actual page assets",
"result": "pass",
"evidence": "All CSS/JS/img/manifest same-origin (/static/...). ZERO inline scripts (the single <script> has src= and passes config via a base64 client_settings attribute). ZERO inline style= attributes. Autocomplete is same-origin /autocompleter (200). JS bundle references zero absolute external origins. Image results use data-src=\"/image_proxy?url=...\" (780 occurrences, same-origin lazy-load) -- external URLs appear only as encoded query params, never as fetch targets, so img-src 'self' data: is safe."
},
{
"command": "Mozilla Observatory scan (MDN Observatory API v2)",
"result": "pass -- A+ GRADED, not inferred",
"evidence": "POST https://observatory-api.mdn.mozilla.net/api/v2/scan?host=searx.kuhy.duckdns.org -> {\"grade\":\"A+\",\"score\":120,\"tests_passed\":10,\"tests_failed\":0,\"tests_quantity\":10,\"scanned_at\":\"2026-08-09T15:20:15Z\"}. Score exactly matches the predicted 120 (100 base +10 default-src 'none' +5 frame-ancestors +5 Referrer-Policy)."
},
{
"command": "external ingress proof (ACME cert on disk)",
"result": "pass",
"evidence": "/data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/searx.kuhy.duckdns.org/*.crt exists; openssl s_client shows issuer 'C=US, O=Let's Encrypt, CN=YE1', subject CN=searx.kuhy.duckdns.org, valid Aug 9 - Nov 7 2026. Stock caddy:2.8 has no DNS-provider module, so this had to be HTTP-01 -- i.e. Let's Encrypt's validator reached this host from the public internet on :80. External ingress is therefore verified, not assumed.",
"note": "This is the durable evidence; the gitea-caddy log line had already rotated away."
},
{
"command": "image pinned by digest",
"result": "pass",
"evidence": "searxng/searxng@sha256:f4c8e59de166ed71f6380c0847c312ca51f0d41996e31d0559163b6b09ecde52 (== :latest on 2026-08-09, release 2026.8.4). Confirmed live: docker inspect searxng --format '{{.Config.Image}}' returns the digest. Re-ran setup + status after pinning: 12 [ OK ] / 18 status OK, unchanged."
},
{
"command": "no regression on the shared Caddy edge",
"result": "pass",
"evidence": "All five pre-existing sites still answer after the snippet + reload: kuhy 200, gitea 200, dice 200, kuhy-cloud 401 (its normal auth challenge), kuhy-sync 200."
},
{
"command": "reboot survival",
"result": "pass",
"evidence": "docker/nftables/cronie all 'enabled'; both containers restart=unless-stopped. No systemd unit needed."
},
{
"command": "latency measurement (the backlog note's '~200ms' line)",
"result": "measured, reported honestly -- NOT met for search, and not meetable",
"evidence": "Front page: median 19ms (min 18, max 157) over 10 runs via public HTTPS. SEARCH: median 486ms (min 233, max 623) over 8 distinct queries. Sub-200ms search is not achievable by any configuration -- a metasearch cannot return faster than the slowest upstream engine it queries. The ~200ms figures on searx.space measure initial (front-page) response, which IS met here."
}
],
"risks": [
"JSON API is LOCAL-ONLY by design. format=json works for processes on this host (pass_ip exempts loopback); a scripted client from anywhere else gets 429 because it cannot send Sec-Fetch-* headers. This satisfies an MCP server running on this box, but NOT one calling in from the phone or another machine. Widening it would mean adding that client's IP to pass_ip.",
"NOT YET VERIFIED: real browser load. The strict CSP was validated by static asset analysis, not by a rendering engine (the Chrome extension was not connected and headless chromium produced empty output on this host). A browser load + console check would close this.",
"NOT YET VERIFIED by the user: the phone-on-cellular acceptance test. Note this is now about user acceptance, not about whether the public path works -- see the ACME evidence in verification.",
"brave/duckduckgo/startpage are disabled due to CAPTCHA from this IP. If the IP's reputation changes they could be re-enabled -- re-check with the unresponsive_engines command in settings.yml's comment.",
"pass_ip exempts loopback from ALL botdetection. Any process on this host can query the JSON API unthrottled. Acceptable for a single-user box; would need revisiting if untrusted local services existed.",
"The instance is publicly reachable and will attract scrapers. The limiter mitigates but does not eliminate this."
],
"rollback": [
"docker compose -f ~/searxng/docker-compose.yml down",
"rm ~/gitea/sites/searx.caddy && docker exec gitea-caddy caddy reload --config /etc/caddy/Caddyfile",
"Validate after rollback: the other five sites on the shared edge (gitea, kuhy, dice, cloud, sync) still answer -- the snippet is the only shared-state change, and reload_caddy removes it automatically if caddy validate fails.",
"rm -rf ~/searxng to drop config + the valkey volume (docker volume rm searxng_valkey-data)."
]
}