Serve installers from the hub; document the private-repo install
The repo is private, so anonymous raw URLs return 404. The hub now serves /install-probe.sh (and /install.sh) from its own checkout, open even with UI_PASSWORD, and the Add probe command fetches from there. The installers still ask for a read-only token to clone. Docs use Gitea's "Authorization: token" header and give a git-clone fallback for the hub. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
54a765510a
commit
efd3836945
10 changed files with 60 additions and 24 deletions
|
|
@ -55,3 +55,5 @@ RETENTION_DAYS=14
|
||||||
|
|
||||||
# The hub address shown in probe install commands (default: the address in your browser).
|
# The hub address shown in probe install commands (default: the address in your browser).
|
||||||
HUB_PUBLIC_URL=
|
HUB_PUBLIC_URL=
|
||||||
|
# Where probe install commands fetch install-probe.sh (default: from this hub, /install-probe.sh).
|
||||||
|
PROBE_INSTALL_URL=
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ A home network monitor with two roles, built from one repo:
|
||||||
|
|
||||||
While the hub is unreachable, results queue in memory and upload later. With no `HUB_URL` it is serve-only, e.g. on a VPS.
|
While the hub is unreachable, results queue in memory and upload later. With no `HUB_URL` it is serve-only, e.g. on a VPS.
|
||||||
|
|
||||||
Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). The installers are fetched from `https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/<file>`. That raw URL pattern is an assumption about this Gitea instance; if curl gets a 404, fix it in `install.sh`, `scripts/build-installers.sh`, `app/hub/settings.py` (`DEFAULT_PROBE_INSTALL_URL`) and the README.
|
Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). **The repo is private.** Anonymous requests to its web, API and raw URLs return 404. Machines need a read-only token (`GIT_TOKEN`, saved in their `.env`) to clone and update.
|
||||||
|
|
||||||
|
- **Hub install:** fetch the installer with `curl -H "Authorization: token $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh`. That raw path is assumed from Gitea's URL scheme and hasn't been confirmed with a token yet. If it 404s, `git clone` the repo and run `install.sh` from the clone.
|
||||||
|
- **Probe installs:** fetch `install-probe.sh` from the hub (`http://<hub>:8000/install-probe.sh`, open even with `UI_PASSWORD`). The Add probe dialog builds that command.
|
||||||
|
|
||||||
## Deployment modes
|
## Deployment modes
|
||||||
|
|
||||||
|
|
|
||||||
36
README.md
36
README.md
|
|
@ -57,11 +57,19 @@ Either way, the service starts on boot and restarts if it crashes.
|
||||||
|
|
||||||
### 1. The hub
|
### 1. The hub
|
||||||
|
|
||||||
|
The repo is private, so fetching the installer needs a read-only Gitea token (Settings → Applications → Access tokens, scope `read:repository`). The token is read without echoing it or saving it in history, and the installer reuses it to clone:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh | bash
|
read -rsp 'Gitea token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: token $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Inside an LXC you are root, so that's it. On another Linux machine in native mode, use `| sudo env INSTALL_MODE=native bash`.
|
Inside an LXC you are root, so that's it. On another Linux machine in native mode, use `| sudo -E env INSTALL_MODE=native bash`. If the raw URL gives a 404 even with the token, clone and run the installer instead:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://git.neilbantoc.dev/services/network-monitor.git /tmp/nm && bash /tmp/nm/install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The token is saved in `/opt/network-monitor/.env` (`GIT_TOKEN`) so `update` can fetch. Only the update step sees it, not the running app.
|
||||||
|
|
||||||
Then connect AdGuard Home in `/opt/network-monitor/.env`:
|
Then connect AdGuard Home in `/opt/network-monitor/.env`:
|
||||||
|
|
||||||
|
|
@ -77,19 +85,18 @@ Open `http://<hub-ip>:8000`. The hub listens on the LAN (`HOST_BIND=0.0.0.0`) be
|
||||||
|
|
||||||
### 2. Probes
|
### 2. Probes
|
||||||
|
|
||||||
On the hub, open **Probes → Add probe** and give the probe a name. The hub shows a command with that probe's token. Open the hub at its LAN address, not `localhost`, so the command has a `HUB_URL` the probe can reach. Run it on the probe machine:
|
On the hub, open **Probes → Add probe** and give the probe a name. The hub shows a command with that probe's token. The hub serves the installer itself, so fetching it needs no Gitea access. Open the hub at its LAN address, not `localhost`, so the command has a `HUB_URL` the probe can reach. Run it on the probe machine:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Linux host (Docker), or an LXC as root (native, detected automatically)
|
# Linux host (Docker), an LXC as root (native, detected automatically), or macOS as your user
|
||||||
curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | HUB_URL=http://192.168.1.10:8000 PROBE_TOKEN=... bash
|
curl -fsSL http://192.168.1.10:8000/install-probe.sh | HUB_URL=http://192.168.1.10:8000 PROBE_TOKEN=... bash
|
||||||
|
|
||||||
# Linux, native, not root
|
# Linux, native, not root
|
||||||
curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | sudo env HUB_URL=http://192.168.1.10:8000 PROBE_TOKEN=... bash
|
curl -fsSL http://192.168.1.10:8000/install-probe.sh | sudo env HUB_URL=http://192.168.1.10:8000 PROBE_TOKEN=... bash
|
||||||
|
|
||||||
# macOS: as your own user (it asks for sudo when it needs it)
|
|
||||||
curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | HUB_URL=http://192.168.1.10:8000 PROBE_TOKEN=... bash
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Because the repo is private, the installer asks for a read-only Gitea token on the terminal before it clones. To skip the prompt, put `GIT_TOKEN=...` before `bash`.
|
||||||
|
|
||||||
The probe's test server listens on port 8765 (`PROBE_PORT`) on all interfaces.
|
The probe's test server listens on port 8765 (`PROBE_PORT`) on all interfaces.
|
||||||
|
|
||||||
**Ping on Linux.** Linux needs unprivileged ping allowed (`net.ipv4.ping_group_range`). The installer sets it and persists it in `/etc/sysctl.d/60-network-probe-ping.conf`. That needs root. Without it, the probe skips ping and keeps its HTTP, DNS and throughput checks.
|
**Ping on Linux.** Linux needs unprivileged ping allowed (`net.ipv4.ping_group_range`). The installer sets it and persists it in `/etc/sysctl.d/60-network-probe-ping.conf`. That needs root. Without it, the probe skips ping and keeps its HTTP, DNS and throughput checks.
|
||||||
|
|
@ -108,7 +115,7 @@ pct create 210 local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst \
|
||||||
--net0 name=eth0,bridge=vmbr0,ip=dhcp --unprivileged 1 --features nesting=1 --onboot 1
|
--net0 name=eth0,bridge=vmbr0,ip=dhcp --unprivileged 1 --features nesting=1 --onboot 1
|
||||||
pct start 210 && pct enter 210
|
pct start 210 && pct enter 210
|
||||||
apt update && apt install -y curl # if the template lacks curl
|
apt update && apt install -y curl # if the template lacks curl
|
||||||
curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | HUB_URL=http://<hub-ip>:8000 PROBE_TOKEN=... bash
|
curl -fsSL http://<hub-ip>:8000/install-probe.sh | HUB_URL=http://<hub-ip>:8000 PROBE_TOKEN=... bash
|
||||||
```
|
```
|
||||||
|
|
||||||
- **`nesting=1`:** Debian 12's systemd needs it in an unprivileged container. New containers get it by default on recent Proxmox.
|
- **`nesting=1`:** Debian 12's systemd needs it in an unprivileged container. New containers get it by default on recent Proxmox.
|
||||||
|
|
@ -130,11 +137,10 @@ On the VPS, run `install-probe.sh` with no `HUB_URL` or `PROBE_TOKEN`, and open
|
||||||
|
|
||||||
### Private repo
|
### Private repo
|
||||||
|
|
||||||
If the repo is private, both installers ask for a read-only token. To avoid echoing it or saving it in shell history:
|
- **Fetching:** the hub installer comes from Gitea with a token (above), and probe installers come from the hub.
|
||||||
|
- **Cloning:** both installers clone with `GIT_TOKEN` and ask for it on the terminal if they can't read the repo.
|
||||||
```bash
|
- **Storage:** the token goes into that machine's `.env` for later updates.
|
||||||
read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: Bearer $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash
|
- **Revoking:** use a read-only token per machine, so one can be revoked without touching the others.
|
||||||
```
|
|
||||||
|
|
||||||
## Deploy changes
|
## Deploy changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import secrets
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import APIRouter, FastAPI, HTTPException, Request
|
from fastapi import APIRouter, FastAPI, HTTPException, Request
|
||||||
from fastapi.responses import FileResponse, JSONResponse, Response
|
from fastapi.responses import FileResponse, JSONResponse, PlainTextResponse, Response
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from app.hub import adguard, db, dns, health, probes, settings
|
from app.hub import adguard, db, dns, health, probes, settings
|
||||||
|
|
@ -63,7 +63,7 @@ async def _adguard_error(_req, exc):
|
||||||
return JSONResponse({"detail": str(exc), "code": "adguard_error"}, status_code=502)
|
return JSONResponse({"detail": str(exc), "code": "adguard_error"}, status_code=502)
|
||||||
|
|
||||||
|
|
||||||
OPEN_PATHS = ("/healthz", "/api/probe/report")
|
OPEN_PATHS = ("/healthz", "/api/probe/report", "/install-probe.sh", "/install.sh")
|
||||||
|
|
||||||
|
|
||||||
@app.middleware("http")
|
@app.middleware("http")
|
||||||
|
|
@ -106,6 +106,18 @@ api.include_router(dns.router)
|
||||||
app.include_router(api, prefix="/api")
|
app.include_router(api, prefix="/api")
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent.parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/install-probe.sh", include_in_schema=False)
|
||||||
|
@app.get("/install.sh", include_in_schema=False)
|
||||||
|
def installer(request: Request) -> PlainTextResponse:
|
||||||
|
"""The installers, served from the hub's own checkout so a private repo needs no raw-file
|
||||||
|
access: curl -fsSL http://<hub>:8000/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash"""
|
||||||
|
name = request.url.path.lstrip("/")
|
||||||
|
return PlainTextResponse((ROOT / name).read_text(), media_type="text/x-shellscript", headers={"Cache-Control": "no-cache"})
|
||||||
|
|
||||||
|
|
||||||
@app.get("/healthz", include_in_schema=False)
|
@app.get("/healthz", include_in_schema=False)
|
||||||
def healthz() -> dict:
|
def healthz() -> dict:
|
||||||
return {"status": "ok", "version": VERSION, "role": "hub"}
|
return {"status": "ok", "version": VERSION, "role": "hub"}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
DEFAULT_PROBE_INSTALL_URL = "https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh"
|
# Empty: the probe install command fetches install-probe.sh from the hub itself (/install-probe.sh),
|
||||||
|
# which works for a private repo. Set PROBE_INSTALL_URL to use another location.
|
||||||
|
DEFAULT_PROBE_INSTALL_URL = ""
|
||||||
|
|
||||||
|
|
||||||
def _list(name: str, default: str) -> list[str]:
|
def _list(name: str, default: str) -> list[str]:
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ export function mount(root, ctx) {
|
||||||
|
|
||||||
function installCommand(info, token) {
|
function installCommand(info, token) {
|
||||||
const hub = info.hub_url || location.origin;
|
const hub = info.hub_url || location.origin;
|
||||||
return `curl -fsSL ${info.install_url} | HUB_URL=${hub} PROBE_TOKEN=${token} bash`;
|
const url = info.install_url || `${hub}/install-probe.sh`;
|
||||||
|
return `curl -fsSL ${url} | HUB_URL=${hub} PROBE_TOKEN=${token} bash`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function commandBlock(cmd) {
|
function commandBlock(cmd) {
|
||||||
|
|
@ -87,7 +88,7 @@ function list(root, ctx) {
|
||||||
function showInstall(p) {
|
function showInstall(p) {
|
||||||
const cmd = installCommand(info, p.token);
|
const cmd = installCommand(info, p.token);
|
||||||
const dlg = modal(`Install “${p.name}”`, el('div', { style: 'display:grid;gap:12px' },
|
const dlg = modal(`Install “${p.name}”`, el('div', { style: 'display:grid;gap:12px' },
|
||||||
el('p', { style: 'margin:0' }, 'Run this on the machine that will be the probe. It starts on boot and keeps running. On Linux hosts it uses Docker (installed if needed). On macOS and inside Proxmox LXC containers it installs natively as a system service; there, Linux needs root: put sudo env before HUB_URL.'),
|
el('p', { style: 'margin:0' }, 'Run this on the machine that will be the probe. It starts on boot and keeps running. On Linux hosts it uses Docker (installed if needed). On macOS and inside Proxmox LXC containers it installs natively as a system service; on Linux that needs root, so outside an LXC put sudo env before HUB_URL. If the git repo is private, the installer asks for a read-only token.'),
|
||||||
commandBlock(cmd),
|
commandBlock(cmd),
|
||||||
el('p.small.muted', { style: 'margin:0' }, `The probe reports to ${info.hub_url || location.origin}. If that address isn't reachable from the probe, change HUB_URL in the command. The command is also on the probe's page.`),
|
el('p.small.muted', { style: 'margin:0' }, `The probe reports to ${info.hub_url || location.origin}. If that address isn't reachable from the probe, change HUB_URL in the command. The command is also on the probe's page.`),
|
||||||
), { wide: true, footer: [el('a.btn', { href: `/probes/${p.id}`, onclick: () => dlg.close() }, 'Open probe'), el('button.btn.primary', { type: 'button', onclick: () => dlg.close() }, 'Done')] });
|
), { wide: true, footer: [el('a.btn', { href: `/probes/${p.id}`, onclick: () => dlg.close() }, 'Open probe'), el('button.btn.primary', { type: 'button', onclick: () => dlg.close() }, 'Done')] });
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
# and open PROBE_PORT (default 8765/tcp) in its firewall.
|
# and open PROBE_PORT (default 8765/tcp) in its firewall.
|
||||||
#
|
#
|
||||||
# Private repo over https: add GIT_TOKEN, read without echoing it:
|
# Private repo over https: add GIT_TOKEN, read without echoing it:
|
||||||
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: Bearer $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash
|
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: token $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash
|
||||||
#
|
#
|
||||||
# Two ways to run (INSTALL_MODE):
|
# Two ways to run (INSTALL_MODE):
|
||||||
# docker The probe in a container with host networking. Default on Linux hosts.
|
# docker The probe in a container with host networking. Default on Linux hosts.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
# curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh | sudo bash
|
# curl -fsSL https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh | sudo bash
|
||||||
#
|
#
|
||||||
# Private repo over https (the token is asked for, not typed into history):
|
# Private repo over https (the token is asked for, not typed into history):
|
||||||
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: Bearer $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh | bash
|
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: token $GIT_TOKEN" https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh | bash
|
||||||
#
|
#
|
||||||
# Two ways to run (INSTALL_MODE):
|
# Two ways to run (INSTALL_MODE):
|
||||||
# docker The app in a container (compose). Default on Linux hosts.
|
# docker The app in a container (compose). Default on Linux hosts.
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ out=install-probe.sh
|
||||||
# and open PROBE_PORT (default 8765/tcp) in its firewall.
|
# and open PROBE_PORT (default 8765/tcp) in its firewall.
|
||||||
#
|
#
|
||||||
# Private repo over https: add GIT_TOKEN, read without echoing it:
|
# Private repo over https: add GIT_TOKEN, read without echoing it:
|
||||||
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: Bearer \$GIT_TOKEN" $RAW/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash
|
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: token \$GIT_TOKEN" $RAW/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash
|
||||||
#
|
#
|
||||||
# Two ways to run (INSTALL_MODE):
|
# Two ways to run (INSTALL_MODE):
|
||||||
# docker The probe in a container with host networking. Default on Linux hosts.
|
# docker The probe in a container with host networking. Default on Linux hosts.
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,13 @@ def test_password(hub, monkeypatch):
|
||||||
assert hub.get("/api/info", auth=("admin", "s3cret")).status_code == 200
|
assert hub.get("/api/info", auth=("admin", "s3cret")).status_code == 200
|
||||||
assert hub.get("/healthz").status_code == 200
|
assert hub.get("/healthz").status_code == 200
|
||||||
assert hub.post("/api/probe/report", json={}).status_code in (401, 422) # token auth, not the password
|
assert hub.post("/api/probe/report", json={}).status_code in (401, 422) # token auth, not the password
|
||||||
|
|
||||||
|
|
||||||
|
def test_hub_serves_installers_without_password(hub, monkeypatch):
|
||||||
|
monkeypatch.setenv("UI_PASSWORD", "s3cret")
|
||||||
|
r = hub.get("/install-probe.sh")
|
||||||
|
assert r.status_code == 200 and r.text.startswith("#!/usr/bin/env bash") and "\nNETMON_ROLE=probe\n" in r.text
|
||||||
|
assert "\nNETMON_ROLE=hub\n" in hub.get("/install.sh").text
|
||||||
|
assert hub.get("/api/probes").status_code == 401 # the rest stays protected
|
||||||
|
monkeypatch.delenv("UI_PASSWORD")
|
||||||
|
assert hub.get("/api/probes").json()["install_url"] == "" # UI builds <hub>/install-probe.sh
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue