Documentation
¶
Overview ¶
Package client provides shared HTTP transports for outbound OCM calls.
Index ¶
- Variables
- func HTTPTransport(rt http.RoundTripper) *http.Transport
- func NewPublicOnlyHTTPClient(cfg TransportConfig) *http.Client
- func NewPublicOnlyRoundTripper(cfg TransportConfig) http.RoundTripper
- func NewTrustedHTTPClient(cfg TransportConfig) *http.Client
- type FederationCIDRs
- type TransportConfig
Constants ¶
This section is empty.
Variables ¶
var ErrPolicyViolation = errors.New("ocm http policy violation")
ErrPolicyViolation is returned when a public-only dial is blocked.
Functions ¶
func HTTPTransport ¶
func HTTPTransport(rt http.RoundTripper) *http.Transport
HTTPTransport returns the guarded base *http.Transport for a public-only wrapper. It returns the transport itself for a trusted client. It returns nil for other round trippers. External package tests use it to inspect proxy, dialer, and TLS settings. Production code must not use it to bypass the scheme wrapper.
func NewPublicOnlyHTTPClient ¶
func NewPublicOnlyHTTPClient(cfg TransportConfig) *http.Client
NewPublicOnlyHTTPClient returns an HTTP client that dials public addresses and, when set, AllowedFederationCIDRs. Direct mode (UseEnvProxy false) is the safe default. True installs http.ProxyFromEnvironment. A selected proxy hides the OCM target from Control; the guarded dialer classifies the proxy hop. Policy is HTTPS-only; initial plain HTTP is allowed only for literal loopback when AllowLoopback is true. AllowedFederationCIDRs does not permit plain HTTP. Non-HTTPS redirects are rejected (10-redirect limit). Literal HTTPS redirects use the same destination policy as dial Control.
func NewPublicOnlyRoundTripper ¶
func NewPublicOnlyRoundTripper(cfg TransportConfig) http.RoundTripper
NewPublicOnlyRoundTripper returns a public-only transport with the same address policy, proxy contract, and scheme policy as NewPublicOnlyHTTPClient: HTTPS-only, with initial plain HTTP only for literal loopback when AllowLoopback is true. Callers that follow redirects themselves still hit the req.Response scheme check; dial Control applies the same address policy.
func NewTrustedHTTPClient ¶
func NewTrustedHTTPClient(cfg TransportConfig) *http.Client
NewTrustedHTTPClient returns an HTTP client that keeps environment proxy support from #5674. It ignores UseEnvProxy.
Types ¶
type FederationCIDRs ¶
type FederationCIDRs struct {
// contains filtered or unexported fields
}
FederationCIDRs is an immutable explicit private-network exception list. The zero value allows no exceptions. ParseFederationCIDRs is the only population path; there is no setter and no exported prefix slice.
func ParseFederationCIDRs ¶
func ParseFederationCIDRs(values []string) (FederationCIDRs, error)
ParseFederationCIDRs parses an explicit private-network exception list. Each value must be a canonical netip.ParsePrefix string with no whitespace, zone, port, URL, or hostname, and the prefix must be wholly inside RFC 1918 or IPv6 ULA (fc00::/7). A nil or empty list returns the zero policy. Any invalid entry rejects the whole list and returns no usable policy.
type TransportConfig ¶
type TransportConfig struct {
Timeout time.Duration
Insecure bool
AllowLoopback bool
// UseEnvProxy is the public-only environment-proxy opt-in. False is the
// safe default. True installs http.ProxyFromEnvironment. Trusted clients
// ignore this field and retain proxy support from #5674.
UseEnvProxy bool
// AllowedFederationCIDRs is an explicit private-network exception list for
// the public-only dial guard. The zero value allows no private exceptions.
// Trusted clients ignore this field.
AllowedFederationCIDRs FederationCIDRs
}
TransportConfig is the runtime HTTP transport config for OCM clients.
func DefaultTransportConfig ¶
func DefaultTransportConfig() TransportConfig
DefaultTransportConfig returns normalized runtime defaults.