Commit Graph
4892 Commits
Author SHA1 Message Date
Kristoffer Dalby 96d68fcbc4 state: apply map requests only under the node key that authorised them 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 4c98552b2d policy: offer exit routes only to viewers whose rules reach the internet
Every destination overlaps /0, so any rule offered a peer's exit routes.
They now need a rule to the internet, the test exit-node visibility
uses; via steering defers them to a regular grant only on that test.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby aca11eae02 mapper: send a router all of its own routes
Its AllowedIPs held only the primaries the policy let it reach. It now
holds every approved route, and PrimaryRoutes the ones it serves.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 87de37fc7a policy: reduce merged destination prefixes to the node's own addresses
Adjacent node addresses merge into one prefix, and each node's filter
kept all of it. A prefix made only of node addresses now shrinks to the
node's own; a prefix the policy wrote, or one the node routes, stays.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 12fb9fae43 api, policy/v2: refuse route prefixes with host bits
Routes are matched as written, so such a prefix never equals the one a
client announces. The approval APIs answer 400 and autoApprovers refuses
it at load and write, with Tailscale's text.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 1c8d768a21 policy, state: log only the routes auto-approval adds 2026-10-28 16:35:21 +00:00
Kristoffer Dalby cb10a23c61 poll: hold the map session's node as a view 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 7112fcd990 policy/matcher, types: compare a node's routes to matchers as ranges 2026-10-28 16:35:21 +00:00
Kristoffer Dalby cb2097ad65 policy/matcher: binary-search ranges in overlap checks 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 43e8802afc policy: look up approved routes in a set when auto-approving
Avoid scanning the growing approval list for every announcement.
Use the sorted current routes when identifying additions.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby e1ef18eadf types, state: reduce a node's routes against the matchers once
Reuse matcher membership and approved subnets across the route list.
Preserve route order and HA co-router visibility.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 9278affb2c types: derive subnet and exit routes in one pass
Emit each approved route once, in announcement order.
Skip derivation when no routes are approved.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 76883f724b state: skip route comparison for writes that leave routes alone
Reuse immutable route inputs when classifying NodeStore writes.
Only derive routes when an announcement or approval changes.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 66eada0995 state, policy/v2: stop treating announced-only routes as policy changes
Policy evaluation reads only announced-and-approved routes.
Keep publishing Hostinfo updates without rebuilding peer adjacency.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 0ae83ca9ca policy/v2, state: elect primaries by oldest control session
A router that reconnects joins as a standby; one that kept its session
takes its routes back once available again, as on Tailscale. Both the
global and the via election use it, in place of anti-flap stickiness.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby c8cf1bb157 types: add when a node's run of control sessions began 2026-10-28 16:35:21 +00:00
Kristoffer Dalby e221bbb74b state: keep a prefix mapped when no router is available
Peers keep the routes of an offline or expired router, as on Tailscale.
The previous primary keeps the prefix, else the lowest-ID approver;
never one the prober declared unreachable.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 6ffa89718a policy/v2, state: elect via primaries among online, healthy routers
Availability tests expiry itself, not only the online flag.
A health change on a via target now triggers a peer recompute.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby acb131a8c6 state: withhold HA probe results only for routers tied to a deferred one 2026-10-28 16:35:21 +00:00
Kristoffer Dalby b60e4a467d state: keep probing a lone advertiser while it is unhealthy 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 92490ef5e9 hscontrol, types: strip trailing slashes from server_url 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 4e8465102a db: bound the wait for a legacy hash verification slot 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 61321494b4 db: reload the credential row after a legacy hash verification 2026-10-28 16:35:21 +00:00
Kristoffer Dalby 6d23d0e42b db: disable GORM's prepared statement cache on SQLite
database.gorm.prepare_stmt is now ignored, with a startup warning.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 142a853267 policy/v2: refuse check SSH rules with tag sources
A check asks the source's user to log in again, and a tagged node has
none. Tailscale SaaS refuses the rule; headscale accepted it.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 0ee3cff157 policy/v2: limit the destination and port pairs a policy declares
A grant lists dst and ip apart, so its filter grows with their product.
Refuse a policy over 100,000 pairs, on every parse.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 6de71bdb73 policy/v2: refuse a port list in a grant ip entry
Tailscale SaaS takes one port range per ip entry; a list was accepted
and expanded. Write each range as an entry of its own.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby e6e1528859 policy/v2: evaluate policy tests before taking the write lock
SetPolicy ran the policy's tests under the lock every map response and
node write needs. Run them on a snapshot of users and nodes first.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 0e7db6e258 policy/v2: index compiled SSH rules by source for sshTests
Each check scanned every rule and parsed every principal per login name,
destination and source address. Compile once per run, key each
destination's rules by principal address, and evaluate a name once.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby a1e04d5d03 policy/v2: parse the compiled filter once per tests run
The tests evaluator parsed every SrcIPs and DstPorts entry again for
each assertion, source prefix and rule. Parse the filter once per run.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 8e9de2ec5f policy/v2: need every dst node for a tests accept, no range sources
An accept passes only when each node behind the dst is reached, as on
Tailscale SaaS; a deny keeps its rule. A CIDR, "*" or autogroup:tagged
src names no user or host, so its test fails.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 8992e88275 policy/v2: label sshTests failures with the dst alias
The report goes back to the policy author: name src and dst as written,
one line per dst occurrence, and a dst with no node as not reached.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby a214790243 policy/v2: bound the tests and sshTests failure report
The report printed every failure with the full labels, so its size was
labels times failures. Print 100 lines of 256-byte labels, then a count.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 1a40efe9ae policy/v2: refuse autogroup:member as an sshTests destination
Tailscale SaaS refuses it when parsing; headscale evaluated it.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 446965dc13 policy/v2: refuse address ranges as sshTests sources
A CIDR, or a hosts entry holding one, as an sshTests src is refused,
as on Tailscale SaaS. Destinations share the range check.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby bc25fac9e6 policy/v2: map login 0 to no local user in SSH rules
Every rule that maps root now carries "0": "", as Tailscale SaaS writes
it, also when the policy lists "0".
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 5d6648babf policy/v2: write an ACL's repeated destination once
An ACL that names a destination and port twice wrote the pair twice.
Grants keep their repeats, as on Tailscale SaaS.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 7aa0ebfc24 policy/v2: write a single-address via destination bare
Via rules wrote every destination with its prefix bits; ACL and grant
rules already drop them for a single address. Both use one formatter.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 53ab9284ee db: keep only the current policy
Every write inserted a row and nothing deleted one, while every reader
takes only the newest. Writers store and install under one lock, so an
uncommitted insert cannot outlive the newer row that pruned the rest.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 21ae79091a state: install a written policy only after it is stored
Writers validated by installing the policy live, so a store failure
left a refused or unstored policy enforced. Validate on a throwaway
manager, store, then reload from the stored row.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 13a4c22af0 policy/v2: refuse an empty policy
SetPolicy returned a nil error for empty input it ignored, so the v1
API stored it as valid. Reload skips only the nil "no policy" case.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby b102973c77 policy/v2: resolve tag owners one hop deep
A user claims only the tags it owns directly, and a tag owns only the
tags that list it, as on Tailscale SaaS. With no walk left, validate
names an undefined owner once, with the tag that lists it.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby b166f80914 policy/v2: evaluate sshTests sources through the nodes they cover
A src was expanded to every address it names, so "*" or ::/0 never
finished. Principals are node addresses: keep those plus one stand-in.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 381594e768 policy/v2: resolve each group once per policy compile
Group.resolve walked users and nodes for every member at every mention.
Resolve all groups once on a copy of the policy and compile from it.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby b8a772f51f policy/v2: compile SSH rules once and share them across nodes
SSHPolicy re-resolved every rule and built private principals per node.
Compile the rules once per policy, users and nodes; per node, only
select.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 75e0071527 policy/v2: merge rules sharing a source slice without rejoining it
The rules of one ACL now share one SrcIPs slice; key it once instead of
joining it again for every rule, globally and per node.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby f0c298bf96 policy/v2: resolve an ACL's sources once for all its destinations
An ACL compiles to one grant per destination, and each resolved and
rendered the same sources. ViaRoutesForPeer only needs one grant per
ACL.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 44e1e3fdef policy/v2: bound via route steering by the peer's routes
Include and Exclude held one entry per overlapping dst, and the election
walked them per dst. Keep one entry per route; a peer without routes
returns at once.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby d8f1651ab8 policy/v2: refresh clients when a user change drops the last via grant
SetUsers read needsPerNodeFilter after the recompile cleared it, so
the change was reported as empty and clients kept the via rules.
2026-10-28 16:35:21 +00:00
Kristoffer Dalby 4bb43e15f0 state: serialise policy reloads
Load and install the stored policy as one step, so an older
reload cannot install its document over a newer one.
2026-10-28 16:35:21 +00:00