Skip to content

feat: add upstream proxy support to aiproxy for passthrough requests#21512

Merged
ssncferreira merged 3 commits intomainfrom
ssncferreira/feat-aibridge-proxy-upstream
Jan 19, 2026
Merged

feat: add upstream proxy support to aiproxy for passthrough requests#21512
ssncferreira merged 3 commits intomainfrom
ssncferreira/feat-aibridge-proxy-upstream

Conversation

@ssncferreira
Copy link
Contributor

@ssncferreira ssncferreira commented Jan 14, 2026

Description

Adds upstream proxy support for AI Bridge Proxy passthrough requests. This allows aiproxy to forward non-allowlisted requests through an upstream proxy. Currently, the only supported configuration is when aiproxy is the first proxy in the chain (client → aiproxy → upstream proxy).

Changes

  • Add --aibridge-proxy-upstream option to configure an upstream HTTP/HTTPS proxy URL for passthrough requests
  • Add --aibridge-proxy-upstream-ca option to trust custom CA certificates for HTTPS upstream proxies
  • Passthrough requests (non-allowlisted domains) are forwarded through the upstream proxy
  • MITM'd requests (allowlisted domains) continue to go directly to aibridge, not through the upstream proxy
  • Add tests for upstream proxy configuration and request routing

Closes: coder/internal#1204

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ssncferreira ssncferreira force-pushed the ssncferreira/feat-aibridge-proxy-upstream branch 3 times, most recently from e4a81dd to d843b9a Compare January 15, 2026 19:41
@ssncferreira ssncferreira marked this pull request as ready for review January 15, 2026 19:43
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Very impressive work!

// Set transport without Proxy to ensure MITM'd requests go directly to aibridge,
// not through any upstream proxy.
proxy.Tr = &http.Transport{
TLSClientConfig: &tls.Config{
Copy link
Contributor

Choose a reason for hiding this comment

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

What role is the TLS config playing here when we forward requests to aibridge?
I see that goproxy defines default TLS settings which seem undesirable, so I'm guessing that is it?
https://github.com/elazarl/goproxy/blob/master/certs.go#L26-L30

The tests seem to pass without this, which suggest that we don't have specific-enough coverage. This can be handled in a follow-up though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point. We probably should set the proxy transport every time to override goproxy's default TLS settings (which use InsecureSkipVerify: true), not just when an upstream proxy is configured. I can address that.

However, this is not a problem currently because aibridge is HTTP, so there is no TLS involved. In the future, if aiproxy and aibridge run as two independent processes with HTTPS between them, then we'd want secure TLS settings. But for now, it's safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 9f9bf3a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this change breaks some tests 😞 The problem is that the tests use a TLS target server with a self-signed certificate. For the proxy to forward requests to this server, it needs to trust the server's certificate. In a real world scenario, the target server would be github.com or google.com for instance, so the certificate would be in the proxy's system cert pool, but the test server's self-signed cert is not.

Reverted the change: e770c6e
I'll address this in a separate PR to not block this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

For sure 👍 can even be after GA, not urgent.
Thanks for testing this out!

// the upstream proxy (true) or MITM'd by aiproxy (false).
// When true, the target domain is NOT in the allowlist.
// When false, the target domain IS in the allowlist.
passthrough bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this terminology might get confusing since we have a concept of passthrough in bridge.
If we went for relayed/proxied/tunneled that might be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum, that is true 🤔
I think I prefer tunneled as it seems the more accurate description of what happens. I can address this in a follow-up PR, because I have been using passthough in other tests (and possibly comments as well). And that way, I can update everywhere 👍

@ssncferreira ssncferreira force-pushed the ssncferreira/feat-aibridge-proxy-upstream branch from d843b9a to 9f9bf3a Compare January 16, 2026 19:00
@ssncferreira ssncferreira merged commit a406ed7 into main Jan 19, 2026
31 checks passed
@ssncferreira ssncferreira deleted the ssncferreira/feat-aibridge-proxy-upstream branch January 19, 2026 08:51
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 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.

aibridge: implement proxy chaining support

2 participants

Comments