Documentation
¶
Overview ¶
Package safedial is THE rule for "may muster-server open a connection to this address": one predicate over a resolved IP (Guard.Allowed) and one dialer that applies it at connect time (Guard.DialContext).
One rule, one place. The HTTP connector proxy (internal/connectors, always on) and the postgres connector (only with MUSTER_DIAL_DENY_PRIVATE=1) both dial through a Guard, so a range added here is refused by both.
🔴 THE CHECK IS ON THE RESOLVED ADDRESS, NEVER ON THE NAME. DialContext resolves the host itself, refuses the dial if ANY answer is non-public, and connects to a checked ADDRESS rather than handing the name back to the system dialer. Checking a name's resolution and then dialling the NAME resolves twice, and a zone that answers public the first time and private the second (DNS rebinding) would get through. The Dialer's Control hook re-checks the socket's actual destination as a backstop for any path that reaches the socket without coming through the resolution check.
Index ¶
Constants ¶
const DialTimeout = 15 * time.Second
DialTimeout bounds one connection attempt.
Variables ¶
var ErrForbiddenAddress = errors.New("refusing to connect to a non-public address")
ErrForbiddenAddress is the dial refusal for a non-public destination.
Functions ¶
This section is empty.
Types ¶
type Guard ¶
type Guard struct {
// AllowLoopback admits loopback destinations (127.0.0.0/8, ::1). Every
// other non-public range stays refused.
AllowLoopback bool
// Resolve replaces the system resolver. nil means net.DefaultResolver.
Resolve func(ctx context.Context, host string) ([]netip.Addr, error)
}
Guard is a dialer that connects only to public addresses.
🔴 THE ZERO VALUE IS THE STRICT ONE: the system resolver, and no non-public destination. AllowLoopback and Resolve LOOSEN or replace it and exist for tests.
func (Guard) Allowed ¶
Allowed reports whether g permits connecting to ip. An IPv4-mapped IPv6 address is judged as the IPv4 address it carries.
func (Guard) Control ¶
Control is a net.Dialer Control hook: the last-moment check on the address a socket is about to connect to ("ip:port").
func (Guard) DialContext ¶
DialContext resolves addr's host, refuses the dial if ANY resolved address is non-public, and connects to a checked address (see the package comment). Its signature is net.Dialer.DialContext's, so it slots into an http.Transport or a pgx DialFunc unchanged.