Skip to content

Headscale user isolation

Documents how per-user network isolation was configured on the headscale.castis.io tailnet, running in Kubernetes (namespace headscale, StatefulSet headscale).


The problem

By default, Headscale (like Tailscale) applies an allow-all policy when no policy file is configured — every device on the tailnet can reach every other device, regardless of which user registered it. This meant any user's devices could reach any other user's devices, which wasn't desired.

The goal

Each user should only be able to reach their own devices. A user with multiple devices (e.g. phone + laptop) should still be able to use them together — only cross-user access should be blocked.

A later requirement was added: a subnet route (<OFFICE_LAN_CIDR>, advertised by node nuc-b) should be reachable by the castis user only — hotel should not be able to reach it.


Confirmed environment

kubectl get statefulset headscale -n headscale -o jsonpath='{.spec.template.spec.containers[0].image}'
# headscale/headscale:v0.28.0

v0.28.0 is the current latest stable release (confirmed directly against GitHub's release page — it carries the "Latest" tag). This matters because the newer grants policy syntax (seen in some current documentation) is not available in any stable release — it only exists in v0.29.0-beta.x pre-releases as of this writing. Using it would have meant running pre-release software unnecessarily.

Users on this tailnet (headscale users list):

ID Username
1 castis
2 hotel

The solution: autogroup:self via the legacy acls field

{
  "acls": [
    {
      "action": "accept",
      "src": ["autogroup:member"],
      "dst": ["autogroup:self:*"]
    }
  ]
}

Confirmed working on v0.28.0 — no upgrade required. autogroup:self was added in v0.27.0 (marked experimental at the time) and had a related bug fix shipped in v0.28.0 itself ("Fix autogroup:self preventing visibility of nodes matched by other ACL rules"), so it's genuinely supported and stable-ish on this version, despite the "experimental" label from its original introduction.

What this rule means

  • src: ["autogroup:member"] — applies to any regular (untagged) user device
  • dst: ["autogroup:self:*"] — but only allows reaching devices where the same user is authenticated on both ends. The :* suffix means "any port" — required syntax for the legacy acls format (unlike the newer grants format, which uses a separate ip field instead).

Why NOT grants (a real mistake made and corrected during setup)

The first attempt used:

{
  "grants": [
    { "src": ["autogroup:member"], "dst": ["autogroup:self"], "ip": ["*"] }
  ]
}
This failed with:
FTL ... parsing policy: unknown field "grants"
grants support was added in v0.29.0 (GitHub issue #2180) — a version that doesn't have a stable release yet. The corrected acls-based rule above achieves the identical outcome and is fully compatible with the actual running version.


Update: restricting the <OFFICE_LAN_CIDR> subnet route to castis only

Background

Node nuc-b advertises the route <OFFICE_LAN_CIDR>. Confirmed via:

kubectl exec -n headscale headscale-0 -- headscale nodes list-routes
ID | Hostname | Approved       | Available      | Serving (Primary)
2  | nuc-b    | <OFFICE_LAN_CIDR> | <OFFICE_LAN_CIDR> | <OFFICE_LAN_CIDR>
The route itself was already approved, available, and serving — so the initial inability of other users to reach it was not a routing/approval problem. It was an ACL gap: autogroup:self:* only grants a user access to their own devices, not to a subnet routed by another node — even one belonging to the same user. Reaching a routed subnet always requires its own explicit dst entry.

Rule added

{
  "action": "accept",
  "src": ["castis@"],
  "dst": ["<OFFICE_LAN_CIDR>:*"]
}
  • src: ["castis@"] — the user@ token format is how headscale policies reference a specific user directly (without a groups block). This is headscale's own internal terminology for the token — its changelog explicitly describes validating that a user@ token resolves to exactly one user in the database, and instructs renaming duplicates via headscale users rename if a token would otherwise match more than one. With exactly one castis and one hotel user on this tailnet, "castis@" resolves unambiguously.
  • dst: ["<OFFICE_LAN_CIDR>:*"] — grants access to the entire subnet, any port.
  • hotel@ is not referenced anywhere in the policy. Once any acls are defined, headscale defaults to deny for anything not explicitly matched — so hotel is denied access to the subnet with no extra rule needed.

A groups wrapper (e.g. "group:castis": ["castis@"]) was considered but intentionally not used — direct reference in src was preferred for simplicity, since there is currently only one user in scope. This can be revisited if castis grows to include multiple headscale users later (at that point, wrapping in a groups block avoids having to add a new acls rule per user).

Validating before applying

Before rolling changes to the live ConfigMap, the policy file should be checked directly:

kubectl exec -n headscale headscale-0 -- headscale policy check -f /etc/headscale/policy.json
If the ConfigMap hasn't been applied to the pod yet, the candidate file can instead be copied in and checked without touching the live config first:
kubectl cp ./policy.json headscale/headscale-0:/tmp/policy.json
kubectl exec -n headscale headscale-0 -- headscale policy check -f /tmp/policy.json

Node-level caveat (separate from the ACL)

nuc-b must have IP forwarding enabled at the OS level, or the route can show as "serving" in headscale while still silently dropping packets:

sysctl net.ipv4.ip_forward   # should return 1


How the policy file was deployed

Since the StatefulSet's config volume mounts the entire headscale-config ConfigMap as a directory (not a single file via subPath):

volumeMounts:
  - name: config
    mountPath: /etc/headscale
volumes:
  - name: config
    configMap:
      name: headscale-config

...adding a new key to that same ConfigMap automatically creates a new file in /etc/headscale/ inside the pod — no changes to the StatefulSet spec were needed at all.

Final ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: headscale-config
  namespace: headscale
data:
  config.yaml: |
    server_url: https://headscale.castis.io
    listen_addr: 0.0.0.0:8080
    metrics_listen_addr: 0.0.0.0:9090
    grpc_listen_addr: 0.0.0.0:50443
    private_key_path: /var/lib/headscale/private.key
    noise:
      private_key_path: /var/lib/headscale/noise_private.key
    prefixes:
      v4: <TAILNET_IPV4_PREFIX>
    derp:
      urls:
        - https://controlplane.tailscale.com/derpmap/default
      auto_update_enabled: true
      update_frequency: 24h
    database:
      type: sqlite
      sqlite:
        path: /var/lib/headscale/db.sqlite
    dns:
      magic_dns: true
      base_domain: ts.castis.io
      override_local_dns: false
    policy:
      path: /etc/headscale/policy.json
    log:
      level: info
  policy.json: |
    {
      "acls": [
        {
          "action": "accept",
          "src": ["autogroup:member"],
          "dst": ["autogroup:self:*"]
        },
        {
          "action": "accept",
          "src": ["castis@"],
          "dst": ["<OFFICE_LAN_CIDR>:*"]
        }
      ]
    }

Changes from the original ConfigMap: 1. Added policy: path: /etc/headscale/policy.json inside config.yaml 2. Added the policy.json: key with the base autogroup:self rule 3. (latest) Added a second acls rule granting castis@ access to <OFFICE_LAN_CIDR>:*, leaving hotel with no access to that subnet by default-deny

Apply

kubectl apply -f headscale-config-with-policy.yaml
kubectl rollout restart statefulset headscale -n headscale

Verification performed

kubectl logs -n headscale headscale-0 --tail=50 | grep -i -E "policy|error|FTL"
No fatal errors — policy loaded successfully on restart.

kubectl exec -n headscale headscale-0 -- headscale policy get
Confirms the live policy matches what was configured.

Real functional test — confirmed working: logging in as a specific user and running tailscale status showed only that user's own device(s) — other users' devices did not appear in the list.

Subnet route test (to confirm after applying the latest rule): - From a castis device: reach a host inside <OFFICE_LAN_CIDR> — should succeed. - From a hotel device: same test — should fail.


A separate question came up: could this StatefulSet be scaled to 2 replicas for redundancy? No.

  • The config uses database.type: sqlite, and Headscale's own maintainers state it "has built-in assumptions that you have a single-writer database" — Headscale explicitly does not support active-active multi-instance operation natively (confirmed via open GitHub feature request #2695, still unresolved).
  • Since this is a StatefulSet with volumeClaimTemplates, each replica would get its own separate PVC — meaning 2 replicas would each have an independent, unsynchronized SQLite database, causing a genuine split-brain depending on which pod a client's traffic happened to hit.
  • Achieving real HA would require migrating to PostgreSQL at minimum, and even then, genuine active-active isn't officially supported — community workarounds exist (e.g. Consul + LiteFS for leader-election-based failover) but add real operational complexity disproportionate to this setup's needs.

Decision: stay at replicas: 1. Kubernetes' own StatefulSet self-healing (recreating a crashed pod automatically) already provides adequate resilience for this use case without the added complexity/risk of multi-instance operation.


Troubleshooting reference

Symptom Cause Fix
FTL ... parsing policy: unknown field "grants" grants syntax used, but running version is v0.28.0 (grants requires v0.29.0+, not yet stable) Use the acls + autogroup:self:* syntax instead (see above) — no upgrade needed
Policy changes don't seem to take effect ConfigMap updated but pod never restarted to pick up the new mount content kubectl rollout restart statefulset headscale -n headscale
Users still see each other's devices after applying policy Pod didn't actually restart, or policy file has a syntax error that failed silently Check kubectl logs -n headscale headscale-0 --tail=50 \| grep -i policy for load confirmation; re-check kubectl exec -n headscale headscale-0 -- headscale policy get matches expected content
A single user's own multiple devices can't reach each other anymore Policy rule too restrictive / autogroup:self misconfigured Confirm the rule uses autogroup:member as source and autogroup:self:* as destination exactly as shown above
Route shows Approved/Available/Serving but no user other than the router itself can reach the subnet autogroup:self does not extend to routed subnets — no dst rule existed for the CIDR Add an explicit acls rule with dst: ["<CIDR>:*"] scoped to the intended src user(s)
Need to restrict a subnet to one user, not all users Missing per-user src scoping on the subnet rule Use "src": ["<username>@"] directly, or wrap in a groups block if multiple users need to share access
Considering scaling to 2+ replicas for HA SQLite + per-replica PVC causes split-brain; Headscale doesn't officially support active-active Stay at 1 replica; rely on Kubernetes' StatefulSet self-healing instead

Version reference

Component Version
Headscale v0.28.0 (confirmed current latest stable at time of setup)
Policy syntax used Legacy acls (not grants — that requires v0.29.0+, not yet stable)
Key features autogroup:self (added v0.27.0, bug-fixed in v0.28.0); user@ token addressing for per-user subnet route restriction