sh2/d2ypp2/docs/deploy-hardening.md
eric eb81d824cc Fix ShellCrash :9999 refused connect by hardening geo, YAML, and WG trust.
Strip removed global-client-fingerprint, force 0.0.0.0:9999, fetch GeoDB via jsdelivr when GitHub is blocked, raise start timeout, and allow 10.66.66.0/24 peers; also accept LAN Clash proxies for Neko.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-24 12:25:35 -05:00

77 lines
3.7 KiB
Markdown

# Deploy hardening notes (x86 / ARM)
Lessons from production deploys on Ubuntu (x86_64 and aarch64) behind Soft Router / WireGuard.
## Architecture
Install scripts detect CPU once and reuse labels:
| `uname -m` | ShellCrash `cpucore` | Docker Compose asset |
|------------|----------------------|----------------------|
| `x86_64` / `amd64` | `amd64` | `x86_64` |
| `aarch64` / `arm64` | `arm64` | `aarch64` |
| `armv7*` / `armhf` | `armv7` | `armv7` |
`harden_shellcrash_runtime` refreshes `cpucore` on every install so a copied image cannot keep the wrong binary label.
## ShellCrash dashboard blocked on WireGuard
Symptom: ShellCrash shows online and has YAML, but `http://10.66.66.x:9999/ui/` (or `10.88.0.x`) fails from WG peers while localhost works — or browser shows `ERR_CONNECTION_REFUSED`.
Causes:
1. ShellCrash nftables WAN firewall accepts only physical LAN (`HOST_IP`) then **rejects** `7890` / `9999`. WireGuard overlays are not in that accept set.
2. CrashCore never binds `:9999` because profile validation fails:
- removed top-level `global-client-fingerprint` (new mihomo/meta)
- missing `Country.mmdb` / GeoIP when GitHub downloads time out
Fix in tree:
- `SHELLCRASH_WG_CIDR` / `SHELLCRASH_TRUSTED_CIDRS` (see `config/system-stack.env.example`; defaults include both `10.66.66.0/24` and `10.88.0.0/24`)
- `ensure_shellcrash_proxy_ports_for_docker` also opens dashboard `db_port`
- systemd drop-in `shellcrash.service.d/allow-trusted.conf` + `/usr/local/sbin/shellcrash-allow-trusted.sh` re-applies after every ShellCrash start
- `shellcrash_patch_runtime_yaml` strips `global-client-fingerprint` and forces `external-controller: 0.0.0.0:9999`
- `ensure_shellcrash_geo_databases` pulls GeoSite/GeoIP/MMDB via jsdelivr when GitHub is unreachable
- `shellcrash.service.d/timeout.conf` raises `TimeoutStartSec=600` (bfstart + geo load exceeds 90s)
## Install-time proxy
When the host cannot reach Docker Hub / GitHub / PyPI / Ubuntu archives directly (typical behind GFW with a LAN Clash on Windows):
```bash
export LIVE_HTTP_PROXY=http://192.168.21.36:7897
export LIVE_HTTPS_PROXY="$LIVE_HTTP_PROXY"
export LIVE_NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,*.lan,*.local
sudo -E bash ./install.sh --local-only --profile all
# optional: clear LIVE_* afterwards so runtime stays direct
```
What the installer does when `LIVE_HTTP_PROXY` is set:
1. Exports shell `http(s)_proxy` for curl / apt / pip / git helpers.
2. Writes `/etc/apt/apt.conf.d/99live-proxy` so `apt-get` keeps working in child processes.
3. Writes `/etc/systemd/system/docker.service.d/http-proxy.conf` and reloads Docker **before** Neko/image pulls (daemon does not inherit shell proxy).
4. On Neko `compose up` timeout, re-applies the Docker proxy drop-in and retries once.
Installer downloads for ShellCrash also try with proxy and without (`--noproxy` / unset env).
## WireGuard + Neko
- Overlay address for this fleet is typically `10.66.66.0/24` (腾讯云) or legacy `10.88.0.0/24`.
- `NEKO_ACCESS_MODE=remote` should use the WG address for `NEKO_WEBRTC_NAT1TO1`, not the physical LAN IP.
- `resolve_neko_nat1to1` auto-picks `wg*` / overlay `10.x` when remote mode is set.
- If a WireGuard overlay IP is already present during Neko install, the installer switches to `remote` automatically.
- Applying a WG conf via the hub also switches Neko to remote when the overlay address is ready, and re-runs the ShellCrash trusted-CIDR hook.
## Ports to remember
| Service | Default |
|---------|---------|
| Control plane | `8001` |
| Caddy edge | `80` → `8001` |
| Homepage | `3080` (not `80`) |
| ShellCrash UI | `9999` |
| ShellCrash mixed | `7890` |
| WebTTY | `7681` |
| File Browser | `8082` |