{"modulePath":"github.com/chainloop-dev/chainloop","version":"v1.138.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package netguard\n\nPackage netguard restricts outbound HTTP connections to publicly routable destinations.\n\n## Variables\n\n```go\nvar ErrBlockedTarget = errors.New(\"blocked outbound request\")\n```\nErrBlockedTarget is returned when a request is refused because its destination is not publicly routable.\n\n```go\nvar Transport = sync.OnceValue(func() *http.Transport {\n\treturn RestrictTransport(nil)\n})\n```\nTransport returns a process-wide transport that only connects to publicly routable destinations, so that its connections are pooled and reused across requests. See RestrictTransport.\n\n## Functions\n\n```go\nfunc IsPubliclyRoutable(ip net.IP) bool\n```\nIsPubliclyRoutable reports whether ip is an address on the public internet.\n\n```go\nfunc NewHTTPClient(timeout time.Duration) *http.Client\n```\nNewHTTPClient returns a client that only connects to publicly routable destinations, backed by Transport.\n\n```go\nfunc RestrictTransport(t *http.Transport) *http.Transport\n```\nRestrictTransport makes t connect to publicly routable destinations only: loopback, private ranges, link-local addresses (where cloud metadata services live) and the IPv6 transition ranges that embed an IPv4 address are all refused with ErrBlockedTarget.\n\nIt also drops any proxy, which would otherwise be the only address the transport connects to and would leave the destination unchecked.\n\nt is modified in place and returned. A nil t starts from a clone of http.DefaultTransport.\n\n## Types\n\n```go\ntype DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)\n```\nDialFunc opens a connection to addr, in the form of net.Dialer.DialContext.\n\n```go\nfunc PublicOnlyDialContext(resolve ResolveFunc, dial DialFunc) DialFunc\n```\nPublicOnlyDialContext wraps dial so that a connection is only made to a publicly routable address.\n\nThe check runs here, at dial time, rather than against the URL, for two reasons. It sees the address the connection will actually use, so a host name that resolves to an allowed address for a check and to a blocked one for the connection cannot slip through: the dial targets the very IP that was validated. And because every redirect hop opens its own connection, the whole chain is covered, not just the URL the caller supplied.\n\n```go\ntype ResolveFunc func(ctx context.Context, host string) ([]net.IPAddr, error)\n```\nResolveFunc resolves a host name into the addresses it points to.\n\n","path":"github.com/chainloop-dev/chainloop/pkg/netguard","name":"netguard","synopsis":"Package netguard restricts outbound HTTP connections to publicly routable destinations.","isRedistributable":true}
