proxyconf

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxyconf holds the -proxy rules that pilot-daemon and pilotctl share on top of github.com/pilot-protocol/common/netproxy: which spellings a proxy setting accepts, how it is shown without credentials, and the loopback exemption every outbound path applies.

A proxy setting is one of:

  • "auto" (or empty): the proxy from the environment (HTTPS_PROXY, https_proxy, ALL_PROXY, all_proxy, honouring NO_PROXY). Whether auto applies at all for a given transport is the caller's policy.
  • "off", or one of its aliases "none", "no", "false", "direct": never use a proxy.
  • an explicit "http://[user:pass@]host[:port]" or "https://..." URL.

Anything else — a bare word such as "proxy", a host:port without a scheme, or another scheme — is rejected, so a typo can never turn into a proxy host name. Errors and display strings never contain credentials.

Rotating credentials are mostly netproxy's business: a Resolver with a refresh source (the -proxy-cmd / $PILOT_PROXY_CMD / config.json proxy_cmd setting; see CommandSource) re-reads the proxy URL every netproxy.DefaultRefreshInterval and whenever a proxy rejects the credentials, and netproxy's Dialer and RefreshingTransport retry that connection once with the new ones. This package adds the loopback rule on top, and the Relay: a loopback CONNECT proxy that gives the processes the daemon starts, which cannot re-read anything, the same refreshed credentials.

Index

Constants

View Source
const (
	Auto = netproxy.ModeAuto
	Off  = netproxy.ModeOff
)

The normalized setting values.

View Source
const EnvRefreshCommand = netproxy.EnvRefreshCommand

EnvRefreshCommand is the environment variable holding the proxy refresh command (netproxy.EnvRefreshCommand, "PILOT_PROXY_CMD").

View Source
const RelayUser = "pilot-relay"

RelayUser is the user name in a Relay's URL. The password is a random token, different for every Relay.

Variables

This section is empty.

Functions

func AuthRejected

func AuthRejected(err error) bool

AuthRejected reports whether err is a proxy's refusal of the credentials (407 Proxy Authentication Required on CONNECT).

func CommandSource

func CommandSource(command string, env []string) func(ctx context.Context) (string, error)

CommandSource returns a refresh source for netproxy.WithRefreshFunc that runs command the way netproxy.WithRefreshCommand does — "sh -c", stdin and stderr discarded (stderr could echo credentials, e.g. under set -x), at most 64 KiB of output, and on Unix in a process group of its own that is killed as a whole when the refresh deadline passes — except that it runs in env instead of this process's current environment.

The daemon needs that because it points its own HTTPS_PROXY at its app Relay (so the apps it starts inherit the Relay, see Relay) once it is running. A refresh command such as bash -c 'printf %s "$https_proxy"' must still see what the daemon was launched with — in Meta Muse a fresh bash then reads the rotated credentials — and never the Relay, which would make the daemon's proxy its own Relay. A nil env runs the command in this process's environment, as netproxy does.

The output is never part of an error.

func ConfigureTransport

func ConfigureTransport(tr *http.Transport, r *netproxy.Resolver, relay *url.URL)

ConfigureTransport routes tr (in place) through r, for transports that cannot be wrapped — http.DefaultTransport, which plugin HTTP clients use or clone. tr.Proxy follows r's current settings, loopback always direct.

relay, when set, is the URL of a Relay for r (Relay.URL): requests that net/http tunnels with CONNECT (https://, wss://) then go to the proxy through it, and the Relay's netproxy.Dialer handles a rejection of the credentials — a 407, or a CONNECT answer so garbled it cannot be parsed (Meta Muse's form) — by refreshing r and retrying the tunnel once, so the request succeeds, and no proxy-supplied text reaches an error. Plain http:// requests, which a proxy forwards rather than tunnels, keep going to the proxy r names. The daemon passes its Relay whenever it proxies.

Without a relay, a 407 answer to a CONNECT refreshes r before the request fails, so the next request carries the new credentials, and the refusal fails with a *netproxy.ConnectError, whose message never quotes the proxy's reason phrase. An answer net/http cannot parse fails with net/http's own error (which quotes the offending status text) and refreshes nothing: net/http never passes it to this hook. (Wrapped clients, see RoundTripper, handle both forms and also retry the failed request.) A nil r leaves tr alone.

func CredentialHint

func CredentialHint(err error) string

CredentialHint explains a proxy's rejection of the credentials — a 407, or an answer that could not be parsed — for a log line or error; "" for any other error.

func DialContext

func DialContext(r *netproxy.Resolver, proxyTLS *tls.Config) func(ctx context.Context, network, addr string) (net.Conn, error)

DialContext returns a dial function that tunnels through the proxy r picks for each target (CONNECT by host name, never resolved locally) and dials loopback targets, and targets r does not proxy, directly. It is a netproxy.Dialer: when the proxy rejects the credentials (407), r refreshes (re-running its refresh command, if any) and the dial is retried once when that produced different credentials. proxyTLS configures the TLS session with an https:// proxy — never the target's TLS, which the caller runs end to end over the returned conn; nil verifies the proxy against the system roots.

func HasCredentials

func HasCredentials(spec string) bool

HasCredentials reports whether an explicit proxy setting carries userinfo. netproxy takes everything before the last '@' as credentials, so any '@' counts — including in a value url.Parse would misread (an unescaped '/', '?' or '#' in the password).

func IsLoopbackHost

func IsLoopbackHost(host string) bool

IsLoopbackHost reports whether host (a name or IP literal, optionally in brackets) is this machine: localhost, *.localhost or a loopback address. Such targets are never sent to a proxy, even an explicit one — the proxy would reach its own loopback, and the request would leave the host.

func Normalize

func Normalize(spec string) (string, error)

Normalize maps a proxy setting to Auto, Off, or the trimmed explicit proxy URL, which it validates. The error never includes credentials.

func Proxies

func Proxies(r *netproxy.Resolver, addr string) bool

Proxies reports whether a TCP dial of addr goes through a proxy (see ProxyFor).

func ProxyFor

func ProxyFor(r *netproxy.Resolver, addr string) string

ProxyFor returns the proxy (redacted, for logs and hints) a TCP dial of addr goes through, "" for a direct dial: loopback targets always, and targets r does not proxy (nil r, Off, NO_PROXY under auto). It reads r's current settings and never waits for a refresh.

func Redact

func Redact(spec string) string

Redact renders a proxy setting for display: "auto", "off" and URLs without credentials unchanged (URLs reduced to scheme://host:port), userinfo replaced by "***". Values that do not parse keep only what follows the last '@'.

func RequestProxy

func RequestProxy(r *netproxy.Resolver) func(*http.Request) (*url.URL, error)

RequestProxy returns an http.Transport.Proxy function that follows r (its current, refreshed settings) but never proxies loopback targets. nil for a nil resolver (net/http's own environment handling then applies wherever the caller leaves Proxy unset).

func Resolve

func Resolve(spec string, opts ...netproxy.Option) (*netproxy.Resolver, error)

Resolve builds the resolver for a proxy setting (see Normalize): Auto reads the environment, Off never proxies, a URL proxies everything. It applies no transport policy. opts are netproxy's (for example netproxy.WithRefreshCommand for rotating credentials); they do not apply to Off. With a refresh command, Resolve runs it once before returning.

func RoundTripper

func RoundTripper(r *netproxy.Resolver, base *http.Transport) http.RoundTripper

RoundTripper returns the transport for an HTTP client that follows r: a netproxy.RefreshingTransport over a copy of base (http.DefaultTransport's settings when nil), so new connections always carry r's current credentials and a request whose CONNECT got 407 is retried once after the refresh, plus the loopback rule: requests to this machine use a direct copy of base. base's own Proxy and OnProxyConnectResponse are replaced. A nil r returns base (nil: http.DefaultTransport).

func UnreadableConnectReply

func UnreadableConnectReply(err error) bool

UnreadableConnectReply reports whether err is netproxy's report of a CONNECT answer it could not parse. Some egress proxies (Meta Muse's) answer wrong or expired credentials this way; HTTP clients show it as "malformed HTTP status code". netproxy's Dialer and RefreshingTransport treat it as a rejection of the credentials (refresh, retry once); its error type is unexported, so this matches the fixed wording netproxy gives it ("read CONNECT response: <fault> (response text withheld)").

Types

type Relay

type Relay struct {
	// contains filtered or unexported fields
}

Relay is a loopback HTTP CONNECT proxy that forwards every tunnel through the egress proxy its Resolver picks, with the Resolver's current credentials: each CONNECT it accepts is opened upstream by a netproxy.Dialer, which refreshes the Resolver and retries once when the proxy rejects the credentials (a 407, or an answer so garbled it cannot be parsed, which is how Meta Muse's rejections arrive), and whose errors never quote the proxy.

The daemon runs one for two kinds of clients:

  • the processes it starts (app-store apps). They inherit the daemon's environment, and a proxy URL in that environment keeps the credentials the daemon was launched with. Where the proxy rotates them (Meta Muse: every few minutes), every new connection such a process opens is then rejected, while the daemon itself, which re-reads its credentials, stays online ("node online, all apps broken"). Pointed at the Relay instead (HTTPS_PROXY=Relay.URL), those processes never hold the proxy's credentials at all.
  • http.DefaultTransport (see ConfigureTransport), which net/http runs itself: it cannot retry a rejected CONNECT, never sees an answer it cannot parse, and quotes such an answer in its error.

The Relay listens on loopback only and accepts only CONNECT (it never sees inside a tunnel; TLS stays end to end). A client must send the Relay's own credentials (RelayUser and a random token, both in URL), so another local user cannot borrow the daemon's proxy credentials through it. Loopback targets are dialed directly and targets the Resolver does not proxy (NO_PROXY) go direct too, as they do for the daemon. When a tunnel cannot be opened the client gets 502 Bad Gateway (403 when the proxy refused the target, 504 on a timeout), with a reason phrase that says why without any credentials or text from the proxy.

func StartRelay

func StartRelay(r *netproxy.Resolver, proxyTLS *tls.Config) (*Relay, error)

StartRelay starts a Relay for r on a loopback port chosen by the system. proxyTLS configures the TLS session with an https:// proxy (nil: the system roots), as for DialContext. r must proxy something.

func (*Relay) Addr

func (rl *Relay) Addr() string

Addr returns the "host:port" the Relay listens on.

func (*Relay) Close

func (rl *Relay) Close() error

Close stops the Relay: it stops accepting, closes every open tunnel and waits for their goroutines to finish.

func (*Relay) Serves

func (rl *Relay) Serves(proxyURL string) bool

Serves reports whether proxyURL, a proxy URL as a refresh command prints it, names this Relay. The daemon never lets its own proxy become its Relay: the Relay would then forward to itself.

func (*Relay) URL

func (rl *Relay) URL() *url.URL

URL returns the proxy URL clients use, http://pilot-relay:<token>@host:port. It carries the Relay's token: hand it to child processes (HTTPS_PROXY), never log it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL