Repository navigation
Gateway: send each engine its own key, never the node's - #126
Merged
Merged
Conversation
Red: an engine without its own credential receives the client's node key. It is the client's credential for this gateway, not for the engine.
… node's The guard checks the client's node key and the reverse proxy passed that header on, so every engine, its logs and any proxy in front of it saw the node's API key. One engineEntry now finds the configured entry behind a target (its own entry when the gateway may start it, otherwise the entry whose url is the target's; a discovered engine has none), and engineAuth sets the engine's own bearer from api_key_env or api_key_file on every proxied route: forward for the primary and, on a fallback switch, for the fallback, and the ComfyUI routes. An engine without a credential, or a credential that will not resolve, gets no Authorization; the latter logs one WARN line naming the engine and the error, never the key. The request goes through either way.
An engine without a credential receives no Authorization; one with api_key_env receives its own bearer; a fallback with its own key receives that key; the ComfyUI routes receive none; a credential that will not resolve sends nothing and logs one WARN line naming the engine and the error, never the key.
One paragraph next to the API key bullet: a proxied request carries the engine's own key from its entry when it has one, none otherwise, and a credential that will not resolve logs one WARN line, never the key. The fallback section says the same of a fallback with its own key, and the CHANGELOG gains a Security entry that tells a user whose engine checked the node's key to give that engine its own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OME GWV6JQR, found while reviewing #114.
Clients authenticate to the gateway with the node's API key. The reverse proxy passed that
Authorizationheader on to every engine, so each engine, its logs and any proxy in front of it saw the node key, and an engine with its own credential got the wrong one. #114 dropped it on the fallback hop only.Every proxied route now goes through one function,
engineAuth. It removes the client's header and sends the engine's own key when its entry has one (api_key_envorapi_key_file). This covers the OpenAI routes, the fallback,POST /promptand the rest of the ComfyUI routes. A discovered engine with no entry gets noAuthorization. A credential that will not resolve sends none and logs one WARN line that names the engine and the error, never the key.Who notices: anyone whose engine checked the node's key. They need to give that engine its own key in
berth.toml. The CHANGELOG says so under a new Security heading.Proof:
TestProxySendsNoKeyToACredentiallessEngineandTestComfyRoutesSendNoKeyfail against main's gateway (the engine receives the node key) and pass with this change.go test ./...,go test -race ./internal/gateway, Windows build and vet, golangci-lint (0 issues).mkdocs build --strictpasses.