Documentation
¶
Overview ¶
Package publicnet restricts outbound connections to the public internet, for fetches whose destination comes from untrusted input.
Index ¶
- Variables
- func CheckRedirectTarget(req *http.Request) error
- func DialContext(dialer *net.Dialer) func(ctx context.Context, network, address string) (net.Conn, error)
- func IsMetadataAddr(addr netip.Addr) bool
- func IsPublicIP(ip net.IP) bool
- func NewHTTPClient() *http.Client
- func PublicOnly(ctx context.Context) bool
- func RequirePublicHost(ctx context.Context, host string) error
- func ResolvePublic(ctx context.Context, host string) ([]net.IPAddr, error)
- func WithPublicOnly(ctx context.Context) context.Context
- func WithRedirectCheck(ctx context.Context, check func(target *url.URL) error) context.Context
Constants ¶
This section is empty.
Variables ¶
var ErrNonPublic = errors.New("non-public address")
Functions ¶
func CheckRedirectTarget ¶ added in v0.19.1302
CheckRedirectTarget runs the check attached to the request's context, if any. Call it from an http.Client's CheckRedirect.
func DialContext ¶
func DialContext(dialer *net.Dialer) func(ctx context.Context, network, address string) (net.Conn, error)
DialContext wraps dialer so it only connects to public addresses, pinning the connection to the address that was checked.
func IsMetadataAddr ¶ added in v0.19.1302
IsMetadataAddr reports whether addr is a cloud metadata or platform endpoint outside the link-local range. Link-local metadata addresses such as 169.254.169.254 are not listed; callers block that range as a whole.
func IsPublicIP ¶
func NewHTTPClient ¶ added in v0.19.1277
func PublicOnly ¶ added in v0.19.1302
func RequirePublicHost ¶
RequirePublicHost rejects host unless every address it resolves to is on the public internet. Callers that then connect should also dial through DialContext, so a record that changes between the check and the connection is still caught.
func ResolvePublic ¶
ResolvePublic resolves host and returns its addresses, failing unless every address is on the public internet.
func WithPublicOnly ¶ added in v0.19.1302
WithPublicOnly marks ctx as running on the control plane with destinations that come from untrusted input. Shared clients that also run in the customer's cloud, where private destinations are legitimate, read the mark through PublicOnly and dial only public addresses when it is set.
func WithRedirectCheck ¶ added in v0.19.1302
WithRedirectCheck attaches a check that clients built in this package, and in templatefetch, run on every redirect target before following it. It is how a caller applies a policy that the client itself knows nothing about, such as the operator's allowed hosts. The check does not run on the first URL: the caller checks that before making the request.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package templatefetch is the HTTP client for vendor-supplied stack template URLs.
|
Package templatefetch is the HTTP client for vendor-supplied stack template URLs. |