Skip to content

feat: validate AI Gateway actor and credentials in proxy mode - #30225

Merged
pawbana merged 6 commits into
mainfrom
pawel/issue-29726-validation
Oct 7, 2026
Merged

pawbana merged 6 commits into
mainfrom
pawel/issue-29726-validation

Conversation

@pawbana

@pawbana pawbana commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Extends the AI Gateway forwardingHandler with 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.

@pawbana

pawbana commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-10-01 09:04 UTC by @pawbana

Review history
  • R1 (2026-10-01): 13 reviewers, 5 Nit, 3 P2, 8 P3, 6 P4, COMMENT. Review
  • R2 (2026-10-01), 5 Nit, 3 P2, 8 P3, 6 P4, COMMENT. Review

deep-review v0.13.0 | Round 2 | 92337c0..95b40d6

Last posted: Round 2, 22 findings (3 P2, 8 P3, 6 P4, 5 Nit), COMMENT. Review

Finding inventory

Finding inventory: PR #30225

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Open handler.go:21 logger field unused; all rejections silent, three previously logged, ResolveCredential error dropped R1 Netero Yes
CRF-2 P3 Open handler.go:32 serve duplicates InflightGate.Middleware; 503 branch untested R1 Netero Yes
CRF-3 P3 Open handler.go:78 Missing credential returns 502 though no upstream contacted; SDKs retry 5xx R1 Netero, Chopper (Note evidence) Yes
CRF-4 P3 Open handler.go:87 Record omits ClientSessionID that interception path sets R1 Netero, Ryosuke Yes
CRF-5 P4 Open router.go:66 len(BridgedRoutes()) > 0 clause has no effect R1 Netero Yes
CRF-6 P4 Open handler.go:72 rec == nil branch unreachable from production caller R1 Netero Yes
CRF-7 Note Note (body) handler.go:42 checkRequest return values used only by tests R1 Netero No
CRF-8 P4 Open handler_internal_test.go:115 Rejection tests check status only, not message R1 Netero Yes
CRF-9 OOS Out of scope (body) aibridge/provider/anthropic.go:216 Anthropic with Bedrock config reports Type anthropic, bypassing router Bedrock check; only test helpers build it R1 Netero, Ryosuke No
CRF-10 P2 Open router.go:66 Bedrock bridged routes skip WebSocket/firewall/size checks and return generic 404; contradicts PR description and NewRouter doc R1 Mafu-san P2, Mafuuu P3, Leorio P3, Gon P3, Ryosuke Nit Yes
CRF-11 P3 Open router.go:66 Forwardability split across router type-name check and credential switch; Bedrock BYOK passes checkRequest and is untested R1 Kite P3, Ryosuke P3 Yes
CRF-12 P2 Open handler.go:81 AWSSigV4 rejection makes every bridged request to Claude Platform IAM 501, though passthrough already signs that provider R1 Pariston Yes
CRF-13 P3 Open handler.go:84 501 message misstates restriction, omits BYOK workaround; SDKs retry 5xx R1 Leorio P3, Chopper P3 Yes
CRF-14 P3 Open handler.go:78 "upstream authentication unavailable" hides ErrNoCredential cause from client R1 Leorio P3, Chopper P3 Yes
CRF-15 P3 Open handler.go:42 No test fails if serve ignores checkRequest rejection R1 Bisky Yes
CRF-16 P4 Open handler_internal_test.go:154 Metadata test does not assert record.Provider R1 Bisky Yes
CRF-17 P4 Open handler_internal_test.go:83 Rejection test uses name list plus switch instead of struct table R1 Bisky P4, Mafu-san Nit Yes
CRF-18 P3 Open handler.go:50 checkRequest name reads as predicate; no doc on nil-means-written contract R1 Gon P3, Leorio P4 Yes
CRF-19 P4 Open handler.go:26 newForwardingHandler doc describes request handling for a constructor R1 Gon Yes
CRF-20 Nit Open backend_test.go:189 Test doc comment restates assertions R1 Gon Yes
CRF-21 Nit Open handler.go:55 firewallID/firewallSequence diverge from codebase names R1 Gon Yes
CRF-22 Nit Open handler_internal_test.go:64 recordedRequest helper name R1 Gon Yes
CRF-23 Nit Open handler_internal_test.go:94 Firewall case tests missing-sequence branch, not invalid UUID R1 Gon, Chopper Yes
CRF-24 Nit Open router_test.go:215 Bedrock test name uses "Disabled" for an enabled provider R1 Gon Yes
CRF-25 P4 Note (body) commit 4f25ef8 Merge commit carries a test-change message with no content R1 Mafu-san P4, Leorio Nit No
CRF-26 Note Note (body) handler.go:81 Claude Platform BYOK/pool requests need provider transport for workspace header when forwarding lands R1 Hisoka No
CRF-27 OOS Out of scope (body) aibridge/bridge.go:224 InterceptionRecord construction duplicated between interception and proxy paths; shared constructor needs bridge.go change R1 Ryosuke No
CRF-28 OOS Out of scope (body) aibridge/provider/provider.go:31 Proxy forwardability should be a provider-owned capability R1 Ryosuke No
CRF-29 Note Dropped by orchestrator (verification note, no action) handler.go:76 ResolveCredential safe because Coder headers stripped first R1 Pariston No
CRF-30 Note Dropped by orchestrator (praise, no action) router_test.go:198 Stub test enforces no forwarding R1 Kite No
CRF-31 Note Dropped by orchestrator (verification note, no action) router_test.go:215 Bedrock test detects removal of the clause R1 Bisky No
CRF-32 Note Dropped by orchestrator (verification note, no action) handler_internal_test.go:112 Rejection cases isolate each check R1 Chopper No
CRF-33 Note Dropped by orchestrator (verification note, no action) handler_internal_test.go:131 No-body-read claim backed by tests R1 Mafu-san No
CRF-34 Note Dropped by orchestrator (praise, no action) router_test.go:201 Failure messages give reason R1 Leorio No
CRF-35 Note Dropped by orchestrator (comment audit, no action) handler.go:46 TODO comment audit R1 Gon No

Contested and acknowledged

Law analysis

Not run. Effective additions 236 (threshold 1000).

Round log

Round 1

Round 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.
Netero first pass: 1 P2, 3 P3, 2 P4, 2 Note, 1 OOS. Panel added CRF-10 to CRF-35. Convergent: CRF-10 (5 reviewers), CRF-11 (2), CRF-13, CRF-14 (2 each).
Downgrades: CRF-19 Gon P2 to P4 (keep-argument: misleading doc on the handler entry point; drop reason: unexported one-line constructor doc with no behavior consequence). CRF-20 Gon P2 to Nit (keep-argument: AGENTS.md requires substantive comments; drop reason: test-intent comment, no consequence). CRF-8 Netero Note to P4 because it asks for a change. CRF-25 moved to body as process observation (commit, no file line).
Interactions: removing the AWSSigV4 rejection (CRF-12) makes CRF-13 moot. Kite's fix for CRF-11 also removes CRF-5.
Reviewed against e804af8..4f25ef8.

Round 2 update

BLOCKED. CRF-19 silent (no reply, handler.go:28 unchanged). No review. Churn guard: 11 addressed (author claims, unverified by panel), 11 contested, 1 silent. Reviewed against 92337c0..95b40d6.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reports Type() == "anthropic", so the router's Bedrock check does not exclude it and BYOK requests pass checkRequest. Only test helpers build this shape today.
  • aibridge/bridge.go:224: InterceptionRecord is 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 changing bridge.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: serve discards 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.RoundTrip sets the required anthropic-workspace-id header, so the forwarding slice needs the provider's transport (as NewPassthroughRouter uses via PassthroughTransportWrapper).

🤖 This review was automatically generated with Coder Agents.

Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread coderd/aibridged/backend_test.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/router_test.go Resolved
@pawbana

pawbana commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch 10 times, most recently from 91e01eb to 1e43d48 Compare October 2, 2026 11:41
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 95b40d6 to 6417449 Compare October 2, 2026 11:59
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 6417449 to 027f798 Compare October 2, 2026 14:50
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch from e8d590a to afb06f1 Compare October 2, 2026 20:38
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 027f798 to c2fb367 Compare October 2, 2026 20:38
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch 2 times, most recently from 28b237f to ae07413 Compare October 5, 2026 09:05
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from c2fb367 to 1a6b56c Compare October 5, 2026 09:15
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch from ae07413 to 0d07390 Compare October 5, 2026 10:55
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 1a6b56c to 053d24e Compare October 5, 2026 11:07
@pawbana
pawbana marked this pull request as ready for review October 5, 2026 11:10
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch 3 times, most recently from 74bc42d to 60b2e22 Compare October 5, 2026 17:13
Base automatically changed from pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 to main October 5, 2026 17:33
@pawbana pawbana changed the title feat: validate AI Gateway proxy requests and credentials feat: validate AI Gateway actor and credentials in proxy mode Oct 5, 2026
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.

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM 👍 just a few comments and suggestions

Comment thread aibridge/x/proxy/handler.go Outdated
http.Error(w, "no actor found", http.StatusBadRequest)
return nil, nil
}
if h.recorder == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, moved check to constructor.

Comment thread aibridge/x/proxy/handler.go Outdated
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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably include the initiator id in this log.

@pawbana pawbana Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This default case is just for AWS, right? Should we add a TODO linking to the relevant issue?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link

Comment on lines +155 to +157
// Model: TODO, depends on extractor
// ClientSessionID: TODO, depends on request buffering
// CorrelatingToolCallID: TODO, depends on extractor

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we link the associated linear issues?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link

Comment thread aibridge/x/proxy/router.go Outdated
Comment on lines +45 to +47
// providers proxy passthrough routes upstream. Non-Bedrock bridged routes
// return 404 after validation succeeds. Bedrock bridged routes return 404
// without validation regardless of credentials.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is this comment up to date? We are still returning a 501 placeholder

http.Error(w, "bridged routes are not yet implemented in proxy mode", http.StatusNotImplemented)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, sorry about that. Made comment simpler.

Comment thread aibridge/x/proxy/router.go Outdated
}

bridged := newForwardingHandler(prov, logger, m, tracer, inflight, rec)
bridged := inflight.Middleware(newForwardingHandler(prov, logger, m, tracer, inflight, rec))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, I think we are calling Admit() and RequestContext() twice:

This will cause 1 request to count as 2. Is this intended?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reorganized tests:

  • TestCheckRequest
    • Rejects
    • Record

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, that looks great, thanks 🏆

…r fields consistent, removed double admit for bridged requests,comment updates
@pawbana
pawbana enabled auto-merge (squash) October 7, 2026 16:39
@pawbana
pawbana merged commit f08bfdd into main Oct 7, 2026
29 checks passed
@pawbana
pawbana deleted the pawel/issue-29726-validation branch October 7, 2026 16:51
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants