ac4af582301a4e8a29245dbba767eba31334ddf9
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
7a6211d047 |
providers: a model's own headers, in Model settings
axelburks on Discord: a vendor routes one model by a header of its own. A key's provider (built-in or custom) can give each model headers (settings.ModelHeaders["pid/model"]). They go on that provider's requests for that model alone, after the provider's headers and after auth: a name both have is sent once, as the model's, so a user's value is never overridden by the provider's or magpie's key header. The gateway names the model (provider.WithModel) on every route that asks one: chat on each API, translated and streamed, count_tokens, System One's decision, embeddings, images, videos and the model test. A fallback provider serving the same model id gets its own headers only. Accounts and plugins carry their sign-in's headers and take none. The editor's "Name, price and reasoning level" panel is now "Model settings" (every language), with + Add header per model, staged and made with the Save; Restore default takes them away. The rows being typed are kept out of the draft's compare, so an untouched editor still closes without asking. Broken by hand: dropping WithModel from gateway.go turns TestModelHeadersReachTheirModelOnEveryRoute red; dropping the provider id check in modelOf turns TestModelHeadersStayWithTheirProvider red. Run, on this stack over origin/main |
||
|
|
7d196b6797 |
gateway: what a proxy says of the caller reaches no vendor, ChatGPT backend or MCP server
Behind Tailscale Serve, a Cloudflare Tunnel or another reverse proxy, the request magpie gets carries what the proxy says of the caller: Tailscale-User-Login, -Name and -Profile-Pic (the user's email, name and picture), True-Client-IP, X-Forwarded-*, Cf-*. The native route dropped X-Forwarded-*, Forwarded, Cf-*, X-Real-Ip and Via, but not True-Client-IP or any Tailscale-*, even though lanGuard itself reads True-Client-IP and Tailscale-User-Login as forwarded (forwardHeaders). The Codex passthrough and relay to the ChatGPT backend (copyHeaders) and the MCP proxy dropped none of them. proxyIdentity names them once: every forwardHeaders entry; any X-Forwarded-*, Cf-* and Tailscale-*; Forwarded, Via, X-Real-Ip, True-Client-Ip, X-Client-Ip and X-Original-Forwarded-For. nativeHeaderDropped, copyHeaders and the MCP proxy's header loop all skip them. The caller's other headers still go on. Checked and left as they are: a provider's PassHeaders (names the user chose), Codex's allow-listed codexHeader, the Codex websocket's headers and passOnCaller. Tests: TestNativeAnyDropsProxyIdentity (native route, under MAGPIE_TRUST_PROXY) and TestPassthroughDropsProxyIdentity (Codex relay through copyHeaders, and /mcp/<server>). Each sends twelve identity headers and checks that none arrive and that X-Custom still does. Broken by hand: with native.go, codex_backend.go and mcp.go at their parent, both tests are red. The native vendor was told True-Client-IP and the three Tailscale-User-* headers. The ChatGPT backend and the MCP server were told all twelve. Run on mote at the pushed head 883690a0b (this commit and the one before, on origin/main |
||
|
|
8a80796805 |
gateway: the native route passes any path of a keyed provider's own API on, at its host
axelburks (Discord #feedback) asked for /v1/magpie/native/<provider>/... to reach the whole of a vendor's API, not only Ark's image and video task paths. Now GET, POST, PUT, PATCH and DELETE of /v1/magpie/native/<provider>/<path> go to the provider's host at /<path> (not under the base's /v1 or /api/v3), with the query and body as they came and the answer streamed back as it comes. Guards: - API-key providers only (nativeKeyed): no subscription, OAuth or plugin account, no remote magpie, no Vertex. 403 otherwise. - The gateway's own guards as every route: lanGuard's Host check, corsGuard (foreign Origin, null, *.localhost without a key), a key beyond loopback, read-only keys refused (PUT/PATCH added to readOnlyRefused), and a key held to models/accounts/limits refused (nativeHeld, as before). - nativeTarget refuses an empty path, "." / ".." segments (encoded too, across %2F), a backslash, a (encoded) leading slash, "://", a scheme-like first segment, and any URL whose host or scheme parsed back isn't the base's. 400, vendor not asked. - The caller's Authorization, x-api-key, api-key, x-goog-api-key, Cookie, ?key=, Origin/Referer/Sec-*/X-Forwarded-*/Cf-*, hop and X-Magpie-* headers are dropped; Sign puts the provider's key in the way it takes one. Set-Cookie, Alt-Svc and HSTS don't come back. - With masking on, a JSON body is masked (fails closed) and restored in the answer; a non-JSON body is a 415. Only a masked request's answer goes through restoring; every other answer streams in 32KB reads, never held whole. - Each request is a Requests row and a usage record (Operation "native"), with tokens when a JSON or SSE answer reports them. - Ark's short paths (nativeArkPath) keep their old code path, under the key's base, unchanged (nativeArk). Docs: gateway-routing.md (table row, native route section), reference.md (path table + paragraph), integrating.md, site integrate.html en and zh. Run (mote, darwin arm64, Go 1.26.8): - go test -count=3 -run 'Native|ReadOnly' ./internal/gateway: ok - go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., gofmt -l: clean - Rebased on origin/main |
||
|
|
db87e014f2 |
gateway: /v1/magpie/native/<provider>/<path> passes Ark's own images and video-task API on
axelburks on Discord asked for a way to reach what the OpenAI-shaped
routes can't carry: Ark's image stream, its task list and cancel, a
field newer than magpie. A coordinator asked for it to stay behind the
gateway's key and auth like every route, and for the design to be said.
Decided:
- One route, /v1/magpie/native/{provider}/{path...} (POST, GET, DELETE),
for Volcengine Ark only (isArk, not a remote magpie), at the paths it
makes images and videos at: POST images/generations; POST/GET
contents/generations/tasks (with Ark's query); GET/DELETE
contents/generations/tasks/<id> (nativeArkPath). Never Ark's chat,
whose routing, usage and masking are the chat routes'. Another
provider or path is a 404 that says what is served.
- Behind every guard a /v1 route has (a key beyond loopback, corsGuard,
the key's rate), and refused to a read-only key (readOnlyRefused).
- Refused (403) to a key held to models, accounts or a spend limit, or
issued by one (nativeHeld): a poll or a cancel can't be tied to a
model, and magpie prices no answer it doesn't read, so it couldn't
hold such a key to them. Such keys use /v1/images/generations and
/v1/videos, which now pass the vendor's own fields on.
- A model the user switched off is refused. The body's strings are
masked (fails closed) and put back in the answer (restoring); numbers
go exact (UseNumber, a 17-digit seed is kept).
- Signed with the provider's key and magpie's User-Agent; no caller
header goes on but Accept. The answer comes back as it came, an event
stream flushed as it arrives.
- Each request is a Requests row and a usage record (Operation
"native", no tokens).
Tests: TestNativeArkRoute (the stream, the task list's query and a
cancel reach Ark signed with the provider's key, the body as sent; chat,
a wrong method, a deeper path, another provider, an unknown one and
every held key are refused without Ark being asked),
TestNativeArkStreamsAsItComes (the first event reaches the caller while
Ark holds the rest), TestReadOnlyKeyEveryRoute (the three patterns in
readOnlyRefused). Docs: gateway-routing.md's native route section.
Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on
|