Repository navigation
feat: validate AI Gateway actor and credentials in proxy mode - #30225
Conversation
|
/coder-agents-review |
|
Chat: Review posted | View chat Review historydeep-review v0.13.0 | Round 2 | Last posted: Round 2, 22 findings (3 P2, 8 P3, 6 P4, 5 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #30225Findings
Contested and acknowledgedLaw analysisNot run. Effective additions 236 (threshold 1000). Round logRound 1Round type: round 1, full panel. Multi-domain (credential and input handling). Panel: ging-go, ryosuke, kurapika, takumi (specialists); pariston, mafuuu (core); bisky, gon, leorio, hisoka, mafu-san, chopper (pool); kite (wildcard). 13 reviewers, above the 9-12 target because takumi (context cancellation in serve) was a triggered specialist. Round 2 updateBLOCKED. CRF-19 silent (no reply, About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR adds preflight checks (actor, recorder, credential, WebSocket, firewall headers, declared size) to proxy-mode bridged routes and builds the interception record before the existing 404 stub. Findings: 3 P2, 8 P3, 6 P4, 5 Nit.
The head commit 4f25ef8 is a clean merge of the base branch, but its message test: carry proxy stub expectations into validation describes a test change that does not exist in it. Use the default merge message or rebase.
Out of scope (needs a ticket or explicit acceptance by a human):
aibridge/provider/anthropic.go:216: Anthropic built with a Bedrock config reportsType() == "anthropic", so the router's Bedrock check does not exclude it and BYOK requests passcheckRequest. Only test helpers build this shape today.aibridge/bridge.go:224:InterceptionRecordis now built by two independent field lists (interception and proxy), so a new field must be added in both places and nothing fails when one is missed. A shared constructor requires changingbridge.go.aibridge/provider/provider.go:31: whether a provider can be forwarded in proxy mode is inferred from its type name and credential type instead of asked of the provider, so a new provider variant can be misclassified.
Notes:
aibridge/x/proxy/handler.go:42:servediscards the record and credential; only the unit test reads them until the forwarding slice lands.aibridge/x/proxy/handler.go:81: Claude Platform requests with BYOK or pooled keys pass preflight.claudePlatformTransport.RoundTripsets the requiredanthropic-workspace-idheader, so the forwarding slice needs the provider's transport (asNewPassthroughRouteruses viaPassthroughTransportWrapper).
🤖 This review was automatically generated with Coder Agents.
|
/coder-agents-review |
There was a problem hiding this comment.
Panel review for this round is blocked because one finding has no response: the newForwardingHandler doc comment at aibridge/x/proxy/handler.go:28 still says it "prepares bridged requests before provider-specific handling", but the function only fills a struct (thread PRRT_kwDOGkVX1s6n3WQg). Fix it, or reply explaining why it should stay. The other 22 findings have replies or code changes. The contested ones (502 and 501 statuses and messages, ClientSessionID, the BridgedRoutes guard, the nil recorder check, Claude Platform IAM, and the naming nits) go back to the reviewers who raised them in the next round.
🤖 This review was automatically generated with Coder Agents.
91e01eb to
1e43d48
Compare
95b40d6 to
6417449
Compare
6417449 to
027f798
Compare
e8d590a to
afb06f1
Compare
027f798 to
c2fb367
Compare
28b237f to
ae07413
Compare
c2fb367 to
1a6b56c
Compare
ae07413 to
0d07390
Compare
1a6b56c to
053d24e
Compare
74bc42d to
60b2e22
Compare
Restore rejection logs for WebSocket upgrades, invalid agent firewall headers, and oversized bodies, and log the actor, recorder, and credential rejections without credential values. Document that a nil checkRequest result means the response is written. Assert exact response bodies and logs per rejection, cover malformed firewall session IDs with a sequence number, assert the recorded provider type, and cover rejection and shutdown through the public router.
Assert both keyless and BYOK Bedrock bridged requests return 404 without reaching upstream, and clarify that only Bedrock skips preflight.
053d24e to
6e9ddda
Compare
ssncferreira
left a comment
There was a problem hiding this comment.
Overall LGTM 👍 just a few comments and suggestions
| http.Error(w, "no actor found", http.StatusBadRequest) | ||
| return nil, nil | ||
| } | ||
| if h.recorder == nil { |
There was a problem hiding this comment.
nit: this feels like a setup error and should probably be handled before handling the request? In fact, not sure if having this in checkRequest is the right call 🤔
There was a problem hiding this comment.
Good point, moved check to constructor.
| cred, err := h.provider.ResolveCredential(r) | ||
| if err != nil { | ||
| trace.SpanFromContext(ctx).SetStatus(codes.Error, "failed to resolve credential") | ||
| logger.Warn(ctx, "failed to resolve credential", slog.Error(err), slog.F("path", r.URL.Path)) |
There was a problem hiding this comment.
We should probably include the initiator id in this log.
There was a problem hiding this comment.
Agree, in general fields should not need to be added manually each time.
Changed so logger has fields are added as checks pass. This logger should also be used for later request processing.
| } | ||
| switch cred.(type) { | ||
| case credential.BYOK, *credential.CentralizedPool: | ||
| default: |
There was a problem hiding this comment.
nit: This default case is just for AWS, right? Should we add a TODO linking to the relevant issue?
| // Model: TODO, depends on extractor | ||
| // ClientSessionID: TODO, depends on request buffering | ||
| // CorrelatingToolCallID: TODO, depends on extractor |
There was a problem hiding this comment.
nit: should we link the associated linear issues?
| // providers proxy passthrough routes upstream. Non-Bedrock bridged routes | ||
| // return 404 after validation succeeds. Bedrock bridged routes return 404 | ||
| // without validation regardless of credentials. |
There was a problem hiding this comment.
nit: Is this comment up to date? We are still returning a 501 placeholder
coder/aibridge/x/proxy/handler.go
Line 168 in 6e9ddda
There was a problem hiding this comment.
Thanks, sorry about that. Made comment simpler.
| } | ||
|
|
||
| bridged := newForwardingHandler(prov, logger, m, tracer, inflight, rec) | ||
| bridged := inflight.Middleware(newForwardingHandler(prov, logger, m, tracer, inflight, rec)) |
There was a problem hiding this comment.
With this change, I think we are calling Admit() and RequestContext() twice:
- here via
inflight.Middleware - in handler.go via ServeHTTP:
coder/aibridge/x/proxy/handler.go
Line 52 in 6e9ddda
This will cause 1 request to count as 2. Is this intended?
There was a problem hiding this comment.
Woops, very good catch, it should not be counted twice. Fortunately it would also be doubly released so at least shutdown would still work properly 😅
Removed double admit from Router for bridged routes. Thanks
| return nil, p.err | ||
| } | ||
|
|
||
| func TestForwardingHandlerInterceptionRecord(t *testing.T) { |
There was a problem hiding this comment.
nit: IIUC, this is the success path of checkRequest. Would it make sense to have a single TestCheckRequest with the failure cases (TestForwardingHandlerRejectsRequest) and with the success cases (TestForwardingHandlerInterceptionRecord)?
There was a problem hiding this comment.
Reorganized tests:
- TestCheckRequest
- Rejects
- Record
There was a problem hiding this comment.
Great, that looks great, thanks 🏆
…r fields consistent, removed double admit for bridged requests,comment updates
Extends the AI Gateway
forwardingHandlerwith actor check, provider credential resolution, and initial interception metadata.Missing provider credentials return 403
Credential resolution failures return 500 with details kept in logs.
AWS-signed bridged credentials remain unsupported.
Generated by Coder Agents on behalf of @pawbana.