publicnet

package
v0.19.1306 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 8 Imported by: 1 module, 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 publicnet restricts outbound connections to the public internet, for fetches whose destination comes from untrusted input.

Index

Constants

This section is empty.

Variables

View Source
var ErrNonPublic = errors.New("non-public address")

Functions

func CheckRedirectTarget added in v0.19.1302

func CheckRedirectTarget(req *http.Request) error

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

func IsMetadataAddr(addr netip.Addr) bool

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 IsPublicIP(ip net.IP) bool

func NewHTTPClient added in v0.19.1277

func NewHTTPClient() *http.Client

func PublicOnly added in v0.19.1302

func PublicOnly(ctx context.Context) bool

func RequirePublicHost

func RequirePublicHost(ctx context.Context, host string) error

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

func ResolvePublic(ctx context.Context, host string) ([]net.IPAddr, error)

ResolvePublic resolves host and returns its addresses, failing unless every address is on the public internet.

func WithPublicOnly added in v0.19.1302

func WithPublicOnly(ctx context.Context) context.Context

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

func WithRedirectCheck(ctx context.Context, check func(target *url.URL) error) context.Context

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.

Jump to

Keyboard shortcuts

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