#3493·headscale

[Bug] via exit-node steering is nullified by any non-via ACL rule matching the viewer

Author: HaaroleanCreated Sep 25, 2026Updated Sep 25, 2026

Is this a support request?

  • This is not a support request

Is there an existing issue for this?

  • I have searched the existing issues

(Closest existing: #3233 and #3408, both closed. This is the inverse of #3408 — there, via-matching exit nodes were wrongly hidden; here, non-matching ones are wrongly shown. I believe PR #3409 over-corrected.)


Current Behavior

A grant restricting internet access to a specific exit node via a tag steers traffic correctly, but does not remove the other exit nodes from the viewer's netmap. All exit nodes keep 0.0.0.0/0 and ::/0 in AllowedIPs, so they all appear in the client's exit-node picker. Selecting a non-permitted one produces a dead tunnel with no error.

The exclusion is computed correctly and then deleted again. The trigger is the presence of any non-via grant that the viewer matches — regardless of that grant's destination.

Root cause

hscontrol/policy/v2/policy.go, in ViaRoutesForPeer (line 1353 in v0.29.4, line 1421 on main):

go
result.Exclude = slices.DeleteFunc(result.Exclude, dstPrefix.Overlaps)

Three things combine:

  1. ACLs are appended to the grant list as non-via grants:

    go
    grants := pm.pol.Grants
    for _, acl := range pm.pol.ACLs {
        grants = append(grants, aclToGrants(acl)...)
    }
  2. Exit routes enter Exclude as 0.0.0.0/0 / ::/0, via matchedPrefixes = append(matchedPrefixes, peer.ExitRoutes()...).

  3. netip.Prefix.Overlaps is symmetric. 100.64.0.15/32 overlaps 0.0.0.0/0, because the default route contains every address.

So for every non-via grant the viewer matches, every one of its resolved destination prefixes deletes 0.0.0.0/0 from Exclude. A rule as ordinary as autogroup:member -> 100.64.0.15:53 is sufficient to disable via steering for every exit node in the tailnet.

The surrounding comment states the intent:

Match by overlap so a broader or narrower regular dst still catches the routes the via grant added to Include.

That reasoning holds for Include / UsePrimary on the preceding lines, where a regular grant legitimately defers to HA primary election. Reusing the same symmetric overlap for Exclude is the defect: for exit nodes the excluded prefix is the one prefix that overlaps everything.

Because the packet filter is a separate layer, traffic restriction still works — only the advertised routes are wrong. This makes the bug easy to miss: the policy looks enforced, but the client offers choices that silently fail.

Expected Behavior

An exit node that does not carry the grant's via tag should not advertise 0.0.0.0/0 / ::/0 to a viewer whose only route to autogroup:internet is through that grant, and should therefore not appear in that viewer's exit-node list.

Unrelated ACL rules should not affect this, regardless of their destination.

Steps To Reproduce

  1. Register two exit nodes, both advertising and approved for 0.0.0.0/0 + ::/0. Tag one tag:exit-a, the other tag:exit-b.

  2. Register a user-owned client node for user1@.

  3. Apply this policy:

    jsonc
    {
      "tagOwners": {
        "tag:exit-a": ["user1@"],
        "tag:exit-b": ["user1@"],
      },
      "grants": [
        {
          "src": ["autogroup:member"],
          "dst": ["autogroup:internet"],
          "ip":  ["*"],
          "via": ["tag:exit-a"],
        },
      ],
    }
  4. On the client: tailscale status --json. Only the tag:exit-a node has 0.0.0.0/0 in AllowedIPs. This is correct.

  5. Now add a single, unrelated ACL rule whose source matches the same viewer — any destination will do:

    jsonc
    "acls": [
      { "action": "accept", "src": ["autogroup:member"], "dst": ["autogroup:self:*"] },
    ],
  6. Reload the policy and re-check tailscale status --json. Both exit nodes now carry 0.0.0.0/0, and both appear in the picker. Traffic is still correctly restricted to tag:exit-a.

Step 5 is the whole bug: adding a rule that has nothing to do with exit nodes disables via steering for all of them.

Controlled confirmation on a live tailnet

Four approved exit nodes, one tagged tag:exit-public. Read from tailscale status --json, not the UI:

policy exit nodes with 0.0.0.0/0 in viewer's AllowedIPs
production (viewer matches 3 ordinary ACL rules) all four
identical, but every ACL source repointed away from the viewer only the tag:exit-public node
reverted to production all four again

To make the viewer match no non-via grant, every ACL source was repointed at a different user, and the viewer was removed from both groups it belonged to — including one whose only rule was group:ha -> <host>:8123, which triggers the same wipe.

Environment

markdown
- OS: Debian 13 (trixie), kernel 6.12.85
- Headscale version: 0.29.4 (also present on `main`)
- Tailscale version: 1.102.4 (macOS), 1.102.5 (linux); reproduced on iOS too
- Number of nodes: 18, of which 4 are approved exit nodes
- Policy mode: file
- TLS: headscale's built-in Let's Encrypt, no reverse proxy

Runtime environment

  • Headscale is behind a (reverse) proxy
  • Headscale runs in a container

Debug information

  • Code path: ViaRoutesForPeer (hscontrol/policy/v2/policy.go) -> State.RoutesForPeer (hscontrol/state/state.go:1303) -> MapResponseBuilder.buildTailPeers (hscontrol/mapper/builder.go:279), which calls RoutesForPeer unconditionally for every peer.
  • The existing tests TestViaRoutesForPeer and issue_3233_test.go::ViaRoutesForPeer_excludes_exit_for_other_tag pass, because they call ViaRoutesForPeer with policies that contain only grants. Adding one ACL rule matching the viewer should make the latter fail — that may be the cheapest regression test for this.

Suggested fix

Never let a narrower destination evict a default route:

go
result.Exclude = slices.DeleteFunc(result.Exclude, func(p netip.Prefix) bool {
    if tsaddr.IsExitRoute(p) && !tsaddr.IsExitRoute(dstPrefix) {
        return false
    }
    return dstPrefix.Overlaps(p)
})

On netmap dumps and trace logs

Deliberately not attached. The failure is fully determined by the policy and is reproducible from the six steps above on any two-exit-node tailnet — a netmap dump from my deployment would add node keys, tailnet addressing and client endpoints without adding information about the bug.

The observable is a single field: whether the non-via exit node carries 0.0.0.0/0 in the viewer's AllowedIPs. That flips purely on whether an unrelated ACL rule matching the viewer is present.

Happy to provide netmap dumps, trace logs or the full policy on request.


Disclosure: this report was written with the assistance of an LLM. The source analysis and the before/after AllowedIPs results were verified by hand against a live 0.29.4 deployment.