ac4af582301a4e8a29245dbba767eba31334ddf9
1
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
7a9490638d |
gateway, gui, settings: an IP / CIDR allow list for the gateway, from MAGPIE_ALLOW_IPS or Settings beside Share on local network (lc on Discord)
What changed: lc runs magpie in Docker on a public host and asked that
only some addresses reach it at all. With a list set, a request from an
address outside it is refused 403 ("magpie answers only the addresses on
its allow list ..., and this request came from <addr>: add it there to
let it in") before its gateway key is looked at, so a leaked key is no use from
elsewhere. No list is as before.
- internal/settings/allowips.go: SplitAllowIPs, ParseAllowIP (an IP or a
CIDR range, v4 or v6; zones dropped, v4-mapped unmapped), CleanAllowIPs.
Settings gets AllowIPs (allowIPs).
- internal/gateway/allow.go: MAGPIE_ALLOW_IPS (comma or space separated)
sets the list in place of Settings'. The address judged is the
connection's own (r.RemoteAddr); X-Forwarded-For and the rest are never
believed (magpie has no trusted-proxy list; MAGPIE_TRUST_PROXY never
reads forwarding headers, and this follows it). Loopback and this
computer's own interface addresses always pass. An entry that doesn't
read lets nothing in and is logged once, so a typo never opens magpie
to every address. lanGuard checks it after the OAuth callback and
before the rebound-Host and key checks; `magpie web` is wrapped with
AllowGuard too.
- GUI: Settings > Network shows an "Allowed addresses" row under Share on local
network when sharing is on, the page is open from another computer, or
the env var is set (then read-only, saying so). POST
/api/settings/allowips saves it, refuses it while the env var is set,
refuses an entry that doesn't read, and refuses a list that would shut
out the address the page itself is open from (KeepsOut). The generic
settings save keeps AllowIPs. Strings in zh, zh-TW, ja and de.
- Docs: the Docker page (en, zh, ja) lists MAGPIE_ALLOW_IPS with a note
that a request from the host itself arrives from the bridge's gateway
(172.17.0.1), that Docker Desktop and rootless Docker show clients as
one address of their own, and that behind a proxy every request comes
from the proxy; docs/reference.md and docs/subsystems/gateway-routing.md
describe it. The READMEs list no env vars, so they are unchanged.
Why: a gateway key is the only lock on a public host; an allow list keeps
everyone else from even trying it.
Run (machine load average 75-140 from other sessions, so the large
packages ran in slices of their top-level tests, each slice
-timeout 9m, private GOCACHE, sandbox HOME):
- New tests: internal/gateway/allow_test.go TestAllowList (allowed,
denied, CIDR v4/v6, IPv6 literal, link-local with zone, v4-mapped,
loopback and own address always in, on the list still needs a key,
a typo shuts everything out, env over settings), TestAllowListServed
(a real connection from loopback passes lanGuard under a list naming
nothing of this computer's; a request from elsewhere is 403 naming its
address and MAGPIE_ALLOW_IPS), TestKeepsOut; internal/settings/allowips_test.go
TestCleanAllowIPs; internal/gui/allowips_settings_test.go
TestAllowIPsSetting; internal/gui/tests/allow-ips.test.cjs (14/14 in
chromium and webkit, at a 390px panel, en and zh, keys in zh, zh-TW,
ja and de). Broken by
hand: with lanGuard's check removed TestAllowList and TestAllowListServed
FAIL; with KeepsOut skipped TestAllowIPsSetting FAILs; with renderAllow
not called the GUI test has 5 failures. Restored, all pass.
- internal/gui/settings_keep_test.go gains AllowIPs:
TestSettingsSaveKeepsWhatItDoesNotSend failed without it, as it should
for a new field.
- go test -tags nogui: every package ok. internal/gateway (4 slices),
internal/agent (4), internal/provider (3), internal/gui (2),
internal/plugin (2), the rest whole. GUI Network-settings test files
(11) 98/98 and i18n-keys ok, both engines.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... ok; linux and windows builds ok.
- Not tried: a real Docker container on a public host (the bridge note
is from Docker's docs, not checked here); behind a real reverse proxy.
|