diff --git a/.gitignore b/.gitignore index 35e9e92..52f38fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ data/ .venv/ +.deploy.env diff --git a/CLAUDE.md b/CLAUDE.md index 441affb..f01a165 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,8 +21,8 @@ See `README.md` for what this is and how it's deployed. This file is how to exte 3. **Server side, only if needed:** add `app/tools/.py` exposing `router` (a FastAPI `APIRouter`) with routes under `/api//…`, and optional `async startup()`/`shutdown()`. `main.py` mounts every module in `tools/` automatically. Persistent files go under - `$DATA_DIR` (`/data`, bind-mounted from `/opt/tools/data`). Keep it light: this runs on the - shared server (container capped at 192 MB / 0.5 CPU). + `$DATA_DIR` (`/data`, bind-mounted from `/opt/tools/data`). Keep it light: it shares a small + server with other workloads (container capped at 192 MB / 0.5 CPU). 4. Prefer running in the browser. Vendor any library into `static/vendor/` (pinned version in the filename comment or README); the CSP allows scripts from `'self'` only, no CDNs. @@ -42,3 +42,6 @@ See `README.md` for what this is and how it's deployed. This file is how to exte the initial page light (the server's upstream is slow). - Run `node --test tests/` and check the page in a browser before deploying; `deploy.sh` refuses to deploy if the tests fail. +- **This repo is public. Never commit anything about the machines it runs on**: no IPs, SSH + targets, hostnames, providers, network layout or tunnel setup. The deploy target lives in the + gitignored `.deploy.env`; operational notes belong in the private homelab docs. diff --git a/README.md b/README.md index bf58180..12a0e2d 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,12 @@ docker run --rm --network host -e PORT=18090 -v "$PWD/data:/data" tools:dev ## Deploy ```sh -./deploy.sh # HOST=root@ -HOST=root@ ./deploy.sh +HOST=root@ ./deploy.sh # or put HOST=… in .deploy.env (gitignored) ``` On the server: `/opt/tools/{compose.yml,app/,data/}`, container `tools`, listening on -`127.0.0.1:8090` only. Put a reverse proxy or tunnel connector -on the same host in front of it. +`127.0.0.1:8090` only, so put a reverse proxy or tunnel connector on the same host in front of it. +It trusts `X-Forwarded-For` from loopback only, which is what makes the per-IP paste limit work. ## Pastebin limits diff --git a/app/tools/paste.py b/app/tools/paste.py index 5448c3c..1e9bb6b 100644 --- a/app/tools/paste.py +++ b/app/tools/paste.py @@ -90,8 +90,8 @@ async def shutdown(): def client_ip(request: Request) -> str: - # uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind - # a reverse proxy that connects over loopback this is already the visitor's address. + # uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind a + # reverse proxy that connects over loopback this is already the visitor's address. return request.client.host if request.client else "" diff --git a/compose.yml b/compose.yml index 97d2a2f..1cc1bde 100644 --- a/compose.yml +++ b/compose.yml @@ -1,5 +1,5 @@ -# Host networking + loopback bind: only a proxy or tunnel on the same host can reach it. -# It listens on 127.0.0.1:8090. +# Host networking + loopback bind: only a reverse proxy or tunnel connector on the +# same host can reach it (127.0.0.1:8090); nothing is exposed directly. name: tools services: tools: @@ -13,7 +13,7 @@ services: PORT: "8090" volumes: - ./data:/data - # Small and capped: it shares a small server with other workloads. + # Small and capped, so it can share a small server with other workloads. mem_limit: 192m cpus: 0.5 read_only: true diff --git a/deploy.sh b/deploy.sh index e6ac9db..94aba83 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,12 +1,13 @@ #!/usr/bin/env bash # Deploy this checkout (including uncommitted changes) over SSH: # HOST=root@ ./deploy.sh -# HOST=root@ ./deploy.sh # elsewhere +# or put HOST=root@ in .deploy.env (gitignored; keep server details out of the repo). # Copies app/ and compose.yml to /opt/tools, rebuilds and restarts the container, # then waits for it to report healthy. Paste data in /opt/tools/data is kept. set -euo pipefail -HOST=${HOST:?set HOST=root@} cd "$(dirname "$0")" +[ -z "${HOST:-}" ] && [ -f .deploy.env ] && . ./.deploy.env +[ -n "${HOST:-}" ] || { echo "usage: HOST=root@ $0 (or set HOST in .deploy.env)" >&2; exit 1; } node --test tests/ >/dev/null || { echo "tests failed; not deploying" >&2; exit 1; } tar -czf - --exclude=__pycache__ --exclude=data app compose.yml | ssh "$HOST" 'set -e; mkdir -p /opt/tools && rm -rf /opt/tools/app && tar --no-same-owner -xzf - -C /opt/tools'