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
- Variables
- func Allows(addr net.Addr, global, client, tunnel *Source) bool
- func AllowsString(addr string, global, client, tunnel *Source) bool
- func Decide(addr net.Addr, names []string, global, client, tunnel *Source) geomatch.Decision
- func DecideString(addr string, names []string, global, client, tunnel *Source) geomatch.Decision
- func GeoFiles() (ipFile, siteFile string)
- func NormalizeDest(raw string) (string, error)
- func NormalizePriority(p int) int
- func NormalizeSource(scope Scope, rules []string) ([]string, error)
- func RefreshError(l *geomatch.Live) error
- func RefreshGeoData() geomatch.RefreshResult
- func SetGeoData(ipFile, siteFile string)
- func SetMaxRules(n int)
- func WatchGeoData(ctx context.Context, interval time.Duration, ...) error
- type Dest
- type RuleError
- type Scope
- type Source
Constants ¶
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.
const DefaultMaxRules = 1000
DefaultMaxRules is the default limit on the rules of a list users may write.
Variables ¶
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 ¶
Allows reports whether every level allows addr. Levels are the global, client and tunnel or host policies; nil levels allow everything.
func AllowsString ¶
AllowsString is Allows for an address given as text, such as host:port.
func Decide ¶
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 ¶
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 ¶
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 ¶
NormalizePriority maps unknown priorities to DenyFirst.
func NormalizeSource ¶
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
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 ¶
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
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 ¶
Allows reports whether the destination addr, a host or host:port, may be reached.
func (*Dest) AllowsResolved ¶ added in v0.35.0
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
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.
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 ¶
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.