diff --git a/CLAUDE.md b/CLAUDE.md index ef05d6d..2aee477 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -29,7 +29,7 @@ Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). The r | lxc (Proxmox node) | A container made by the installer; inside it, the same as native Linux. | `pct exec -- /usr/local/bin/-update` (full path: `pct exec` runs with a minimal PATH without `/usr/local/bin`) | `pct exec -- journalctl -u -f` | | docker | `compose.yml` (hub, bridge, port 8000) / `compose.probe.yml` (probe, `network_mode: host`). The image is runtime only; the source is cloned into a volume. | `docker exec network-monitor update` / `docker exec network-probe update` | `docker logs -f ` | | native, Linux | `/opt/` is the git checkout plus `.venv/`, `data/`, `.env`, `.native`. A systemd unit `.service` runs `native/run.sh` as user `netmon`. | `sudo -update` | `journalctl -u -f` | -| native, macOS | Same layout. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc..plist` runs as the installing user. | `-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt//data/service.log` | +| native, macOS | Same layout, owned by the installing user. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc..plist` runs the app as **root**: macOS 15 Local Network privacy blocks LAN connections from a daemon running as a user (`[Errno 65] No route to host` while curl works), and root daemons are exempt (tested on 15.3.1). | `-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt//data/service.log` | `` is `network-monitor` (hub) or `network-probe`. Mode defaults: - **native** on macOS and inside LXC (detected with `systemd-detect-virt -c`) diff --git a/README.md b/README.md index 45ef46d..9fb55ce 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,9 @@ Docker also changes the firewall: its rules and a `DROP` policy on the `FORWARD` ### Mac mini 1. Run the probe command above as your user. It needs the Xcode Command Line Tools (`xcode-select --install`) and Python 3.11+. If Python is missing, it installs `python@3.13` with Homebrew. -2. It installs a LaunchDaemon (`/Library/LaunchDaemons/dev.neilbantoc.network-probe.plist`) that runs as your user from boot, with no login needed. +2. It installs a LaunchDaemon (`/Library/LaunchDaemons/dev.neilbantoc.network-probe.plist`) that runs from boot, with no login needed. + - **It runs as root.** On macOS 15, Local Network privacy blocks a background service running as your user from reaching LAN addresses: you'd see `No route to host` while `curl` works. A service running as root is exempt, and a background service can't show the permission prompt. + - **Your user still owns** the checkout, the Python environment and updates. 3. Logs go to `/opt/network-probe/data/service.log`. 4. Keep the Mac awake. In System Settings → Energy, turn on "Prevent automatic sleeping", or the probe stops while the Mac sleeps. diff --git a/native/setup.sh b/native/setup.sh index 2a02f4f..5d890ae 100755 --- a/native/setup.sh +++ b/native/setup.sh @@ -48,7 +48,7 @@ ensure_python() { if [ "$(uname -s)" = Darwin ]; then PLATFORM=launchd SERVICE="dev.neilbantoc.$NAME" - SVC_USER=$(id -un) + SVC_USER=$(id -un) # owns the checkout and runs -update; the daemon itself runs as root [ "$SVC_USER" != root ] || native_die "on macOS, run the installer as your own user, not with sudo" else PLATFORM=systemd @@ -125,7 +125,10 @@ else Label$SERVICE - UserName$SVC_USER + ProgramArguments /bin/bash$INSTALL_DIR/native/run.sh WorkingDirectory$INSTALL_DIR diff --git a/tests/test_installers.py b/tests/test_installers.py index 98e49fb..b050bfc 100644 --- a/tests/test_installers.py +++ b/tests/test_installers.py @@ -150,3 +150,11 @@ def test_explicit_port_wins_over_lan_default(tmp_path): pick = 'CALLER_MODE=; choose_mode; if [ "$ROLE" = hub ] && [ -z "$CALLER_PORT" ] && uses_lan_name; then HOST_PORT=80; fi; echo "$MODE $HOST_PORT"' assert bash(base + 'CALLER_PORT=; HOST_PORT=8000; ' + pick, INSTALLER="install.sh").stdout.strip() == "native 80" assert bash(base + 'CALLER_PORT=9000; HOST_PORT=9000; ' + pick, INSTALLER="install.sh").stdout.strip() == "native 9000" + + +def test_macos_daemon_runs_as_root(): + """macOS 15 Local Network privacy blocks LAN connections from a launchd daemon that runs + as a user; root daemons are exempt. The plist must not set UserName.""" + setup = (ROOT / "native" / "setup.sh").read_text() + plist = setup[setup.index("")] + assert "UserName" not in plist