policycore

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 11 Imported by: ? 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.

README

policycore

Selector resolution, address-space primitives, and the output sanitization contract, shared by tail-acl and the other tailnet tools built on it.

Import it from the github.com/rshade/tail-acl module, for example github.com/rshade/tail-acl/pkg/policycore/ipcalc. Go builds only the packages you import, so the CLI's own dependencies stay out of your binary.

Several tools need to answer one question identically: does this policy selector name this thing? Two tools disagreeing about one policy is worse than duplicated code, so the logic lives here rather than in each tool.

Scope

The sanitize subpackage owns level parsing, environment-over-flag precedence, HMAC placeholder allocation, exact known-value replacement in prose, strict timestamp quantization, envelope metadata, and reflection-guard support. It does not know any tool's report shape: each binary rebuilds its own output types from zero at the render boundary so a newly added field cannot pass through without an explicit decision.

The addrspace subpackage compares route CIDRs and recognizes Tailscale 4via6 prefixes, including extracting their embedded site IDs. It knows neither static policy shape nor live device state, and it does not decide whether an overlap or repeated site ID is intentional; callers own those classifications.

The hujsonedit subpackage applies schema-agnostic, comment-preserving RFC 6902 edits to HuJSON documents. It carries no knowledge of any particular document's fields; tail-acl and tail-ipam both build their typed edits on it.

The posture subpackage parses, validates, and evaluates Tailscale device-posture rule expressions. It is stdlib-only and three-valued: an expression or attribute it cannot read is reported, never folded into a pass or a failure. Its grammar and vocabularies (the ip:country country list, the known-attribute table) are editorial readings of the control plane's behavior, each pinned by a Tier-2 provenance guard test against a fixture captured from the live server. tailnet-audit evaluates devices with it; tail-acl validates expressions with it.

The alpha subpackage is the convention for hand-modeling a Tailscale feature that is alpha or unreleased in the pinned SDK — see Alpha feature modeling below. Shared alpha policy shapes also live there when multiple tools must interpret them identically; declarative node sharing is the first such model.

For selector matching, the scope is resolving a selector to the values it names:

  • * and the full autogroup vocabulary, split into role autogroups (resolved from the tailnet's user roster) and autogroups resolved from the policy document alone — autogroupSpecFor in autogroup.go is the single, authoritative enumeration; this README does not restate it
  • tag: and user selectors
  • group: expansion, including nesting, with a cycle guard
  • Hosts and IPSets expansion, with a cycle guard
  • CIDR and address containment

Out of scope — kept in tail-acl:

  • Port and protocol evaluation
  • via routing behavior
  • Policy parsing, merging, and upload

The one shared policy-shape predicate is ContainsLiteralWildcard. Both tail-acl and tailnet-audit use it to keep the ownership boundary between a static literal-wildcard advisory and a destination that becomes broad only after resolving it against the live fleet. It recognizes only a port-stripped literal *; it deliberately does not classify any autogroup as a wildcard.

Usage

A Matcher carries the policy plus the live tailnet facts the policy document cannot supply. Policy is a container holding the pinned SDK's ACL together with the policy fields that SDK does not model:

matcher := policycore.Matcher{Policy: &policycore.Policy{ACL: acl}}
matched := matcher.AnyMatches(rule.Source, "tag:web", "")

A caller that has read the tailnet's user roster supplies it, which is what lets the role autogroups resolve. HaveRoles is an assertion that the roster is complete and authoritative; leave it false after a failed, partial, or truncated read:

matcher := policycore.Matcher{Policy: &policycore.Policy{ACL: acl}, Roles: roles, HaveRoles: true}

A matcher can preserve the difference between a definite non-match and missing live state:

match := matcher.MatchesTri("autogroup:admin", "ada@example.com", "")

For a role autogroup such as autogroup:admin, roster availability and query shape determine the three-state result:

HaveRoles Query shape Roster result Verdict
false tag — NoMatch
false user or bare device/CIDR — Unresolvable
true tag — NoMatch
true user matching role Matched
true user another role NoMatch
true user absent NoMatch
true bare device/CIDR — Unresolvable

A complete roster maps logins to roles. It makes an absent user a definite non-match, but it cannot settle a bare device address because it does not map devices to owners.

Cross-tailnet selectors

A group://<alias>/<name> or tag://<alias>/<name> selector names members of another tailnet, whose roster this policy cannot supply. HaveExternalTailnets plays the role HaveRoles plays for the roster: it asserts that the policy's externalTailnets declarations were actually read, so an alias missing from them is missing rather than merely unparsed.

matcher := policycore.Matcher{Policy: &policycore.Policy{
    ACL:                  acl, // acl.ExternalTailnets holds the declarations
    HaveExternalTailnets: true,
}}
Selector HaveExternalTailnets Alias declared Verdict
well-formed true yes Unresolvable
well-formed true no NoMatch
well-formed false — Unresolvable
malformed either — Unresolvable

An alias is a local name, so one absent from declarations that were read is named by nothing in this policy — the same reading an undefined group: gets. A malformed selector stays undecidable because the :// prefix declares intent: it is a mistyped cross-tailnet reference, not a string that happens to name nobody. A caller that does not parse externalTailnets must leave HaveExternalTailnets false, and every cross-tailnet selector then reports Unresolvable.

Three-state resolution follows nested groups. A group is decidable only when every member is decidable against the query; one nested undecidable autogroup makes a non-matching group Unresolvable. A definite match by any member still settles the group as Matched. Undefined groups remain definite non-matches, and group cycles terminate without being treated as missing live state.

Membership is keyed on the selector itself, not on the group: prefix, so a groups entry the control plane would reject resolves the same way here as one it accepts. Matching and resolvability read that one lookup, which is what keeps a group the matcher expands from being reported as settled.

A caller with no tailnet access uses the roster-blind entry point instead:

matched := policycore.SelectorMatches("group:eng", "ada@example.com", policy, "")

Alpha feature modeling

policycore/alpha is the shared convention for hand-modeling a Tailscale feature that is alpha or unreleased in the pinned tailscale.com/client/tailscale/v2 SDK, so a tool in this repo can pick up an alpha feature early instead of waiting for the SDK to catch up. A feature's hand-modeled types live with the tool that needs them, or in policycore/alpha when more than one tool needs the same policy representation. Declarative node sharing follows the shared case: the SDK models the policy section itself (tailscale.ACL.ExternalTailnets, since tailscale.com/client/tailscale/v2 v2.11.0 — the hand-modeled types here retired when its migration tripwire fired), while ParseExternalSelector parses its cross-tailnet group and tag references and LooksLikeExternalSelector is the recognition view of the same grammar. Matcher resolves those references only as far as this tailnet's policy allows — see Cross-tailnet selectors — never by confirming membership in the other tailnet.

Adding an alpha-backed feature:

  1. Hand-model the feature's types where the tool that needs them lives, or in policycore/alpha if the policy representation must be shared.

  2. Add it to the slice returned by alpha.RepositoryFeatures() in policycore/alpha/alpha.go. That function is the canonical repository-wide inventory naming every hand-modeled alpha feature, its doc source, when this repo started modeling it, and where it sits in Tailscale's own release pipeline:

    func RepositoryFeatures() []Feature {
        return []Feature{
            {
                Name:        "example-alpha-feature",
                DocURL:      "https://tailscale.com/kb/example",
                ModeledDate: time.Date(2026, time.September, 1, 0, 0, 0, 0, time.UTC),
                Stage:       StageAlpha,
            },
        }
    }
    

    alpha.NewRegistry() instead returns an empty, caller-owned registry for validation and lookup. Calling Register on that value does not update the repository inventory.

  3. Give the feature its own migration tripwire — typically a test that fails once the pinned SDK adds real support for it, forcing a conscious decision to migrate off the hand-modeled types instead of letting them silently diverge from the now-real SDK types. alpha.RepositoryFeatures() exposes the feature and its Stage; it does not enforce that feature's tripwire itself, so updating Stage as the feature moves through the pipeline is on the contributor doing the migration.

  4. Cite alpha-sourced data with alpha.AlphaHint as the source-provenance confidence, not "hint". "alpha-hint" is an allowed SourceRef confidence value in tailscale-doctor and tailnet-audit (AGENTS.md AX convention 13): "hint" is editorial evidence verified at test time to resolve in a stable pinned module, while AlphaHint is editorial evidence against a surface Tailscale itself calls unstable — categorically weaker.

Live-verifying an alpha feature

Every other test in this repo is pure/offline (AGENTS.md AX convention 9), which cannot validate a claim like "this hand-modeled struct still matches what the live API returns today." alpha.VerifierRegistry is the opt-in tier for exactly that claim:

  1. Alongside the feature's hand-modeled types, write a alpha.LiveVerifyFunc that fetches live data and round-trips it through the type, returning an error if a field the type expects is missing or reshaped. It takes only a context.Context; close over whatever client and credentials it needs.
  2. Add a //go:build live_verify-tagged test beside the feature. Name it TestLiveVerify... so the workflow's test filter selects it. In that test, populate an alpha.Registry with the feature and use it to construct a VerifierRegistry.
  3. In the same test, explicitly call VerifierRegistry.RegisterVerifier(featureName, fn). Registration is caller-owned runtime state: defining a verifier does not register it, and there is no package discovery or global verifier registry. A nil func, an unknown feature name, or a duplicate registration is rejected.
  4. Call VerifierRegistry.RunAll(ctx) and fail the test for each non-nil result error. RunAll returns one VerifyResult per registered verifier, sorted by name without stopping at the first failure; it returns an empty slice when no verifiers have been registered.

This mechanism is generic; it carries no feature-specific knowledge itself. In particular, the generic test in policycore/alpha/liveverify_live_test.go imports no feature packages and registers no feature verifiers; it checks live credential resolution and the empty-run plumbing only. A feature receives live coverage only when its own tagged test performs the registration and execution described above.

The credentialed tests are invoked only by .github/workflows/alpha-live-verify.yml's opt-in workflow_dispatch job — the same "excluded from ordinary CI by design" posture as macos-scutil-capture.yml. On pull requests, that workflow runs only when the change touches policycore/alpha/** or the workflow file itself. When selected, its credential-free go vet -tags live_verify ./... job compile-checks tagged files in every module. A tagged verifier outside policycore/alpha does not by itself trigger that check; add its path to the workflow's pull_request.paths filter if it needs continuing PR coverage.

Module layout

This is a library module with no binary. Production addrspace code uses only the standard library. Its Tier-2 provenance test imports the pinned tailscale.com/net/tsaddr package to cross-validate the owned 4via6 decoder; no production package imports the full tailscale.com module.

Documentation

This README covers the resolution semantics. For the exported functions, signatures, and helper inventory, see the public API reference.

Documentation

Overview

Package policycore resolves Tailscale policy selectors against concrete values. It is shared by tail-acl and tailnet-audit so both tools answer "does this selector name this thing?" identically; two tools disagreeing about one policy is worse than the duplication this replaces.

Scope is deliberately narrow: entity resolution only. Port, protocol, and via evaluation stay in tail-acl; posture expression handling lives in the posture subpackage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressContains

func AddressContains(selector, query string) bool

AddressContains reports whether selector covers query, where either may be an address or a prefix.

func AutogroupResolvable

func AutogroupResolvable(selector, query string) bool

AutogroupResolvable is the roster-blind view of whether this selector's membership can be decided against this query without control-plane state. Decidability is a property of the pair, not of the selector alone: autogroup:tagged is settled against "tag:batch" and against a user identity, but against "100.64.0.9" it needs the device-to-tag map, which lives in the control plane. Answering such a query "no match" would be exactly the confident wrong answer Match exists to prevent — and reporting a settleable one Unresolvable trains callers to ignore the state, so both directions matter. This function has no policy argument, so it cannot inspect group members; use Matcher.MatchesTri or SelectorMatchesTri when resolving a policy selector that may name a group.

Having no policy document, it also holds no external-tailnet declarations, so it reports every cross-tailnet selector undecidable. A Matcher whose policy declares them settles the undeclared-alias case, exactly as a roster settles the role-autogroup case.

func ContainsLiteralWildcard

func ContainsLiteralWildcard(selectors []string) bool

ContainsLiteralWildcard reports whether selectors contains the literal "*" selector. Callers whose policy surface attaches ports to destinations must strip those ports first, so "*:443" and "*:*" become the same literal host selector the tail-acl overbroad-wildcard advisory owns.

This intentionally does not treat autogroups as wildcards. In particular, autogroup:tagged can name most of a live fleet, but only control-plane state can answer whether it does; tailnet-audit owns that dynamic question.

func EffectiveSrcPosture

func EffectiveSrcPosture(own, fallback []string) ([]string, bool)

EffectiveSrcPosture resolves the source-posture list that gates a rule: the rule's own srcPosture when that list is non-empty, otherwise the policy's defaultSrcPosture. Tailscale documents the default as replaced by a rule's own posture, not added to it, so a rule with its own srcPosture is gated by exactly that list.

fromDefault reports whether the returned list came from the fallback, so a caller can name the origin of a gate in its decision text.

func ExpandAddressSelector

func ExpandAddressSelector(selector string, policy *tailscale.ACL) []string

ExpandAddressSelector resolves a selector through Hosts and IPSets to the concrete addresses or prefixes it names. A Hosts value is returned as written: a literal address or prefix is that literal and is not looked up again as a host name, and any other value is returned unchanged rather than followed. The control plane rejects a hosts value that is not a literal, so following an alias chain would agree with a policy that cannot deploy. An IPSets entry is materialized through ResolveIPSet, so operations, ranges, and host: references inside it resolve, and a set that cannot be materialized expands to nothing. A value that names neither is returned unchanged, as is every value when policy is nil: a document that does not exist declares no aliases, so the selector already is the concrete value it names.

func IsCrossTailnetSelector

func IsCrossTailnetSelector(selector string) bool

IsCrossTailnetSelector reports whether selector uses the cross-tailnet group://<alias>/<name> or tag://<alias>/<name> grammar, which names members of another tailnet rather than of this one.

It reports true for a malformed cross-tailnet selector as well. A mistyped cross-tailnet reference is still a cross-tailnet reference, and treating it as an ordinary local selector would report an authoring typo as "this rule names nobody" instead of "this cannot be decided from this policy".

func IsPublicAddress

func IsPublicAddress(value string, policy *tailscale.ACL) bool

IsPublicAddress reports whether value resolves to any publicly routable address, which is what autogroup:internet selects.

func IsRoleAutogroup

func IsRoleAutogroup(selector string) bool

IsRoleAutogroup reports whether selector is one of the role-based autogroups resolved from a tailnet's user roster rather than from the policy document.

func KnownAutogroup

func KnownAutogroup(selector string) bool

KnownAutogroup reports whether selector is an autogroup whose membership this package can ever confirm, independent of any particular query. Callers that grade a whole policy rather than one query use it to flag autogroups whose presence makes a verdict provisional, so the list lives here rather than being restated per tool.

The role autogroups are deliberately excluded: a tag refutes them, but no offline fact confirms them. Use AutogroupResolvable when a query is in hand — a known autogroup can still be undecidable against a given query.

func LooksLikeUser

func LooksLikeUser(selector string) bool

LooksLikeUser reports whether a selector names a user rather than a group.

func ParseRoster

func ParseRoster(data []byte) (map[string]tailscale.UserRole, error)

ParseRoster decodes an operator-supplied login-to-role roster.

It accepts two shapes so an operator with API access needs no transformation step: the Tailscale users endpoint's envelope, {"users":[{"loginName":…, "role":…}]}, and a hand-authored flat object mapping login to role. Fields beyond loginName and role are ignored, so `curl …/users > roster.json` works directly.

Parsing lives here, beside Matcher.roleMatches, because the two must agree on normalisation. roleMatches looks up m.Roles[strings.ToLower(query)]; a loader elsewhere that forgot to lowercase would make that equality silently false, and with HaveRoles true a missed lookup is a confident wrong NoMatch rather than a missing one. Keeping both halves in one package makes that class of drift impossible instead of merely tested-for.

A successful parse always returns a non-nil map, including for an empty roster. Callers use nil to mean "no roster was supplied" and set Matcher.HaveRoles from that distinction, so returning nil for {} would silently downgrade a complete-but-empty roster to an unread one.

func ResolveIPSet

func ResolveIPSet(name string, policy *tailscale.ACL) ([]netip.Prefix, error)

ResolveIPSet materializes one IPSets entry into the address space its members cover, as the minimal sorted prefix covering. Members are applied in list order through the ipset grammar: an implicit member and an add contribute their target's address space, a remove withdraws it from whatever earlier members contributed, so a later add re-contributes space an earlier remove withdrew. A host: reference is one Hosts lookup whose value must be a literal address or prefix, a range contributes every address between its ends, and an ipset: reference recurses with a path-scoped cycle guard, a per-call memo, and the same depth and size limits tail-ipam applies.

A set that cannot be materialized — a member that does not parse, an implicit member beside a remove (ValidateIPSetOperations), a host: alias that is undefined or names something other than an address or prefix, an undefined or cyclic ipset: reference, or an expansion past the limits — is an error naming the set and the member, never a partial set: dropping a member the resolver could not read would either hide address space or, for a failed remove, silently widen the set.

func SelectorMatches

func SelectorMatches(selector, query string, policy *tailscale.ACL, source string) bool

SelectorMatches reports whether one selector names query using only what the policy document supplies. It is the roster-blind entry point the three-state resolvers in this package are built on, and the form callers with no tailnet access use; role autogroups therefore never match here, which is exactly what AutogroupResolvable reports as undecidable. A caller holding a user roster builds a Matcher instead.

func ValidateIPSetOperations

func ValidateIPSetOperations(members []string) error

ValidateIPSetOperations enforces the control plane's explicit-operation rule: once any member is a remove operation, every member must be an explicit add or remove, because an implicit member's position relative to the remove would otherwise be ambiguous. It classifies by the operation word alone so a caller can report the rule for a set whose targets do not all parse.

Types

type IPSetImplicitMemberError

type IPSetImplicitMemberError struct {
	Member string
	Remove string
}

IPSetImplicitMemberError reports a member list that carries a remove operation alongside a member with no operation word. Member is the first implicit member in list order and Remove the first remove operation, so a message can name both.

func (*IPSetImplicitMemberError) Error

func (e *IPSetImplicitMemberError) Error() string

type IPSetMember

type IPSetMember struct {
	Operation IPSetOperation
	Kind      IPSetMemberKind
	Target    string
}

IPSetMember is one parsed ipset member. Target is canonical for the address-bearing kinds — a masked prefix, an address or range rendered from its parsed form — and kept as written for host: and ipset: references, so two spellings of one member compare equal through String.

func ParseIPSetMember

func ParseIPSetMember(member string) (IPSetMember, error)

ParseIPSetMember classifies one raw ipset member using the control plane's grammar: an optional add/remove operation word followed by a CIDR prefix, a bare address, an inclusive range A-B, a host:<alias> reference, or an ipset:<name> reference. It is syntax only: whether a referenced host or ipset exists is the caller's question, because answering it needs a policy.

func (IPSetMember) HostAlias

func (m IPSetMember) HostAlias() (string, bool)

HostAlias returns the alias a host: member names — the key a caller looks up in the policy's hosts — and false for every other kind.

func (IPSetMember) String

func (m IPSetMember) String() string

String renders the member in its canonical spelling: the operation word, when present, a space, and the canonical target.

type IPSetMemberKind

type IPSetMemberKind string

IPSetMemberKind classifies what an ipset member's target names.

const (
	// IPSetMemberPrefix is a CIDR prefix or a bare address.
	IPSetMemberPrefix IPSetMemberKind = "prefix"
	// IPSetMemberRange is an inclusive address range written A-B.
	IPSetMemberRange IPSetMemberKind = "range"
	// IPSetMemberHost is a host:<alias> reference into the policy's hosts.
	IPSetMemberHost IPSetMemberKind = "host"
	// IPSetMemberIPSet is an ipset:<name> reference to another ipset.
	IPSetMemberIPSet IPSetMemberKind = "ipset"
)

type IPSetOperation

type IPSetOperation string

IPSetOperation is the operation word an ipset member may carry. The control plane applies members in order: an implicit member and an add both contribute addresses, a remove withdraws them.

const (
	// IPSetImplicit marks a member written without an operation word.
	IPSetImplicit IPSetOperation = ""
	IPSetAdd      IPSetOperation = "add"
	IPSetRemove   IPSetOperation = "remove"
)

type Match

type Match int

Match is the outcome of resolving a selector against a query.

A policy file does not contain every fact a membership decision depends on. Role autogroups resolve against control-plane state that only a matcher with a complete roster holds, so collapsing "cannot tell" into "does not match" yields a confident wrong answer — the one outcome a reachability or coverage verdict must never produce. Match keeps that third state addressable instead.

const (
	// NoMatch means the selector provably does not name the query.
	NoMatch Match = iota
	// Matched means the selector names the query.
	Matched
	// Unresolvable means membership depends on control-plane state the matcher
	// does not have, so neither Matched nor NoMatch can be claimed.
	Unresolvable
)

func AnySelectorMatchesTri

func AnySelectorMatchesTri(
	selectors []string,
	query string,
	policy *tailscale.ACL,
	source string,
) (Match, string)

AnySelectorMatchesTri resolves a selector list against query. A match by any selector settles the list, so it outranks an earlier undecidable one. When nothing matches it returns Unresolvable along with the first selector that could not be decided, which callers surface as the reason.

func SelectorMatchesTri

func SelectorMatchesTri(selector, query string, policy *tailscale.ACL, source string) Match

SelectorMatchesTri resolves one selector against query, reporting Unresolvable rather than NoMatch when the answer depends on control-plane state. source is the requesting identity, used only to resolve autogroup:self.

type Matcher

type Matcher struct {
	Policy *Policy
	// Roles maps a user's login name, lowercased, to their tailnet role.
	Roles map[string]tailscale.UserRole
	// HaveRoles reports that Roles is a complete and authoritative user roster.
	HaveRoles bool
}

Matcher resolves policy selectors against a query identity. Policy is the tailnet policy document and everything declared inside it; Roles and HaveRoles carry the live tailnet fact that document cannot supply — who holds which role, and whether a complete, authoritative roster was read.

When HaveRoles is false, role autogroups resolve to nothing and Recognized reports them as unresolved rather than unmatched, so a caller degrades to "coverage may be understated" instead of claiming a device is ungoverned. HaveRoles true with an empty Roles map is different: the complete roster was read and no user holds any role, so role autogroups are recognized and match nobody. Callers must leave HaveRoles false after a partial, truncated, or failed read. A static policy tool that has no tailnet access leaves it false.

func (Matcher) AnyMatches

func (m Matcher) AnyMatches(selectors []string, query, source string) bool

AnyMatches reports whether any selector names query. source is the requesting identity, used only to resolve autogroup:self.

func (Matcher) AnyMatchesTri

func (m Matcher) AnyMatchesTri(selectors []string, query, source string) (Match, string)

AnyMatchesTri resolves a selector list against query. A match by any selector settles the list, so it outranks an earlier undecidable one. When nothing matches it returns Unresolvable along with the first selector that could not be decided, which callers surface as the reason.

func (Matcher) KnownExternalTailnetAlias

func (m Matcher) KnownExternalTailnetAlias(alias string) bool

KnownExternalTailnetAlias reports whether this matcher's policy declares alias as an external tailnet. It is the single lookup every cross-tailnet view goes through, so no two of them can disagree about which aliases exist.

A false result means "not declared by a policy whose declarations were read", which a matcher that never read them cannot distinguish from "not declared at all" — so such a matcher reports false for every alias. Use Recognized or MatchesTri when the difference matters; both keep an unreadable declaration undecidable rather than reporting it absent.

func (Matcher) Matches

func (m Matcher) Matches(selector, query, source string) bool

Matches reports whether selector names query. source is the requesting identity, used only to resolve autogroup:self.

func (Matcher) MatchesTri

func (m Matcher) MatchesTri(selector, query, source string) Match

MatchesTri resolves one selector against query with everything this matcher holds, reporting Unresolvable rather than NoMatch when the answer depends on state the matcher does not have. source is the requesting identity, used only to resolve autogroup:self.

func (Matcher) Recognized

func (m Matcher) Recognized(selector string) bool

Recognized reports whether this matcher understands selector well enough that a non-match means query is genuinely not named, rather than merely unevaluable. Every selector that is neither an autogroup nor a cross-tailnet reference is recognized — tags, users, groups, hosts, ipsets, and addresses all resolve from the policy document alone — as are the autogroup forms this package resolves. The one exception among them is an ipset the resolver cannot materialize: its non-match means the set could not be read, so it is reported unrecognized, exactly as MatchesTri reports it Unresolvable. A host whose value is not a literal address or prefix is the same kind of failure: expansion returns the value unchanged, so a non-match is not evidence that the host names nothing.

Role autogroups are recognized only when the user roster was read. Without that live tailnet fact no caller can decide them, so a non-match must be reported as unresolved rather than as absence of coverage.

A cross-tailnet selector is recognized only in the one case whose non-match is conclusive: it is well-formed, this policy's external-tailnet declarations were read, and its alias is not among them, so it is named by nothing here. A declared alias needs the other tailnet's roster, and a malformed selector is an authoring error, so neither is recognized.

Every other autogroup defers to KnownAutogroup rather than being re-listed here, and the cross-tailnet case defers to crossTailnetSpecFor for the same reason. Recognized is the policy-aware view of questions KnownAutogroup and IsCrossTailnetSelector answer for callers holding less, and a second copy of either list would drift the moment one learned a new form — the drift this package exists to prevent.

type Policy

type Policy struct {
	*tailscale.ACL

	// HaveExternalTailnets reports that ExternalTailnets was read from the
	// policy document. It draws the distinction HaveRoles draws for the user
	// roster: a nil map with this set means the policy declares no external
	// tailnets, which settles an undeclared alias as a definite non-match,
	// while a nil map with it clear means the caller never parsed the field,
	// which settles nothing. A caller that does not parse externalTailnets
	// must leave it false, or a cross-tailnet selector it cannot evaluate is
	// reported as provably unmatched.
	HaveExternalTailnets bool
}

Policy is a tailnet policy document: the pinned SDK's ACL together with the read flags no SDK can carry. The ACL is embedded, so Groups, Hosts, IPSets, and ExternalTailnets stay promoted and the matching walk reads the document exactly as it did when Matcher held a bare *tailscale.ACL.

It exists so a hand-modeled policy field has one home rather than widening Matcher each time this repository models another. ExternalTailnets was the first: declarative node sharing is alpha, and tailscale.v2.ACL carried no externalTailnets field until v2.11.0. The SDK models it now, so the hand-modeled field is gone and the promoted one serves; what stays here is the read flag, which records a fact about the caller rather than the document.

Directories

Path Synopsis
Package addrspace provides policy-agnostic address-space primitives for comparing route CIDRs and deriving site IDs from Tailscale 4via6 prefixes.
Package addrspace provides policy-agnostic address-space primitives for comparing route CIDRs and deriving site IDs from Tailscale 4via6 prefixes.
Package alpha is the shared convention for hand-modeling a Tailscale feature that is alpha or unreleased in the pinned tailscale.com/client/tailscale/v2 SDK, so a tool in this repo can pick up an alpha feature early instead of waiting for the SDK to catch up.
Package alpha is the shared convention for hand-modeling a Tailscale feature that is alpha or unreleased in the pinned tailscale.com/client/tailscale/v2 SDK, so a tool in this repo can pick up an alpha feature early instead of waiting for the SDK to catch up.
Package cliflags adapts stdlib-flag-era command lines to pflag parsing.
Package cliflags adapts stdlib-flag-era command lines to pflag parsing.
Package hujsonedit provides schema-agnostic, comment-preserving RFC 6902 edits to HuJSON documents: build PatchOperation values with PatchAdd, PatchRemove, PatchComment, and PatchCommentOverwrite, then apply them with WritePatch to a file or with PatchBytes to a document held in memory.
Package hujsonedit provides schema-agnostic, comment-preserving RFC 6902 edits to HuJSON documents: build PatchOperation values with PatchAdd, PatchRemove, PatchComment, and PatchCommentOverwrite, then apply them with WritePatch to a file or with PatchBytes to a document held in memory.
Package ipcalc provides policy-agnostic subnet arithmetic.
Package ipcalc provides policy-agnostic subnet arithmetic.
Package posture evaluates Tailscale device-posture rule expressions against a captured device's facts.
Package posture evaluates Tailscale device-posture rule expressions against a captured device's facts.
Package sanitize defines the repository-wide output-sanitization contract.
Package sanitize defines the repository-wide output-sanitization contract.
sanitizetest
Package sanitizetest provides assertions for output-sanitization tests.
Package sanitizetest provides assertions for output-sanitization tests.

Jump to

Keyboard shortcuts

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