safedial

package
v0.331.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 7 Imported by: 0 modules, 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 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

View Source
const DialTimeout = 15 * time.Second

DialTimeout bounds one connection attempt.

Variables

View Source
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

func (g Guard) Allowed(ip netip.Addr) bool

Allowed reports whether g permits connecting to ip. An IPv4-mapped IPv6 address is judged as the IPv4 address it carries.

func (Guard) Control

func (g Guard) Control(_, address string, _ syscall.RawConn) error

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

func (g Guard) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

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.

Jump to

Keyboard shortcuts

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