Skip to content

[probes.starlark] add probe-level proxy support - #1513

Merged
manugarg merged 10 commits into
cloudprober:mainfrom
aholden85:starlark-proxy-support
Nov 2, 2026
Merged

manugarg merged 10 commits into
cloudprober:mainfrom
aholden85:starlark-proxy-support

Conversation

@aholden85

@aholden85 aholden85 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Adds probe-level HTTP proxy support to the Starlark probe using the same proxy_url and proxy_connect_header fields as the HTTP probe, plus a no_proxy field for bypassing the proxy for selected hosts.

The configured proxy is applied to both the default HTTP client and every client created from tls_configs. This allows a Starlark script to use its named TLS configuration through the proxy without adding a proxy selector to the script. The proxy function is built with common/httpclient.BuildProxy, which returns a plain http.ProxyURL-backed func by default, or one based on golang.org/x/net/http/httpproxy.Config (standard NO_PROXY syntax) once no_proxy is set.

When proxy_url is unset, existing behavior is preserved, including Go's ProxyFromEnvironment handling. When configured, every target is proxied, including localhost/loopback, unless no_proxy is also set -- in which case no_proxy matching takes over, and localhost/loopback are then never proxied regardless of no_proxy's contents (a quirk of httpproxy.Config.ProxyFunc, which hardcodes that bypass).

No Starlark builtin or script changes are required.

Tests cover:

  • Requests through the configured proxy using the default client.
  • HTTPS through a real CONNECT tunnel using both a named TLS config and the proxy.
  • proxy_connect_header being sent on the CONNECT request.
  • no_proxy bypassing the proxy for a matching host.
  • Behavior when proxy_url is unset.
  • Invalid, relative, unsupported-scheme, and hostless proxy URLs being rejected during probe initialization.

Update (post-review)

Proxy construction was extracted into a shared common/httpclient.BuildProxy, now used by the http and starlark probes, so proxy_url/no_proxy/proxy_connect_header behave identically across both probe types.

Also added socks5 as an accepted proxy_url scheme, an Init-time error when no_proxy/proxy_connect_header are set without proxy_url, credential-safe error messages for a malformed proxy_url, and rejection of tls_configs combined with an https:// proxy_url (as both would otherwise share one TLSClientConfig for the proxy's own TLS handshake).

Update (round 2)

Addressed review feedback:

  • BuildProxy now returns a plain http.ProxyURL(parsed) func when no_proxy is unset, restoring the http probe's original behavior of proxying every target, including loopback. httpproxy.Config (and its loopback bypass) only kicks in once no_proxy is actually set.
  • BuildProxy now also returns the parsed (lowercased) scheme, so the tls_configs-vs-https-proxy guard in the Starlark probe checks the parsed scheme instead of a case-sensitive string prefix (it previously missed an HTTPS:// proxy URL).
  • Added common/httpclient/httpclient_test.go covering BuildProxy directly: the loopback-proxied default, no_proxy bypass, invalid/malformed URLs (credential-safe errors), rejected schemes, and scheme normalization.
  • One behavior note for the release notes: for the http probe, proxy_connect_header set without proxy_url, and a proxy_url with a scheme other than http/https/socks5, now fail probe Init() instead of being silently ignored.

Closes #1505.

@manugarg manugarg 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.

I just posted a comment about this here: #1505 (comment)

@aholden85

Copy link
Copy Markdown
Contributor Author

I just posted a comment about this here: #1505 (comment)

Thanks @manugarg - I've read through it and will "recalibrate" this branch/PR, as it reads as a more aligned solution, at least to me on first viewing. Watch this space 😛

Marking as Draft for now to avoid an unintended merge.

@aholden85
aholden85 marked this pull request as draft September 29, 2026 07:55
@aholden85 aholden85 changed the title probes/starlark: add proxy support via proxy_configs probes/starlark: add probe-level proxy support Oct 5, 2026
@aholden85
aholden85 marked this pull request as ready for review October 5, 2026 22:21
@aholden85

Copy link
Copy Markdown
Contributor Author

Apologies for the delay @manugarg, real life got in the way a bit 😅

I've updated the title, desc, and files as part of this PR - it made sense to re-use the PR rather than close this one and create a new one, but please let me know if you'd prefer that.

Also, I've removed the note about the issues I encountered when running ./tools/gen_pb_go.sh and will create a new issue regarding this.

@aholden85

Copy link
Copy Markdown
Contributor Author

Let me know if this doesn't correctly address your feedback on #1505 and I'll take another crack at it.

Comment thread probes/starlark/starlark.go Resolved
Comment thread probes/starlark/starlark.go Resolved
Comment thread probes/starlark/starlark.go Resolved
Comment thread probes/starlark/starlark.go Resolved
Comment thread probes/starlark/runtime.go Resolved
Comment thread probes/starlark/runtime.go Resolved
@aholden85

Copy link
Copy Markdown
Contributor Author

Thank you so much @manugarg - I'll take a look at this shortly and address your feedback.

Also, are there alternative ways to chat w/ you in a less formal manner about Cloudprober (if nothing else 😅), or would you prefer to just retain conversations on GitHub (issues, PRs, etc) at this stage?

@aholden85
aholden85 force-pushed the starlark-proxy-support branch from e4d00e2 to 01c9cdf Compare October 15, 2026 05:36
@aholden85

aholden85 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

One thing worth calling out explicitly is that unifying proxy handling onto common/httpclient.BuildProxy changes the plain http probe's existing behaviour, not just starlark probes. It no longer proxies loopback/localhost targets (via httpproxy.Config's hardcoded bypass), where it used to proxy everything unconditionally via http.ProxyURL.

I think this is the right call for consistency between probe types, but wanted to flag it as a deliberate behaviour change rather than something that slipped in without notice.

Comment thread common/httpclient/httpclient.go Resolved
Comment thread probes/starlark/starlark.go Resolved
Comment thread common/httpclient/httpclient.go Resolved
Comment thread probes/http/http.go Resolved
@aholden85

Copy link
Copy Markdown
Contributor Author

Thanks for the second pass, @manugarg -- addressed all four points.

One side effect worth flagging: probes/http/http_test.go's TestGetTransport had been changed to build a real *http.Request instead of passing nil, since the httpproxy-based func dereferenced req.URL. Since the http probe always calls BuildProxy with an empty no_proxy, it now gets back a plain http.ProxyURL func again, which ignores its argument -- so I reverted that test back to passing nil, keeping the diff smaller.

…n-blocking test send

- BuildProxy: accept socks5h, which net/http's Transport supports and the
  http probe's proxy_url accepted before.
- newTestProxy: update the comment; the loopback bypass only applies when
  no_proxy is set.
- newTestConnectProxy: don't block the handler on a full gotHeader channel.
- no_proxy: drop the incorrect HTTP-probe comparison, note the loopback
  bypass, and remove the trailing blank line in config.proto.
@manugarg manugarg changed the title probes/starlark: add probe-level proxy support [probes.starlark] add probe-level proxy support Nov 2, 2026
@manugarg
manugarg merged commit e1c792f into cloudprober:main Nov 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Starlark probe: support explicit proxy configuration (parity with HTTP probe)

2 participants