Help us shape the future of Go! Take the 2026 Go Developer Survey

policy

package
v1.44.3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ConnectTimeout = 30 * time.Second
View Source
const Errno = "EACCES"

Variables

View Source
var ErrDenied = errors.New("denied by policy")

Functions

func ResolveEndpoints added in v1.17.2

func ResolveEndpoints(ctx context.Context, hostports []string, hosts *Hosts) ([]netip.AddrPort, error)

Types

type DebugPorts added in v1.43.0

type DebugPorts struct {
	Found   []uint16
	Given   []uint16
	Exposed []uint16
}

type Dialer

type Dialer struct {
	Policy *Policy
	Base   net.Dialer
	Hosts  *Hosts
}

func NewDialer

func NewDialer(p *Policy) *Dialer

func (*Dialer) Control

func (d *Dialer) Control(network, address string, _ syscall.RawConn) error

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

func (*Dialer) DialContext

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

type Error

type Error struct {
	Addr    netip.AddrPort
	Checked netip.Addr
	Rule    string
	Reason  string
}

func (*Error) Errno

func (e *Error) Errno() string

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

type Hosts added in v1.16.0

type Hosts struct {
	// contains filtered or unexported fields
}

func LoadHosts added in v1.16.0

func LoadHosts(path string) (*Hosts, error)

func ParseHosts added in v1.16.0

func ParseHosts(r io.Reader) (*Hosts, error)

func (*Hosts) Lookup added in v1.16.0

func (h *Hosts) Lookup(network, name string) ([]netip.Addr, bool)

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

func Local

func Local(protectedPorts ...uint16) *Policy

func New

func New() *Policy

func Remote

func Remote(protectedPorts ...uint16) *Policy

func (*Policy) AddProtectedEndpoints added in v1.17.3

func (p *Policy) AddProtectedEndpoints(id string, addrs []netip.AddrPort)

func (*Policy) Allow

func (p *Policy) Allow() []string

func (*Policy) AllowsAny

func (p *Policy) AllowsAny(addr netip.Addr) bool

func (*Policy) Check

func (p *Policy) Check(addr netip.Addr, port uint16) error

func (*Policy) CheckDatagram added in v1.42.0

func (p *Policy) CheckDatagram(addr netip.Addr, port uint16) error

func (*Policy) Deny

func (p *Policy) Deny() []string

func (*Policy) Exposed added in v1.43.0

func (p *Policy) Exposed() []uint16

func (*Policy) Filter

func (p *Policy) Filter(addrs []netip.Addr) []netip.Addr

func (*Policy) Guard added in v1.43.0

func (p *Policy) Guard(d DebugPorts) *Policy

func (*Policy) GuardPort added in v1.43.0

func (p *Policy) GuardPort(port uint16) bool

func (*Policy) Live added in v1.43.0

func (p *Policy) Live(scan func() []uint16, found func(uint16))

func (*Policy) ProtectBrowser added in v1.17.2

func (p *Policy) ProtectBrowser(ctx context.Context, id string, hostports []string, hosts *Hosts) error

func (*Policy) ProtectEndpoints added in v1.17.2

func (p *Policy) ProtectEndpoints(id string, addrs []netip.AddrPort)

func (*Policy) ProtectedEndpoints added in v1.17.2

func (p *Policy) ProtectedEndpoints(id string) []netip.AddrPort

func (*Policy) RefreshBrowser added in v1.17.3

func (p *Policy) RefreshBrowser(ctx context.Context, id string, hostports []string, hosts *Hosts) error

func (*Policy) Summary

func (p *Policy) Summary() string

func (*Policy) With

func (p *Policy) With(allow, deny []Rule) *Policy

type Ports added in v1.43.0

type Ports []uint16

func (*Ports) Set added in v1.43.0

func (s *Ports) Set(v string) error

func (*Ports) String added in v1.43.0

func (s *Ports) String() string

type Resolver

type Resolver struct {
	Policy *Policy
	Base   *net.Resolver
	Hosts  *Hosts
}

func NewResolver

func NewResolver(p *Policy) *Resolver

func (*Resolver) LookupNetIP

func (r *Resolver) LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)

type Rule

type Rule struct {
	Prefix netip.Prefix
	Port   uint16
}

func ParseRule

func ParseRule(s string) (Rule, error)

func (Rule) String

func (r Rule) String() string

type Rules

type Rules []Rule

func ParseRules

func ParseRules(values []string) (Rules, error)

func (*Rules) Set

func (r *Rules) Set(value string) error

func (Rules) String

func (r Rules) String() string

Jump to

Keyboard shortcuts

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