fix(setup/onecli): restrict admin API and postgres to loopback after OneCLI install#2434
fix(setup/onecli): restrict admin API and postgres to loopback after OneCLI install#2434glifocat wants to merge 2 commits into
Conversation
…OneCLI install Closes nanocoai#2433 References onecli/onecli#268, onecli/onecli#263
…ECLI_BIND_HOST through compose-up, detect via docker inspect - hardenOneCliBinds now also rewrites ~/.onecli/config.json api-host and ~/.onecli/.env ONECLI_URL when they point at the bridge IP on :10254, so the host admin connection survives the loopback pin. - applyHardenedCompose detects the gateway bind via docker inspect of the running :10255 port (fallback: ~/.onecli/.env) and passes ONECLI_BIND_HOST in the subprocess env so the proxy stays reachable from agent containers. - detectUnsafeOneCliBinds now prefers docker inspect of :10254 as truth and falls back to ~/.onecli/.env, catching shell-set values that .env misses. - Adds 15 new unit tests covering the config.json/.env rewrites, swapHostInAdminUrl, and detection paths via injected inspectFn.
|
Pushed Must-fix 1 — stale admin URLs after the loopback pin
Both are best-effort — if either file is missing or unparseable, we log and continue (the security fix on the compose file has already landed). The gateway port The call site in Must-fix 2 —
Then passes Nit — Reordered the detection to call About the marker on an already-patched compose The marker line is the idempotency signal — a re-run sees it and returns Tests
All tests use an injected cc @nanocoai/maintainers — ready for another pass when you have time. |
Type of Change
.claude/skills/<name>/, no source changes)Description
Closes #2433. References onecli/onecli#268 and onecli/onecli#263.
OneCLI's installer auto-picks the
docker0bridge IP asONECLI_BIND_HOSTon bare-metal Linux, and itsdocker-compose.ymluses that single variable for all three published ports — the proxy gateway (:10255), the admin API (:10254), and Postgres (:5432). The proxy needs to be on the bridge so agent containers can reach it; the admin API and Postgres do not. The net effect is that on a default NanoClaw install on a Linux host, every agent container can read every agent access token via unauthenticated HTTP athttp://<bridge-ip>:10254/api/agents, and can also connect to Postgres directly with the documented default credentials.This PR adds a small post-install step in
setup/onecli.tsthat rewrites the generated compose file to pin:10254and:5432to127.0.0.1, leaving:10255on whatever bind the installer chose. The proxy stays reachable from agent containers; the admin API and Postgres become loopback-only.Filed upstream as onecli/onecli#268 with proposed fixes for the installer + compose template. This downstream patch protects NanoClaw users in the meantime, and remains a useful defense-in-depth step even after upstream lands their fix.
What the patch does
hardenOneCliBinds()does a targeted regex rewrite of the upstream compose, replacing the${ONECLI_BIND_HOST:-127.0.0.1}prefix with a literal127.0.0.1on just the admin and Postgres port lines.# nanoclaw: admin+postgres pinned to loopback (onecli/onecli#268)) at the top of the file so a re-run is a no-op and the source of the change is discoverable.docker compose up -dto reconcile running containers. Failure here is non-fatal; the rewrite has already landed and a subsequent compose-up will pick it up.--reusemode does not rewrite (other apps may depend on the existing bind), but it does read~/.onecli/.env, detect a non-loopbackONECLI_BIND_HOST, and emit a warning +UNSAFE_BINDin the status block so operators see the exposure.emitStatus('ONECLI', ...)gainsHARDENED+HARDEN_NOTEkeys for observability.Tests
setup/onecli.test.tsadds four unit tests that operate on a tempdir copy of the upstream compose shape — no docker calls, no real OneCLI install:127.0.0.1, gateway left untouched, marker prependedreason: already_patched)reason: layout_unrecognized), file untouchedreason: compose_missing)All 327 tests pass locally; typecheck clean.
Why a regex instead of a YAML parser
The upstream compose is small, hand-written, and the lines we care about are exact-match strings. A regex against those exact strings catches drift loudly (we warn and no-op), where a YAML parser would happily round-trip a renamed key and silently do nothing. The marker comment is the durable signal anyone reading the file can find.
Scope
This patch is intentionally narrow. It does not change the OneCLI auth surface (that's upstream #263), and it does not touch the
--remote-urlpath (those installs don't run a local gateway).For Skills