acl

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 13 Imported by: 1 module, 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 acl compiles and evaluates the access lists of nps on top of geomatch: the source lists (who may connect) of the global, client and tunnel or host levels, and the destination list of a proxy tunnel.

Index

Constants

View Source
const (
	// DenyFirst denies an address on the blacklist even if the whitelist has
	// it, and denies addresses on neither list.
	DenyFirst = int(geomatch.DenyFirst)
	// AllowFirst allows an address on the whitelist even if the blacklist has
	// it, and allows addresses on neither list.
	AllowFirst = int(geomatch.AllowFirst)
)

Priorities of a source level that has both lists.

View Source
const DefaultMaxRules = 1000

DefaultMaxRules is the default limit on the rules of a list users may write.

Variables

View Source
var (
	// ErrMalformedScope is rule text (a scope) with a syntax error or no rule.
	ErrMalformedScope = errors.New("malformed scope")
	// ErrScopeDenied is a destination the scope does not admit.
	ErrScopeDenied = errors.New("destination outside the scope")
)

Functions

func Allows

func Allows(addr net.Addr, global, client, tunnel *Source) bool

Allows reports whether every level allows addr. Levels are the global, client and tunnel or host policies; nil levels allow everything.

func AllowsString

func AllowsString(addr string, global, client, tunnel *Source) bool

AllowsString is Allows for an address given as text, such as host:port.

func Decide

func Decide(addr net.Addr, names []string, global, client, tunnel *Source) geomatch.Decision

Decide is Allows with the level and rule that decided. names name the global, client and tunnel levels for the decision's text.

func DecideString

func DecideString(addr string, names []string, global, client, tunnel *Source) geomatch.Decision

DecideString is Decide for an address given as text, such as host:port.

func GeoFiles

func GeoFiles() (ipFile, siteFile string)

GeoFiles returns the geoip and geosite files.

func NormalizeDest

func NormalizeDest(raw string) (string, error)

NormalizeDest returns the canonical form of destination rules, one per line. The error names the rules that were rejected; they are left out.

func NormalizePriority

func NormalizePriority(p int) int

NormalizePriority maps unknown priorities to DenyFirst.

func NormalizeSource

func NormalizeSource(scope Scope, rules []string) ([]string, error)

NormalizeSource returns the canonical form of the source rules, without duplicates. The error names the rules that were rejected; they are left out of the result.

func RefreshError added in v0.35.0

func RefreshError(l *geomatch.Live) error

RefreshError returns the rules of a list of RefreshGeoData's Failed that the new geodata cannot serve, by line.

func RefreshGeoData added in v0.35.0

func RefreshGeoData() geomatch.RefreshResult

RefreshGeoData checks the geodata files once for all lists and recompiles the lists whose files changed. A list that new geodata breaks keeps its rules and is reported in Failed; RefreshError tells why, and its Tag is the owner CompileSource was given.

func SetGeoData

func SetGeoData(ipFile, siteFile string)

SetGeoData sets the geoip and geosite files. Lists compiled from other files are recompiled by RefreshGeoData. ext-ip: rules of the global lists resolve relative names next to the geoip file.

func SetMaxRules

func SetMaxRules(n int)

SetMaxRules sets the limit on the rules of each list users may write, the client, tunnel, host and destination lists; 0 means no limit. It must be called before any list is compiled.

func WatchGeoData added in v0.35.0

func WatchGeoData(ctx context.Context, interval time.Duration, report func(geomatch.RefreshResult)) error

WatchGeoData runs RefreshGeoData every interval until ctx ends, and calls report with each result that changed a list.

Types

type Dest

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

Dest is the compiled destination access policy of a tunnel. A nil Dest allows every destination.

func CompileDest

func CompileDest(mode int, rules string, owner any) (*Dest, error)

CompileDest compiles a destination list in mode AclOff, AclWhitelist or AclBlacklist (0, 1, 2). An empty whitelist allows nothing; one with a rule whose geodata file is missing allows everything until the file is there. owner tags the list for RefreshGeoData.

func CompileScope added in v0.35.0

func CompileScope(text string, owner any) (*Dest, error)

CompileScope compiles rule text: lines of [allow|deny whitespace] rule, default allow, ignoring blank lines and those starting with #. Empty text is no limit, and nil is returned. Text with no rule or a syntax error is ErrMalformedScope. A rule whose geodata is unavailable does not fail: it is skipped, a deny that matches nothing and, when the file is missing, an allow list that admits everything; this is warned about once.

func (*Dest) Allows

func (d *Dest) Allows(addr string) bool

Allows reports whether the destination addr, a host or host:port, may be reached.

func (*Dest) AllowsResolved added in v0.35.0

func (d *Dest) AllowsResolved(addr string, ips []netip.Addr) bool

AllowsResolved decides addr, a host:port, whose host is or resolved to ips: a deny of the name or of any IP refuses; then it needs no allow rules or an allow of the name or of every IP.

func (*Dest) DeniesName added in v0.35.0

func (d *Dest) DeniesName(addr string) bool

DeniesName reports whether a deny rule matches addr, a host:port, as it is: what can be refused before resolving it.

type RuleError

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

RuleError reports the rules of a list that were rejected, by line.

func (*RuleError) Error

func (e *RuleError) Error() string

func (*RuleError) Unwrap

func (e *RuleError) Unwrap() error

type Scope

type Scope uint8

Scope tells who may write a list, which bounds what it may contain.

const (
	// ScopeGlobal lists are written by the administrator only.
	ScopeGlobal Scope = iota
	// ScopeUser lists may be written by users.
	ScopeUser
)

type Source

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

Source is the compiled source access policy of one level. A nil Source allows every address.

func CompileSource

func CompileSource(scope Scope, priority int, black, white []string, owner any) (*Source, error)

CompileSource compiles the source lists of a level. Rules that cannot be used, for example geoip: rules without geodata, are skipped and named by the error; the returned Source applies the others. A whitelist with a rule whose geodata file is missing restricts nothing until the file is there. owner tags the lists for RefreshGeoData.

func (*Source) Policy

func (s *Source) Policy() geomatch.Policy

Policy returns the geomatch policy of the level.

Jump to

Keyboard shortcuts

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