macOS: run the launchd daemon as root so it can reach the LAN
On macOS 15, Local Network privacy blocks LAN connections from a launchd daemon running as a user (EHOSTUNREACH; curl works), and a daemon can't show the permission prompt. Tested on 15.3.1 with the probe's own Python: a root daemon connects to the hub, the same daemon with UserName gets "No route to host". The plist no longer sets UserName. The checkout, venv and <name>-update stay owned by the installing user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
30ce39d5f0
commit
380243545c
4 changed files with 17 additions and 4 deletions
|
|
@ -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 <ctid> -- /usr/local/bin/<name>-update` (full path: `pct exec` runs with a minimal PATH without `/usr/local/bin`) | `pct exec <ctid> -- journalctl -u <name> -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 <name>` |
|
||||
| native, Linux | `/opt/<name>` is the git checkout plus `.venv/`, `data/`, `.env`, `.native`. A systemd unit `<name>.service` runs `native/run.sh` as user `netmon`. | `sudo <name>-update` | `journalctl -u <name> -f` |
|
||||
| native, macOS | Same layout. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc.<name>.plist` runs as the installing user. | `<name>-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt/<name>/data/service.log` |
|
||||
| native, macOS | Same layout, owned by the installing user. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc.<name>.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). | `<name>-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt/<name>/data/service.log` |
|
||||
|
||||
`<name>` is `network-monitor` (hub) or `network-probe`. Mode defaults:
|
||||
- **native** on macOS and inside LXC (detected with `systemd-detect-virt -c`)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <name>-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
|
|||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key><string>$SERVICE</string>
|
||||
<key>UserName</key><string>$SVC_USER</string>
|
||||
<!-- No UserName: the daemon runs as root. macOS 15 Local Network privacy exempts root
|
||||
launchd daemons but blocks LAN connections (EHOSTUNREACH) from a daemon running as a
|
||||
user, and a daemon can't show the permission prompt. Code, venv and updates stay
|
||||
owned by $SVC_USER. -->
|
||||
<key>ProgramArguments</key>
|
||||
<array><string>/bin/bash</string><string>$INSTALL_DIR/native/run.sh</string></array>
|
||||
<key>WorkingDirectory</key><string>$INSTALL_DIR</string>
|
||||
|
|
|
|||
|
|
@ -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("<plist"):setup.index("</plist>")]
|
||||
assert "<key>UserName</key>" not in plist
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue