publicnet

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package publicnet keeps the hosted build's connections to mail servers on the public internet. A person names their own IMAP server; in MAILRULES_MODE=cloud that name must not lead the daemon into the operator's own network: its loopback, a private network, a cloud metadata service on a link-local address. Check refuses such a server before anything is dialed, and Dialer refuses at dial time, on the address actually connected to, so a name that resolves to a public address when it is checked and to a private one when it is dialed (DNS rebinding) is refused too. Both answer with an error that wraps mail.ErrNotPublic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, r Resolver, host string) error

Check refuses host, an IP address or a name, when it is or resolves to an address that is not public (an error that wraps mail.ErrNotPublic). A name that does not resolve is an error that does not wrap it. Nothing is dialed. r nil is the system's resolver.

func Control

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

Control is a net.Dialer Control function that refuses to connect to an address that is not public. It runs on the address the socket is about to connect to, after any name was resolved, so no answer of a resolver gets past it. An address it cannot read is refused too.

func Public

func Public(ip netip.Addr) bool

Public reports whether ip is an address on the public internet: not loopback, private (RFC 1918, IPv6 unique local), link-local, unspecified, multicast or broadcast, not carrier-grade NAT, documentation or another special-purpose range, in IPv4, in IPv6 and in the IPv6 forms that carry an IPv4 address (IPv4-mapped, NAT64, 6to4), which are judged by the IPv4 address they carry.

Types

type Dialer

type Dialer struct {
	Resolver Resolver // nil: the system's resolver
	// contains filtered or unexported fields
}

Dialer connects only to public addresses. It resolves the host itself, refuses it when any of its addresses is not public, as Check does, and then connects to those addresses one by one through a net.Dialer whose Control refuses, on the socket about to connect, an address that is not public. A name is resolved once per dial, and what is connected to is what was checked.

func (Dialer) DialContext

func (d Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to address, "host:port", as net.Dialer.DialContext does, or fails before connecting with an error that wraps mail.ErrNotPublic.

type Resolver

type Resolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

Resolver looks up a host name's addresses. *net.Resolver is one; tests fake it.

Jump to

Keyboard shortcuts

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