88b4c00ea11c8653cada22e11edf20ab1594de43
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d9ca84a2f4 |
gateway: built-in TLS, magpie serve/web/daemon install --tls-cert --tls-key, reloaded on renewal (RoderickZH)
magpie serve, magpie web and magpie daemon install take --tls-cert <file> --tls-key <file> (or MAGPIE_TLS_CERT / MAGPIE_TLS_KEY). The gateway and the web UI on its listener then serve HTTPS to other computers. Without them nothing changes. - Half a pair, a file that doesn't parse, or a flag with no value is refused at start with a message naming the missing flag. - The pair is re-read when either file's mtime or size changes (certbot renewal), with no restart. A renewal that doesn't parse keeps the certificate already served and is logged once. - Other computers get HTTPS only. Plain HTTP from them gets net/http's 400 "Client sent an HTTP request to an HTTPS server". - This computer (loopback, or a peer address equal to the local one) may still use plain http on the same port. Its connections are sniffed on their own goroutine (a first byte of 0x16 is TLS) for up to 10s, so a silent client holds nobody else up. gateway.URL() stays http://127.0.0.1:<port>, which agents, MCP servers, ServedBy, the healthcheck and daemon status all use, and no certificate covers loopback. - WSL NAT and containers count as other computers. - ALPN is http/1.1 only (hijacked connections and websockets need it), with TLS 1.2 as the minimum. - Printed links, LAN addresses, publicURL, the serve/web banners and daemon install show https:// for other computers' addresses. - The DNS-rebinding Host checks (foreignPage, rebound, the MCP loopbackHost) don't depend on the scheme and are unchanged. - daemon install carries MAGPIE_TLS_* into the unit or plist. A reinstall or `daemon web on` that names no certificate keeps the installed pair, and --no-tls removes it. - Docs: reference.md gets an HTTPS section that names Caddy as the alternative, gateway-routing.md gets a TLS row, and docker.html (en, zh, ja) gets the env rows. What was run: - New tests: internal/gateway/tls_test.go (others HTTPS-only, this computer both, a silent local client holds no other, renewed certificate served, CheckTLS, addresses, Relisten keeps TLS), internal/cli/tls_cli_test.go and daemon TestInstallCarriesTLS (linux and darwin, paths with space, %, & and "). - Each was broken by hand and went red: no wrap in listen, no reload, a synchronous sniff, a bad renewal dropping the certificate, http in publicURL or the pinned LANURLs, the carried entries removed, and keepTLS as a no-op. - Real use under a sandbox HOME, with a self-signed pair, on 0.0.0.0:3461: - Half a pair, a garbage certificate, a flag with no value, and the env set to half a pair each exit 1 with the message. - curl -k https://127.0.0.1 and https://<LAN IP>/v1/models with a key: 200. Plain http on loopback: 200. - The cert files were swapped for a second pair while it ran. openssl s_client then showed the new CN and serial, and curl --cacert with the new pair got 200. A junk key file then kept the second pair, logged once. - From the Windows box over the LAN: plain http got 400; https with the key got 200, and without it 401. - magpie web --addr 0.0.0.0:3462: https network links. From Windows, http got 400 and https with the key got 303. - gofmt -l clean. go vet passed on darwin, GOOS=linux -tags nogui and GOOS=windows. - go test -tags nogui for ./internal/cli, ./internal/daemon, and the TLS tests of ./internal/gateway and ./internal/gui: all pass at the rebased head. - Two reds in the full suite (`go test -tags nogui ./...`) are the same on origin/main f074996d9; both are filed: - TestGatewayHeldByAContainer failed 2 of 5 there (#2107). - The gateway package runs past go test's default 10m under load: 1208s on main and 1221s here, both passing with -timeout 40m (#2108). |
||
|
|
f64d9312ff |
site, docs: a Privacy page lists everything magpie sends and how to turn it off (#1986)
#1986 asked what the daily count sends, where the id lives and how to stop it. The answer was spread over one README paragraph and the reference. A new page, /docs/privacy (en, zh, ja), lists it from the code: - the daily PostHog batch (internal/stats): a whole example, the label rules for agents/providers/models, partner counts, the $process_person_profile:false flag; - every switch: Settings -> Privacy's two toggles, noStats/noUsageStats, DO_NOT_TRACK / MAGPIE_NO_STATS, noAutoUpdate (About -> Automatic updates), and that a change applies at the next hourly look; - the files: install-id (made at the first send, not at first run, as the issue said) and stats-sent in settings.Dir(), partner-counts.json in the cache folder, their paths per OS and portable, and deleting them; - what usemagpie.ai sees whatever the settings (update feed every 6h, notes, partner list with its 1-in-10 sampled count, /go links, the icon proxy) and the Cloudflare Web Analytics on the site's own pages; - public lists fetched (models.dev, open.er-api.com, npm, GitHub) and providers' quota reads with the user's own accounts; - OTLP export, off by default, its env vars; - why the count stays on by default in releases. Every docs page in all three languages gets a Privacy link in its nav and footer. README (en, zh) and start.html's "What does magpie send about me?" (en, zh, ja) link to the page. docs/reference.md's Files list gains install-id, stats-sent and partner-counts.json, and Counting users says when the id is made, the hourly try, and links the page. Checked against: internal/stats/stats.go, usage.go, provider/partner_events.go, settings (NoStats, NoUsageStats, NoAutoUpdate, UpdateEvery 360, otel.go), appdir, update, fx, catalog, site/worker.js, and the GUI's Settings tabs/labels in index.html, app.js and i18n.js (zh, ja). Run: Playwright (Chromium and WebKit) on all three pages at 1100 and 420 wide, light and dark: no horizontal scroll, no element past the viewport, no page errors (24/24), screenshots looked at for zh at 420 dark. Every href/anchor in site/public/docs resolves; relative links in README and reference resolve. node site/worker.test.mjs passes. Not run: the page on the deployed worker (the site deploys by hand with wrangler, so it is live at the next deploy); the language redirect for /docs/privacy was not exercised beyond the worker's existing tests. |
||
|
|
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.
|
||
|
|
3541ec2fd5 |
gateway, gui: a gateway key's limit can run every N days, and Reset usage counts it from 0 again (#1509, PennyVibe)
PennyVibe asked for a key limit on a cycle of N days rather than a
calendar day, week or month, and for a way to zero a key's usage by
hand. Both are in.
Every N days (N from 1 to 3650):
- access.Limit gains Days and Since. Since is magpie's own: the
limit-key action always works it out, and a value a client sends is
ignored.
- The cycle starts when the limit is set. Each cycle is N×24h of
absolute time from Since, so a restart, a time-zone change or a DST
shift doesn't move it.
- Changing only the caps or "count cache reads" keeps the cycle.
Changing N or the period, or turning the limit on, starts a new
cycle now.
- A hand-written "days" limit with no Since runs from the Unix epoch.
- The GUI window menu offers "Every N days" with a Days field. The CLI
takes `magpie gateway-key limit <id> 10d`. The refusal and status
name the cycle ("for this 1-day cycle").
Reset usage:
- A new action, reset-limit-key, is on the editor's "Reset usage"
button (after a confirm) and on `magpie gateway-key limit <id> reset`.
- It sets Since to now, so tokens and cost both count from 0 together.
- An N-day key starts a new cycle then.
- A day, week or month key keeps its window's end, so it stays on the
calendar. Only the calls before the reset stop counting.
- The usage log is not touched. Authenticate reloads keys each request,
so the reset takes effect at once.
Keys saved before keep their JSON byte for byte (omitzero, nothing
written on load).
Docs: reference.md documents the cycle and reset rules. The docker page
(en, zh, ja) mentions every-N-days.
Run:
- go test -tags nogui ./... with a temp HOME.
- New Go tests:
- TestLimitDaysCycle covers the NY DST, UTC and UTC+8 boundaries.
- TestLimitCalendarReset.
- TestLimitSetAndReset covers keep/restart, an old key's JSON left
untouched, and errors.
- TestKeyLimitDaysCycleAndReset covers the 429 text and header, a
restart, the cycle boundary, and Reset clearing the token and cost
caps together.
- TestKeyLimitCalendarReset.
- TestGatewayKeyLimitCLI covers 10d, reset and bad args.
- Broken by hand: with reset leaving Since alone,
TestLimitSetAndReset, TestKeyLimitDaysCycleAndReset and
TestKeyLimitCalendarReset go red.
- gofmt -l is clean. GOOS=linux and GOOS=windows go vet -tags nogui
pass on ., access, budget, gateway and gui.
- GUI: the new gateway-key-cycle.test.cjs runs in chromium and webkit ×
en, zh, zh-TW, ja and de, with a narrow-width check. Also run, in both
engines: every test using the caller-keys fixture, i18n-keys,
gui-ja, gui-de and gui-zh-tw (80 pass).
- Real use:
- Sandbox magpie (temp HOME, gateway 127.0.0.1:3691, dev UI 3692)
with a fake OpenAI upstream (300+50 tokens a call).
- `gateway-key limit <id> 1d --tokens 700` allowed 2 calls with curl,
then a 429 "for this 1-day cycle" with X-Magpie-Limit-Reset a day
after it was set.
- Pressed Reset usage in the GUI with Playwright and confirmed. The
badge was no longer spent and showed 0 of 700, and curl passed 2
calls again before the next 429.
|
||
|
|
3ee97def30 |
claude: a server or container without Claude Code can have magpie download Anthropic's own build, asked first and checked against its manifest (Jorben)
A Claude subscription signs in and answers through the local `claude`, so
on a server or in the Docker image, which has none, it couldn't be used
(Jorben on Discord: could it be downloaded on first use, as Bun is).
- internal/claudecode: Anthropic's native build, as claude.ai/install.sh
takes it: downloads.claude.ai/claude-code-releases/latest names the
version, its manifest.json the platform's SHA-256 and size (linux
glibc/musl, darwin, win32). A build that doesn't match both is not kept.
It goes to <cache>/claude-code/<version>/claude, one version kept. Find
takes the machine's own claude first, then the download.
- magpie claude-code [install [--yes]|remove]: says the version, platform,
size, the URL it comes from, where it goes, that its checksum is checked
and that it is Anthropic's software under Anthropic's terms, then asks
[y/N]. magpie accounts add claude offers it when there is no Claude Code
(not on Windows, where one in WSL may be the one).
- the gateway's claudeBinary and the sign-in's claudeExecutable take
claudecode.Find; their "not installed" errors name the command.
- Docker docs (en, zh, ja): Claude sign-in needs `docker exec -it magpie
magpie claude-code install` first; kept in /config/cache.
The Dockerfile is unchanged: distroless cc-debian12 has glibc.
Run:
- go test -tags nogui ./... under a temp HOME with pinned caches: all ok
- gofmt -l: none; go vet (darwin), GOOS=linux and GOOS=windows go vet
-tags nogui ./...: clean; darwin, linux, windows builds
- TestClaudeSubscriptionRunsTheDownloadedClaudeCode fails on the old
proc.FindTool lookup ("Claude Code is not installed"); taking the
checksum compare out fails TestInstallRefusesABuildTheManifestDoesntName
- real: magpie claude-code install --yes downloaded Claude Code 2.1.296
darwin-arm64 (230 MB) into a sandbox HOME, checked; it ran --version
- real, in gcr.io/distroless/cc-debian12:nonroot with the image's /config
layout: install downloaded 2.1.296 linux-arm64 (245 MB) to
/config/cache/magpie/claude-code, it ran `2.1.296 (Claude Code)` there,
and magpie accounts add claude went on to print the claude.ai sign-in
link and ask for the pasted address
- the claudecode tests built for linux/arm64 pass in debian:12-slim
|
||
|
|
83c963c466 |
gateway: a gateway MAGPIE_ADDR puts on the network asks callers from other machines, a container's host among them, for an enabled gateway key, as sharing does
What changed - lanGuard: a request whose peer isn't loopback (or that carries a forwarding header) is remote. While the gateway is shared, or MAGPIE_ADDR names a host other than loopback/localhost (OnNetwork: 0.0.0.0 in the Docker image, a server's address), a remote request is answered only with an enabled gateway key, on every route behind the guard; otherwise it is refused (403) as before. Before, a MAGPIE_ADDR on the network with sharing off took remote requests with any key. A remote request let in with a key is marked as shared-mode ones are, so quotas, quota cards, refresh and prices answer it. callerGuard follows the same condition. OpenToAnyone is replaced by OnNetwork. - Loopback is unchanged: any key still works on the gateway's own machine and inside the container (HEALTHCHECK included). - CLI keyNote and the console's Connect note no longer describe an open gateway; on the network they say other machines need a gateway key (`magpie gateway-key add <name>`). The console shows the Gateway keys block and network addresses when OnNetwork (gatewayJSON.onNetwork replaces open); the "Open to the network" strings are removed. - Docs: docker.html (en/zh/ja) and remote.html (en/zh/ja) say callers outside the container need a gateway key, how to make one, that sharing isn't needed for it, and what an upgrade means for agents that sent `magpie`; docs/reference.md and providers-accounts.md likewise. A MAGPIE_ADDR pinned to one interface's address now asks a key of this computer's agents calling that address too (documented). Tests - New TestNetworkGatewayGuardsEveryRoute: from 172.17.0.1 and 192.168.1.9 every registered route (model APIs, count_tokens, systemone, the Responses websocket GET, MCP, Codex backend and catalog, /v1/magpie/*, images, embeddings, rerank, videos, Gemini) gets 401 without a valid key; with one, models and quotas answer 200. - TestNetworkGatewayNeedsAKey (was TestExplicitOpenGatewayAccepts...), TestLANGuard, TestProxiedLoopbackNeedsTheKey, TestQuotasOverLAN, TestMCPProxyStaysHere, session route and remote prices tests, TestOnNetwork, serve_cli and gui public_url tests updated. With the old lanGuard restored, TestNetworkGatewayNeedsAKey, TestNetworkGatewayGuardsEveryRoute, TestLANGuard and TestProxiedLoopbackNeedsTheKey fail. Run - go test -tags nogui -count=1 ./internal/gateway ./internal/gui ./internal/provider . under a temp HOME: ok. - gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on those packages: clean. - GUI: public-url and gateway-caller-keys tests, Chromium and WebKit: 22/22. - Locally built image (OrbStack), -p 127.0.0.1:3481:3425: from the host, /v1/models with no key, `magpie` and another made-up key -> 401; count_tokens and /mcp/x -> 401; a key from `docker exec ... magpie gateway-key add Host` -> models 200, quotas 200; inside the container wget /v1/models -> 200; healthcheck exits 0. `web --addr 0.0.0.0:3430`: /api/state 401 without the web key, 200 with its cookie. |
||
|
|
d86a4e0568 |
site: the docs have Docker and Remote magpie pages in English, Chinese and Japanese, listed in every docs page's contents and footer and linked from the READMEs (HuanCheng Bai on Discord)
Until now, both were only in docs/reference.md. The new pages are at
/docs/docker, /docs/remote and their zh/ and ja/ versions.
- docker: the image, its tags, ports, the /config volume and the nonroot
user. How to run it with the browser UI (`web --addr 0.0.0.0:3430
--no-open`, MAGPIE_WEB_KEY, the ?k= cookie). Signing in through the
Callback URL paste or `docker exec ... magpie accounts add`. What
/config keeps, the env vars, sharing with gateway keys, and a Compose
file for a NAS. Healthcheck and updates.
- remote: sharing the main magpie, then adding it as a Remote magpie
from the app, the TUI (a/w/m) or `magpie provider add remote-magpie
<key> url=... id=office`. What comes over (models, groups, APIs,
images, System One, embeddings, prices, quotas) and the errors magpie
shows, quoted from remote_quotas.go and lan.go.
The facts were checked against the code, not reference.md:
- the Dockerfile ENV, VOLUME, HEALTHCHECK and EXPOSE;
- docker.yml's tags;
- web_cli.go;
- the lanGuard in internal/gateway/lan.go;
- the remote-magpie preset.
The Docker page's warning says a Docker gateway answers anyone until
sharing is on, because MAGPIE_ADDR is 0.0.0.0 there.
The new links in the top nav bar carry a toc-only class:
- docs.js still lists them in the contents;
- the bar keeps today's width, since nine links overflowed it at
1024-1280px.
`.steps li` gets min-width: 0, so a long inline code no longer widens
the grid past a phone's width, where `overflow: hidden` clipped the
text.
Run:
- Real containers from ghcr.io/yetone/magpie:latest (v0.1.1150):
- the documented `docker run ... web` came up healthy, and its log
output is what the page shows;
- with "lan": true, `Bearer magpie` got 401 and a gateway key got 200;
- a second container ran `provider add remote-magpie <key>
url=http://<a>:3425 id=office` and listed office/test-relay/... models.
- `node --test site/*.test.mjs`: 23 pass.
- Playwright, in Chromium and WebKit, at 1280, 1024 and 390, light and
dark:
- no horizontal scroll and no nav overflow on all 20 docs pages;
- every internal link and #anchor resolves. /zh/ and /ja/ are routed
by the worker and return 200 live.
|