diff --git a/README.md b/README.md index fc331b0..6a91227 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,15 @@ export SKYG_AUTH__DB_PATH=/tmp/slinuxm-demo/db.sqlite BIN=target/release/slinuxm TOKEN=$($BIN token create demo) # printed once, never stored in plaintext -$BIN serve & # http://127.0.0.1:9109, loopback only +$BIN serve & # http://127.0.0.1:1984, loopback only -curl -s http://127.0.0.1:9109/healthz # public -curl -s -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:9109/api/v1/systemd/units?state=failed' -curl -s -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:9109/api/v1/journal?priority=err&lines=20' -curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:9109/api/v1/docker/ps # 503 if Docker is not running +curl -s http://127.0.0.1:1984/healthz # public +curl -s -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:1984/api/v1/systemd/units?state=failed' +curl -s -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:1984/api/v1/journal?priority=err&lines=20' +curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:1984/api/v1/docker/ps # 503 if Docker is not running ``` -Point an MCP client at `http://127.0.0.1:9109/mcp` with the same bearer header (see [MCP](#mcp)). Stop the server with `kill %1`. +Point an MCP client at `http://127.0.0.1:1984/mcp` with the same bearer header (see [MCP](#mcp)). Stop the server with `kill %1`. The service listens on loopback by default. To reach it from another machine set `server.bind`, keep auth on, and use [TLS](#tls). For a permanent install as a systemd service, see [Install](#install) and [Tokens](#tokens). @@ -80,7 +80,7 @@ Notes: ## REST -Base: `http://127.0.0.1:9109`. Errors are `{"error":{"code","message"}}`. +Base: `http://127.0.0.1:1984`. Errors are `{"error":{"code","message"}}`. | Route | Notes | |---|---| @@ -96,13 +96,13 @@ Base: `http://127.0.0.1:9109`. Errors are `{"error":{"code","message"}}`. ```sh TOKEN=slinuxm_... -curl -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:9109/api/v1/systemd/units?state=failed' -curl -N -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:9109/api/v1/journal/follow?priority=err' +curl -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:1984/api/v1/systemd/units?state=failed' +curl -N -H "Authorization: Bearer $TOKEN" 'http://127.0.0.1:1984/api/v1/journal/follow?priority=err' ``` ## MCP -Endpoint: `http://127.0.0.1:9109/mcp` (Streamable HTTP). Eight tools (`list_systemd_units`, `get_systemd_unit`, `list_systemd_timers`, `get_journal_logs`, `tail_journal`, `list_containers`, `get_container`, `get_container_logs`), two prompts (`diagnose_unit`, `container_health_report`) two resources (`systemd://units/failed`, `docker://containers`) and two resource templates (`systemd://unit/{name}`, `docker://container/{name}`, same JSON as `get_systemd_unit` and `get_container`; percent-encode unusual characters in the name). Log content is untrusted data and is labelled as such in tool results. +Endpoint: `http://127.0.0.1:1984/mcp` (Streamable HTTP). Eight tools (`list_systemd_units`, `get_systemd_unit`, `list_systemd_timers`, `get_journal_logs`, `tail_journal`, `list_containers`, `get_container`, `get_container_logs`), two prompts (`diagnose_unit`, `container_health_report`) two resources (`systemd://units/failed`, `docker://containers`) and two resource templates (`systemd://unit/{name}`, `docker://container/{name}`, same JSON as `get_systemd_unit` and `get_container`; percent-encode unusual characters in the name). Log content is untrusted data and is labelled as such in tool results. Generic client config (header-capable clients): @@ -110,21 +110,21 @@ Generic client config (header-capable clients): { "mcpServers": { "linux-tracker": { - "url": "http://127.0.0.1:9109/mcp", + "url": "http://127.0.0.1:1984/mcp", "headers": { "Authorization": "Bearer slinuxm_..." } } } } ``` -Claude Code: `claude mcp add --transport http linux-tracker http://127.0.0.1:9109/mcp --header "Authorization: Bearer $TOKEN"`. +Claude Code: `claude mcp add --transport http linux-tracker http://127.0.0.1:1984/mcp --header "Authorization: Bearer $TOKEN"`. Inspector: `npx @modelcontextprotocol/inspector`, transport Streamable HTTP, add the bearer header. Raw handshake with curl: ```sh -curl -si -X POST http://127.0.0.1:9109/mcp \ +curl -si -X POST http://127.0.0.1:1984/mcp \ -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \ -H 'Accept: application/json, text/event-stream' \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"curl","version":"0"}}}' @@ -132,7 +132,7 @@ curl -si -X POST http://127.0.0.1:9109/mcp \ ### Origin and Host checks -`/mcp` validates `Origin` and `Host` to defend against DNS rebinding from browsers. Loopback names, `server.bind` and the configured port are accepted by default. Requests without an `Origin` header (non-browser clients) pass this check, so the bearer token remains the real gate. If you bind to `0.0.0.0` or serve behind a name, add the names clients use to `server.allowed_hosts` (for example `["monitor.lan:9109"]`) and any browser origins to `server.allowed_origins`. With `auth.enabled = false` (loopback only), REST requests are checked against a Host allowlist (loopback names, `server.bind` and `server.allowed_hosts`) and get `403` otherwise, to blunt DNS rebinding. There is no Origin check on REST and no token in that mode, so keep auth enabled on any multi-user host. If the host is reachable beyond a trusted network, enable native TLS (see the TLS section) or terminate TLS in a reverse proxy. +`/mcp` validates `Origin` and `Host` to defend against DNS rebinding from browsers. Loopback names, `server.bind` and the configured port are accepted by default. Requests without an `Origin` header (non-browser clients) pass this check, so the bearer token remains the real gate. If you bind to `0.0.0.0` or serve behind a name, add the names clients use to `server.allowed_hosts` (for example `["monitor.lan:1984"]`) and any browser origins to `server.allowed_origins`. With `auth.enabled = false` (loopback only), REST requests are checked against a Host allowlist (loopback names, `server.bind` and `server.allowed_hosts`) and get `403` otherwise, to blunt DNS rebinding. There is no Origin check on REST and no token in that mode, so keep auth enabled on any multi-user host. If the host is reachable beyond a trusted network, enable native TLS (see the TLS section) or terminate TLS in a reverse proxy. ## TLS @@ -155,7 +155,7 @@ Self-signed example: openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days 365 \ -keyout key.pem -out cert.pem -subj '/CN=monitor.lan' \ -addext 'subjectAltName=DNS:monitor.lan,DNS:localhost,IP:127.0.0.1' -curl --cacert cert.pem -H "Authorization: Bearer $TOKEN" https://localhost:9109/api/v1/systemd/units +curl --cacert cert.pem -H "Authorization: Bearer $TOKEN" https://localhost:1984/api/v1/systemd/units ``` Rotation: replace the files and send `SIGHUP` (`kill -HUP $(pidof slinuxm)`, or `systemctl kill -s HUP `). New connections get the new certificate; established ones are not dropped. The certificate and key are read as two separate files, so rotation tooling must send SIGHUP only after BOTH are in place; if the pair is unreadable or mismatched (for example the cert was replaced but the key not yet), the old certificate stays, an error is logged, and you send SIGHUP again once the files are consistent. Any intermediate certificates must be in the `cert_file` chain. Both the TLS and the plain listener are HTTP/1.1 only, share one accept loop, cap concurrent connections at 1024 and close connections that send no request header within 30 seconds. SIGHUP is harmless when TLS is disabled (it is logged and ignored). For ACME, point `cert_file` and `key_file` at the client's output (for example certbot's `live//fullchain.pem` and `privkey.pem`, or the NixOS `security.acme` directory) and send SIGHUP from the renewal hook. For sops-nix or systemd `LoadCredential`, point at the decrypted or credential path (`/run/credentials//...`) so the service user needs no access to the original key file. diff --git a/config.example.toml b/config.example.toml index 80f8e22..e956f89 100644 --- a/config.example.toml +++ b/config.example.toml @@ -8,7 +8,7 @@ [server] bind = "127.0.0.1" # listen address; non-loopback requires auth.enabled = true; SKYG_SERVER__BIND -port = 9109 # listen port; SKYG_SERVER__PORT +port = 1984 # listen port; SKYG_SERVER__PORT allowed_hosts = [] # extra Host header values accepted on /mcp, added to loopback names and bind; SKYG_SERVER__ALLOWED_HOSTS allowed_origins = [] # extra Origin values accepted on /mcp, must include scheme, e.g. "https://app.example.com"; SKYG_SERVER__ALLOWED_ORIGINS diff --git a/plan.md b/plan.md index d1bdfa9..ab5a5c3 100644 --- a/plan.md +++ b/plan.md @@ -70,7 +70,7 @@ The key structural decision: **`sources/` is the only place that talks to D-Bus/ ```toml [server] bind = "127.0.0.1" # set 0.0.0.0 only with auth enabled -port = 9109 +port = 1984 [auth] enabled = true # hard-required when bind != localhost @@ -256,7 +256,7 @@ Solo, do it sequentially: 0 → A → B → C → D → E → F → G → 3. Wit 1. `cargo build` inside `devenv shell`; unit tests for config precedence and DTO mapping. 2. Run locally: `cargo run -- serve --bind 127.0.0.1`; create a token via `cargo run -- token create`. -3. REST: `curl -H "Authorization: Bearer …" localhost:9109/api/v1/systemd/units?state=failed`, SSE follow endpoints via `curl -N`. -4. MCP: point a client at `http://localhost:9109/mcp` (e.g. `npx @modelcontextprotocol/inspector`) — verify tool list, call each tool, check auth rejection without the header. +3. REST: `curl -H "Authorization: Bearer …" localhost:1984/api/v1/systemd/units?state=failed`, SSE follow endpoints via `curl -N`. +4. MCP: point a client at `http://localhost:1984/mcp` (e.g. `npx @modelcontextprotocol/inspector`) — verify tool list, call each tool, check auth rejection without the header. 5. OTel: run `otelcol` with a debug exporter, enable `[otel]`, confirm unit/container gauges appear on the poll interval and journal/docker log records flow with correct severity/attributes. 6. Negative tests: no token → 401; `auth.enabled=false` + `bind=0.0.0.0` → startup refuses; docker socket absent → clean error on docker endpoints, rest of API unaffected. diff --git a/plan/decisions.md b/plan/decisions.md index 08a790b..2a6cfa3 100644 --- a/plan/decisions.md +++ b/plan/decisions.md @@ -108,11 +108,11 @@ The MCP spec requires Origin validation on Streamable HTTP servers. If the pinne --- -## DEC-9 — Port 1984 in the NixOS module, loopback by default +## DEC-9 — Port 1984 by default, loopback by default **Status:** Decided 2026-10-16 -The module defaults `port = 1984` and `bind = "127.0.0.1"`. The binary's own default is unchanged. Exposing the service to the LAN is an install-time choice made in the host's own config, never a default: the operator sets `bind`, `openFirewall` (or an interface-scoped rule) and `allowedHosts` for that deployment. Config validation already refuses auth-off on a non-loopback bind, and a non-loopback bind without TLS logs a warning (see DEC-12). +The binary and the NixOS module both default to `port = 1984` and `bind = "127.0.0.1"` (the binary default was 9109 until 2026-10-16, when the user made 1984 the default everywhere). Exposing the service to the LAN is an install-time choice made in the host's own config, never a default: the operator sets `bind`, `openFirewall` (or an interface-scoped rule) and `allowedHosts` for that deployment. Config validation already refuses auth-off on a non-loopback bind, and a non-loopback bind without TLS logs a warning (see DEC-12). **Decision:** Accepted by the user. The default is loopback. Installs change the relevant settings. diff --git a/plan/workstreams/WS-F-mcp.md b/plan/workstreams/WS-F-mcp.md index 5e916b5..6499cfa 100644 --- a/plan/workstreams/WS-F-mcp.md +++ b/plan/workstreams/WS-F-mcp.md @@ -48,7 +48,7 @@ Tick these in [`TODO.md`](../../TODO.md). ## Done when - F9 passes. -- With P3 wiring, Verification #4 passes. MCP Inspector at `http://localhost:9109/mcp` with a bearer header lists 8 tools, 2 prompts and 2 resources, and every tool returns data. Without the header the client receives 401. +- With P3 wiring, Verification #4 passes. MCP Inspector at `http://localhost:1984/mcp` with a bearer header lists 8 tools, 2 prompts and 2 resources, and every tool returns data. Without the header the client receives 401. ## Notes diff --git a/plan/workstreams/WS-H-nixos.md b/plan/workstreams/WS-H-nixos.md index 25022ce..3f2af8e 100644 --- a/plan/workstreams/WS-H-nixos.md +++ b/plan/workstreams/WS-H-nixos.md @@ -21,7 +21,7 @@ Tick these in [`TODO.md`](../../TODO.md). - **H2** `flake.nix` exporting `packages..default` and `nixosModules.default`, plus `checks` wired to H8. - **H3** `nix/module.nix` options under `services.skyg-linux-tracker`: - `enable`, `package` - - `port` (default **1984**; the app default is unchanged, DEC-9) + - `port` (default **1984**, same as the binary default) - `bind` (default `"127.0.0.1"`; LAN exposure is set per install) - `tls.enable`, `tls.certFile`, `tls.keyFile` (passed via systemd `LoadCredential`, DEC-12) - `openFirewall` (default `false`) @@ -54,7 +54,7 @@ Tick these in [`TODO.md`](../../TODO.md). ## Notes -- Port 1984 is set in the module only, so the non-Nix path is unchanged. +- Port 1984 is also the binary default, so the module just passes it through. - Tokens are printed once and never stored (DEC-11). Declarative/hash-imported tokens and activation-time `bootstrapTokens` are out of scope for v1 are not offered. - The module must not put secrets in the generated TOML. Anything sensitive goes through `environmentFile`. diff --git a/src/config.rs b/src/config.rs index 647376b..dfc929c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -76,7 +76,7 @@ impl Default for ServerConfig { fn default() -> Self { Self { bind: IpAddr::V4(Ipv4Addr::LOCALHOST), - port: 9109, + port: 1984, allowed_hosts: Vec::new(), allowed_origins: Vec::new(), tls: TlsConfig::default(), @@ -351,7 +351,7 @@ mod tests { Jail::expect_with(|_| { let c = load(None, &CliOverrides::default()).unwrap(); assert_eq!(c, Config::default()); - assert_eq!(c.server.port, 9109); + assert_eq!(c.server.port, 1984); assert!(c.auth.enabled); assert_eq!(c.limits.max_lines, 1000); assert_eq!(c.limits.max_follow_secs, 60); @@ -484,6 +484,6 @@ mod tests { .insert("authorization".into(), "secret".into()); let s = c.to_toml_redacted().unwrap(); assert!(!s.contains("secret")); - assert!(s.contains("port = 9109")); + assert!(s.contains("port = 1984")); } } diff --git a/src/mcp/mod.rs b/src/mcp/mod.rs index 62be0af..78ed729 100644 --- a/src/mcp/mod.rs +++ b/src/mcp/mod.rs @@ -835,7 +835,7 @@ mod tests { cfg.server.allowed_origins = vec!["https://mon.example.com".into()]; let st = fake_state(cfg); assert!(allowed_hosts(&st).contains(&"mon.example.com".to_string())); - assert!(allowed_origins(&st).contains(&"http://localhost:9109".to_string())); + assert!(allowed_origins(&st).contains(&"http://localhost:1984".to_string())); assert!(allowed_origins(&st).contains(&"https://mon.example.com".to_string())); let _svc = service(st); } @@ -846,8 +846,8 @@ mod tests { cfg.server.tls.enabled = true; let st = fake_state(cfg); let o = allowed_origins(&st); - assert!(o.contains(&"https://localhost:9109".to_string())); - assert!(o.contains(&"https://127.0.0.1:9109".to_string())); + assert!(o.contains(&"https://localhost:1984".to_string())); + assert!(o.contains(&"https://127.0.0.1:1984".to_string())); assert!(!o.iter().any(|x| x.starts_with("http://"))); } @@ -883,14 +883,14 @@ mod tests { b.body(Body::from(body)).unwrap() }; let r = svc - .call(mk("localhost:9109", Some("http://evil.example"))) + .call(mk("localhost:1984", Some("http://evil.example"))) .await .unwrap(); assert_eq!(r.status(), StatusCode::FORBIDDEN); let r = svc.call(mk("evil.example", None)).await.unwrap(); assert_eq!(r.status(), StatusCode::FORBIDDEN); let r = svc - .call(mk("localhost:9109", Some("http://localhost:9109"))) + .call(mk("localhost:1984", Some("http://localhost:1984"))) .await .unwrap(); assert_ne!(r.status(), StatusCode::FORBIDDEN); diff --git a/src/server.rs b/src/server.rs index 4a42c0f..d692476 100644 --- a/src/server.rs +++ b/src/server.rs @@ -181,7 +181,7 @@ fn allowed_hosts(c: &Config) -> Arc> { Arc::new(v) } -/// Strip an optional port and IPv6 brackets: `[::1]:9109` -> `::1`. +/// Strip an optional port and IPv6 brackets: `[::1]:1984` -> `::1`. fn host_only(h: &str) -> &str { let h = h.trim(); if let Some(rest) = h.strip_prefix('[') { @@ -217,8 +217,8 @@ mod tests { #[test] fn host_parsing() { - assert_eq!(host_only("localhost:9109"), "localhost"); - assert_eq!(host_only("[::1]:9109"), "::1"); + assert_eq!(host_only("localhost:1984"), "localhost"); + assert_eq!(host_only("[::1]:1984"), "::1"); assert_eq!(host_only("::1"), "::1"); assert_eq!(host_only("10.0.0.5"), "10.0.0.5"); }