Skip to content

The VPN (Headscale / Tailscale)

The VPN links the zones, the coordination server and remote devices : Headscale 🡕 coordinates from the HCS, Tailscale 🡕 is the client on each node. This page gathers the operating procedures. Routing, DNS, MagicDNS, access policy and keys are explained in How the tailnet works.

Enabling coordination and declaring the HCS (profile: hcs) is enough :

etc/config.yaml
network:
coordination:
enable: true
hostname: "hcs"
domain: "headscale"

The role of each node follows from the topology :

NodeIdentityRole
HCStag:hcscoordination, pivot DNS, global services, exit node (closed)
Gatewaytag:gw-<zone>subnet router : advertises the /16 of its zone
Admin workstationtag:adminSSH to all machines
Personal deviceits ownerservices, according to its groups

An admin workstation is a host whose groups contains admin and whose host file enables the client :

usr/machines/portable/configuration.nix
darkone.service.tailscale.enable = true;
darkone.service.tailscale.autoPauseOnLan.enable = true;

autoPauseOnLan pauses the client when the laptop is plugged into a zone (NetworkManager required).

Machines join the tailnet without a shared key : the HCS creates a single-use key for each one, with its declared tags. just configure handles it, so does just full-install. The recipe alone can be rerun at any time :

Fenêtre de terminal
just tailnet-enroll gw
[ DNF ] TAILNET • gw not enrolled, backend NeedsLogin: sending a single-use key...
[ DNF ] TAILNET • gw: gw tag:gw-maison 100.64.0.8

It is idempotent :

SituationEffect
Node enrolled, name and tags compliantnothing (already enrolled)
Tags or name differcorrected on the HCS, without reconnection
Never enrolled, deleted or reinstallednew key, registration
Old node with the same name offlinedeleted, the new one takes the name
Old node with the same name onlinerefused : two machines carry this name
Host without Tailscale clientignored

The mechanism is detailed in Activation keys and enrollment.

A gateway enrolls like any machine ; two points are specific to it.

  1. Check the route of its zone

    The gateway advertises the /16 of its zone, which the policy approves automatically for tag:gw-<zone>. On the HCS :

    Fenêtre de terminal
    sudo headscale nodes list-routes
  2. Declare its tailnet address

    The HCS reaches the zone resolver through this address (pivot DNS), as do the services that target it (backups, monitoring). Read it from the output of just tailnet-enroll, then report it :

    etc/config.yaml
    zones:
    maison:
    gateway:
    vpn:
    ipv4: "100.64.0.8"
  3. Propagate the address

    Fenêtre de terminal
    just generate
    just apply hcs
    just apply gw-atelier # passerelle du poste d'administration, si autre zone
    just apply gw

    The admin workstation resolves the short name gw through its zone’s gateway. If not redeployed since gw was added, it ignores it and just apply gw fails.

    Applying the gateway closes its public SSH (WAN, open until then). Also redeploy the other gateways and the hosts targeting this address. HeadscaleNodeDrift reports a declared address that no longer matches.

A smartphone or personal computer connects with the Kanidm identity of its owner : no key, no manual validation.

Can connectCondition in etc/config.yaml
Administratoradmin or nix-admin profile
Member of a zonezone-<zone> group
Member of an AI spacein the users of an ai-space host

These accounts form the Kanidm group tailnet, provisioned automatically ; Kanidm refuses the others. To open access, add the group to the user, regenerate, then just apply hcs. The user then follows Connect a device.

The device joins the web services (HTTPS) of its zones, of those of its AI spaces and of the HCS, nothing else. A Samba share, a printer or SSH requires a rule : see Adapting the access policy.

The device belongs to the person (alice@) and expires after 180 days : they then reconnect with their login.

Removing access : remove the group, just apply hcs, then delete their devices. Otherwise, they keep the DNS and HTTPS of the HCS until they expire (alert HeadscaleUnexpectedNode).

Fenêtre de terminal
sudo headscale nodes list # appareils, propriétaires, expiration
sudo headscale nodes expire -i <id> # forcer une reconnexion
sudo headscale nodes delete -i <id> # retirer l'appareil

The policy is generated from the topology : its rules are detailed in Access policy. Options adjust it, on the HCS :

Option darkone.service.headscale.DefaultEffect
policy.adminDevices{ }personal devices allowed SSH : name → tailnet IPv4
policy.exitNodeSources[ ]sources allowed to exit to the Internet via the HCS
policy.extraHosts{ }aliases of undeclared devices : name → CIDR
policy.extraAcls[ ]rules added after the generated rules
policy.enforcetruefalse : everything allowed, for migration only
nodeExpiry"180d"expiry of personal devices (0 : never)

Each declared host of a zone is already an alias (its name → its LAN address) : a rule targets nas:445 without going through extraHosts.

usr/machines/hcs/configuration.nix
darkone.service.headscale.policy = {
# SSH depuis le téléphone d'Alice (adresse lue dans `headscale nodes list`)
adminDevices.phone-alice = "100.64.0.9";
# Exit node du HCS ouvert aux administrateurs
exitNodeSources = [ "group:admins" ];
# Imprimante réseau pour tous les appareils personnels
extraHosts.printer = "10.0.4.10/32";
extraAcls = [
{
action = "accept";
src = [ "autogroup:member" ];
dst = [ "printer:631" ];
}
# Partage Samba du serveur `nas` (hôte déclaré) pour Alice
{
action = "accept";
src = [ "alice@" ];
dst = [ "nas:445" ];
}
];
};

Then just apply hcs : the policy is checked at build time, and Headscale reloads it without restarting.

On the HCS (just enter hcs) :

CommandUsage
sudo headscale nodes listnodes, owner, tags, addresses, expiry
sudo headscale nodes list-routesadvertised and approved routes
sudo headscale nodes rename -i <id> <nom>rename a node
sudo headscale nodes expire -i <id>force a reconnection
sudo headscale nodes delete -i <id>delete a node
sudo headscale users listpersonal device owners
sudo headscale preauthkeys listpre-authorized keys : tags, usage, expiry
sudo headscale policy getserved policy
sudo dnf-tailnet-enroll status <hôte>declared identity of a host

Tags and routes are not set by hand : just tailnet-enroll sets the declared tags, the policy approves the routes. The other client settings (advertised routes, Tailscale SSH disabled, exit node) are realigned by tailscaled-autoconnect, at startup and during deployments that change them.

CommandAnswers
tailscale statuspeers, online or not, direct path or relay
tailscale ping <nœud>real path : via <ip>:41641 (direct) or via DERP
tailscale whois <ip>node, tags or owner behind an address
tailscale dns statusMagicDNS, split DNS, search domains received
journalctl -u tailscaled-autoconnectlast record or realignment of settings

Without a --bypass… option, headscale policy check compiles a file against the real nodes and runs its tests block, without touching the policy in place.

  1. Start from the served policy :

    Fenêtre de terminal
    sudo headscale policy get > /tmp/policy.json
  2. Add a tests block : a source, then the expected destinations, each a single host (address and port) :

    "tests": [
    { "src": "alice@", "accept": ["100.64.0.8:443"], "deny": ["100.64.0.8:22"] }
    ]
  3. Check :

    Fenêtre de terminal
    sudo headscale policy check -f /tmp/policy.json
SymptomCheckRemedy
TailscaleUnhealthy, backend NeedsLogintailscale status on the nodejust tailnet-enroll <hôte>
Login showing headscale auth registerHeadscaleOidcFallback alertsudo systemctl restart headscale on the HCS
Kanidm refuses access to Headscale VPNuser’s groupsadmin profile, zone-<zone> or AI space member, just apply hcs
Zone unreachable from the tailnetheadscale nodes list-routesgateway enrolled with its tag, route approved
Zone service refused to a deviceuser’s groups, tailscale whois <ip>add zone-<zone>, just apply hcs
Non-web service unreachable (Samba, ping)policy rulespolicy.extraAcls rule
SSH refused on a tailnet addresstag:admin workstation or adminDevices devicedeclare the device
Internal names unresolved outside the zonetailscale dns statusenable “Use Tailscale DNS”
Login page not found“Use Tailscale DNS” activedisable it for the duration of the login
Slow traffictailscale ping shows via DERPoutbound UDP filtered, or strict NAT on both sides
no declared tailnet identitytagged host, HCS deployed from its declarationjust apply hcs
named … is online, not deleting ittwo machines carry the same nameturn off the old one or rename the host

Every 15 minutes, headscale-audit compares the real nodes to the declared topology, without changing anything. Details of the discrepancies are in its log :

Fenêtre de terminal
journalctl -u headscale-audit -n 20
AlertReportsAfter
HeadscaleNodeDriftHCS or gateway missing, wrong tags, address different from the declared one30 min
HeadscaleUnexpectedNodeundeclared tagged node, or device of an account outside the tailnet groupimmediately
HeadscalePolicyInvalidpolicy refused, or served policy different from the file30 min
HeadscaleOidcFallbackKanidm absent at Headscale startup : OIDC connections cutimmediately
HeadscaleNodeExpiringpersonal device expiring within 7 days1 h
HeadscaleAuditStaleaudit without success for more than one hourimmediately

All are warning, on the Prometheus that monitors the HCS. An absent admin workstation is not an anomaly ; when present, its tags are checked.

A tailscaled can silently drop off Headscale : the control connection is lost while the service stays “active”, and a gateway’s subnet becomes unreachable. A local watchdog detects and fixes this case, on every Tailscale client.

AspectBehavior
Probeevery 60 s : tailscale status (backend, online state)
Debounce3 consecutive failed probes (~3 min) before acting
Fixrestarts tailscaled, which reconnects to the control plane
Anti-loopone fix per 10 min window
Unenrolled nodeno restart (NeedsLogin) : just tailnet-enroll
Paused laptopwatchdog stopped, metric removed
Observabilitydnf_tailscale_healthy, dnf_tailscale_selfheal_restarts_total (textfile node_exporter)

Two alerts accompany the mechanism :

  • TailscaleUnhealthy : still disconnected after 10 min, despite the fix ;
  • TailscaleFlapping : more than 3 fixes in one hour.

On a gateway, dnsmasq sends every domain.tld query to the HCS resolver through the tailnet : the client would need the VPN to find the server that brings up the VPN. At boot, moreover, the local resolver is not yet listening.

Each Tailscale client therefore receives the HCS public address in its /etc/hosts, derived from etc/config.yaml (the HCS itself is excluded). dnsmasq answers this name from that file, without ever forwarding it :

Fenêtre de terminal
grep headscale /etc/hosts # 203.0.113.10 headscale.domain.tld

The client thus connects without any resolver, including when local DNS is down, precisely when self-repair must be able to act.

  • Personal device : see Connect a personal device.
  • Admin laptop : when away, it reaches all zones through the tailnet (just enter <hôte>). Plugged back into a zone, its client pauses and the local gateway takes over again.