Skills von blackbook: network/headscale-vpn
This commit is contained in:
@@ -1,111 +1,50 @@
|
|||||||
---
|
---
|
||||||
name: headscale-vpn
|
name: headscale-vpn
|
||||||
description: Deploy headscale TUN server on arm64 macOS.
|
description: Use when managing Robbi's headscale tailnet. Prod+local.
|
||||||
version: 1.0.0
|
version: 2.0.0
|
||||||
author: robertrapp
|
author: robertrapp
|
||||||
license: MIT
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
hermes:
|
||||||
|
tags: [headscale, tailscale, vpn, dns, wodanio]
|
||||||
|
related_skills: [openwrt-ap-dns-pihole]
|
||||||
---
|
---
|
||||||
|
|
||||||
# headscale-vpn
|
# headscale-vpn
|
||||||
|
|
||||||
Use when deploying headscale TUN server on arm64 macOS for VPN node management and registration.
|
Class: anything about Robbi's headscale/Tailscale tailnet — node registration, routes, DNS, ACL, config
|
||||||
|
changes on the production server, or a local test deployment.
|
||||||
|
|
||||||
## When to Use
|
## Always-on rules
|
||||||
User needs to set up headscale TUN server on arm64 macOS for VPN node registration and traffic routing.
|
- **Credentials**: never print or store real keys/tokens; show them as `[REDACTED]`. Load `~/Wodanio/.env`
|
||||||
|
inside scripts instead of echoing values.
|
||||||
|
- **Find out where headscale actually runs before planning edits.** Production (`vpn.robbis.space`) is a
|
||||||
|
container service on Wodanio DSPS, configured purely by `HEADSCALE_*` env vars — no config file, no SSH.
|
||||||
|
Details and API calls: `references/wodanio-production.md`.
|
||||||
|
- **Consent gate**: if the real setup differs from what the requester assumed (env vars instead of a file,
|
||||||
|
platform-managed config, untested setting syntax, restart side effects), stop and ask with concrete options
|
||||||
|
and a recommendation. Read-only inspection and a local backup are fine to do first.
|
||||||
|
- **Don't guess the user** for registrations — list users first.
|
||||||
|
|
||||||
## Trigger
|
## Procedure: change production config (DNS, routes, etc.)
|
||||||
User needs to set up headscale TUN server on arm64 macOS for VPN node registration and traffic routing.
|
1. `GET /v1/container` -> headscale id; `GET /v1/container/{id}` -> current envs + podId.
|
||||||
|
2. Back up the full service JSON locally (chmod 600) — this is the "config backup".
|
||||||
|
3. Read-only state via exec (`headscale nodes list`, `nodes list-routes`) or the REST API.
|
||||||
|
4. Ask if anything is non-obvious (see consent gate); then `PATCH /v1/container/{id}` with the changed envs
|
||||||
|
(this redeploys = restart).
|
||||||
|
5. Verify: pod state `running`, `headscale configtest`/`version` via exec, `nodes list` still shows all nodes,
|
||||||
|
and the change is visible on a client (e.g. `tailscale dns status`). Roll back from the backup on failure.
|
||||||
|
|
||||||
## Workflow
|
## DNS decision rules
|
||||||
|
- `.lan` names need a split nameserver `lan -> 192.168.178.35` (Pi-hole); global Cloudflare can't resolve them.
|
||||||
|
- Global DNS = a LAN IP only works for nodes that accept the subnet route. An approved `192.168.178.0/24`
|
||||||
|
route is necessary but not sufficient: check `tailscale status` health on clients ("--accept-routes is
|
||||||
|
false") — such nodes would lose all DNS away from home. Offer: split-only / global+enable accept-routes /
|
||||||
|
Pi-hole via its tailnet IP (needs Pi-hole to permit all origins).
|
||||||
|
- Test resolvers directly before proposing them: `dig +short +time=3 +tries=1 @<ip> jellyfin.lan`.
|
||||||
|
|
||||||
### 1. Binary Acquisition
|
## References
|
||||||
- Download headscale binary from GitHub releases: `curl -sL "https://github.com/juanfont/headscale/releases/download/v0.29.7/headscale_0.29.7_darwin_arm64" -o /tmp/headscale && chmod +x /tmp/headscale`
|
- `references/wodanio-production.md` — DSPS API, exec/podId, env-var config model, backup/rollback, network facts.
|
||||||
- Verify binary: `/tmp/headscale --version`
|
- `references/local-macos-deploy.md` — standalone test server on arm64 macOS (binary, config, socket pitfalls).
|
||||||
- pip/brew installation is unavailable — use manual binary download only
|
- `references/headscale-config.md` — full config template.
|
||||||
|
- `scripts/headscale-probe.sh` — server/socket probe for local deployments.
|
||||||
### 2. Configuration
|
|
||||||
Create config with ALL required fields:
|
|
||||||
```yaml
|
|
||||||
listen_addr: 0.0.0.0:8080
|
|
||||||
server_url: http://127.0.0.1:8080
|
|
||||||
backend:
|
|
||||||
type: sqlite
|
|
||||||
sqlite:
|
|
||||||
path: /tmp/headscale.db
|
|
||||||
noise:
|
|
||||||
private_key_path: /tmp/noise_key.pem
|
|
||||||
dns:
|
|
||||||
nameservers:
|
|
||||||
global:
|
|
||||||
- 8.8.8.8
|
|
||||||
override_local_dns: false
|
|
||||||
auth:
|
|
||||||
method: file
|
|
||||||
file:
|
|
||||||
prefix: 100.64.0.0/10
|
|
||||||
```
|
|
||||||
|
|
||||||
**Critical**: The `noise.private_key_path` and `auth.file.prefix` fields are REQUIRED. Missing these will cause config load failures.
|
|
||||||
|
|
||||||
### 3. Server Startup
|
|
||||||
- Start server with config: `/tmp/headscale serve -c /tmp/headscale_config.yaml`
|
|
||||||
- Use foreground mode for initial setup to see errors
|
|
||||||
- Use `HEADSCALE_CONFIG` env var to point to config file
|
|
||||||
- Server socket path: CLI always expects `/var/run/headscale/headscale.sock` — config socket_path must match or connection will fail
|
|
||||||
|
|
||||||
### 4. User/Node Management
|
|
||||||
- List users: `/tmp/headscale -c <config.yaml> users list --output json`
|
|
||||||
- Register new node: `headscale nodes register --user <user> --key <pre-auth-key> --output json`
|
|
||||||
- After registration, verify with: `headscale nodes list --output json`
|
|
||||||
- If socket connection times out, check that server process is running and socket file exists
|
|
||||||
|
|
||||||
## Pitfalls & Gotchas
|
|
||||||
|
|
||||||
- **No pip/brew**: `pip install headscale` fails — use manual binary download from GitHub releases
|
|
||||||
- **Config format**: `noise.private_key_path` and `auth.file.prefix` are REQUIRED fields
|
|
||||||
- **Socket path**: CLI always expects `/var/run/headscale/headscale.sock` — config socket_path must match or connection will fail
|
|
||||||
- **User determination**: If unknown which user new PC should belong to, list users first: `/tmp/headscale users list --output json` — do NOT guess the user
|
|
||||||
- **Credential rule**: All API keys, tokens, passwords, secrets, connection strings must be replaced with `[REDACTED]` — never retain actual values
|
|
||||||
|
|
||||||
## Support Files
|
|
||||||
- `references/headscale-config.md` — complete config template
|
|
||||||
- `scripts/headscale-probe.sh` — verification script for server status and socket existence
|
|
||||||
|
|
||||||
## Example
|
|
||||||
```bash
|
|
||||||
# Download binary
|
|
||||||
curl -sL "https://github.com/juanfont/headscale/releases/download/v0.29.7/headscale_0.29.7_darwin_arm64" -o /tmp/headscale && chmod +x /tmp/headscale
|
|
||||||
|
|
||||||
# Create config
|
|
||||||
cat > /tmp/headscale_config.yaml << 'EOF'
|
|
||||||
listen_addr: 0.0.0.0:8080
|
|
||||||
server_url: http://127.0.0.1:8080
|
|
||||||
backend:
|
|
||||||
type: sqlite
|
|
||||||
sqlite:
|
|
||||||
path: /tmp/headscale.db
|
|
||||||
noise:
|
|
||||||
private_key_path: /tmp/noise_key.pem
|
|
||||||
dns:
|
|
||||||
nameservers:
|
|
||||||
global:
|
|
||||||
- 8.8.8.8
|
|
||||||
override_local_dns: false
|
|
||||||
auth:
|
|
||||||
method: file
|
|
||||||
file:
|
|
||||||
prefix: 100.64.0.0/10
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Generate noise key
|
|
||||||
/tmp/headscale generate private-key -o /tmp/noise_key.pem
|
|
||||||
|
|
||||||
# Start server
|
|
||||||
/tmp/headscale serve -c /tmp/headscale_config.yaml &
|
|
||||||
|
|
||||||
# List users
|
|
||||||
/tmp/headscale -c /tmp/headscale_config.yaml users list --output json
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
*Skill captures workflow for headscale TUN server on arm64 macOS, including binary download, config requirements, socket path pitfalls, and user preference for [REDACTED] credentials.*
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Local/test headscale on arm64 macOS
|
||||||
|
|
||||||
|
1. Binary from GitHub releases (manual download is the reliable path):
|
||||||
|
`curl -sL https://github.com/juanfont/headscale/releases/download/v0.29.7/headscale_0.29.7_darwin_arm64 -o /tmp/headscale && chmod +x /tmp/headscale && /tmp/headscale version`
|
||||||
|
2. Config — `noise.private_key_path` and the IP prefix are required or config load fails:
|
||||||
|
```yaml
|
||||||
|
listen_addr: 0.0.0.0:8080
|
||||||
|
server_url: http://127.0.0.1:8080
|
||||||
|
backend: {type: sqlite, sqlite: {path: /tmp/headscale.db}}
|
||||||
|
noise: {private_key_path: /tmp/noise_key.pem}
|
||||||
|
dns: {nameservers: {global: [8.8.8.8]}, override_local_dns: false}
|
||||||
|
auth: {method: file, file: {prefix: 100.64.0.0/10}}
|
||||||
|
```
|
||||||
|
3. `/tmp/headscale generate private-key -o /tmp/noise_key.pem`, then run `serve -c <cfg>` in the foreground first
|
||||||
|
to see errors (or set `HEADSCALE_CONFIG`).
|
||||||
|
4. The CLI talks to the unix socket; if the config's socket path differs from the CLI default
|
||||||
|
(`/var/run/headscale/headscale.sock`), pass `-c <cfg>` so both agree — otherwise CLI calls time out.
|
||||||
|
5. Users/nodes: `users list --output json`, `nodes register --user <user> --key <key>`, `nodes list --output json`.
|
||||||
|
|
||||||
|
See also `references/headscale-config.md` and `scripts/headscale-probe.sh`.
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# Production headscale on Wodanio DSPS
|
||||||
|
|
||||||
|
Robbi's real tailnet control server (`https://vpn.robbis.space`, MagicDNS base `ts.robbis.space`) runs as a
|
||||||
|
container service named `headscale` on the Wodanio DSPS platform, NOT on a host you can SSH into.
|
||||||
|
Credentials live in `~/Wodanio/.env` (DSPS token and headscale API key). Load them in the script; never print
|
||||||
|
values. Device docs: `~/Wodanio/tailnet/GERAETE.md`, ACL: `~/Wodanio/tailnet/policy.hujson`.
|
||||||
|
|
||||||
|
## DSPS API (base `https://dsps1.zlg-dc1.wodanio.net`, bearer auth with the DSPS token)
|
||||||
|
- Spec is embedded in `/v1/docs/swagger-ui-init.js` (`swaggerDoc` object); `/v1/docs/swagger.json` returns HTML.
|
||||||
|
Fetch it with subprocess and `json.JSONDecoder().raw_decode` from the first `{` after `"swaggerDoc"` —
|
||||||
|
the terminal tool truncates the big output and breaks parsing.
|
||||||
|
- `GET /v1/container` -> list services (headscale, traefik, nats). `GET /v1/container/{id}` -> full definition
|
||||||
|
incl. `envs[]` (`{key,value}`), `volumes`, `proxies`, `podStatus[].podId`.
|
||||||
|
- `POST /v1/container/{id}/exec` body `{"podId": "<podStatus[0].podId>", "command": ["/ko-app/headscale", ...]}`
|
||||||
|
— podId is required. The image is distroless (ko): no `ls`/`sh`; only `/ko-app/headscale` runs.
|
||||||
|
- `PATCH /v1/container/{id}` changes the service and redeploys it (= restart). DSPS access is over the public
|
||||||
|
internet, so a headscale restart does not cut off agent access.
|
||||||
|
- When redacting output, mask by env *name*, not by a field called `key` — DSPS env entries use a `key`
|
||||||
|
field for the variable name.
|
||||||
|
|
||||||
|
## Config model
|
||||||
|
- There is NO config file (`WRN no config file found, using defaults`). All settings are `HEADSCALE_*` env vars
|
||||||
|
on the DSPS service, e.g. `HEADSCALE_DNS_MAGIC_DNS=true`, `HEADSCALE_DNS_BASE_DOMAIN=ts.robbis.space`,
|
||||||
|
`HEADSCALE_DNS_NAMESERVERS_GLOBAL=1.1.1.1 1.0.0.1` (space-separated list), `HEADSCALE_POLICY_MODE=database`.
|
||||||
|
- "Backup the config" = save the full `GET /v1/container/{id}` JSON locally (e.g.
|
||||||
|
`~/Wodanio/headscale-container.bak-<date>.json`, chmod 600) before any PATCH; restore by PATCHing envs back.
|
||||||
|
- Map-valued settings (`dns.nameservers.split`) have no obvious env form; a JSON string in
|
||||||
|
`HEADSCALE_DNS_NAMESERVERS_SPLIT` is unverified. After any change, verify with `headscale configtest` via exec
|
||||||
|
and check a node actually receives it; roll back from the backup if not. Mounting a real config.yaml into the
|
||||||
|
`/var/lib/headscale` volume is the alternative (changes how the service is configured -> ask first).
|
||||||
|
|
||||||
|
## Read-only checks via exec
|
||||||
|
- `headscale version`, `headscale nodes list`, `headscale nodes list-routes` (columns Approved/Available/Serving).
|
||||||
|
- Same data via headscale REST `GET /api/v1/node` (fields `availableRoutes`, `approvedRoutes`, `subnetRoutes`,
|
||||||
|
`online`).
|
||||||
|
|
||||||
|
## Home network facts relevant to DNS
|
||||||
|
- Pi-hole: `192.168.178.35` (the `nas` node, tailnet 100.64.0.3). Resolves `.lan` names. Does not answer on its
|
||||||
|
tailnet IP unless Pi-hole is set to permit all origins.
|
||||||
|
- Subnet router: node `rpi` advertises+approved `192.168.178.0/24` (autoApprovers).
|
||||||
Reference in New Issue
Block a user