Skip to content

fix: back up the Tailscale device state - #58

Open
3alpha wants to merge 2 commits into
masterfrom
fix/backup-tailscale-state
Open

3alpha wants to merge 2 commits into
masterfrom
fix/backup-tailscale-state

Conversation

@3alpha

@3alpha 3alpha commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Problem

The package declares no manifest backup items, so Dappnode full backups (DNP_DAPPMANAGER#2511, #2512) mark it as "not covered". A restore reinstalls Tailscale with its settings, including TS_AUTHKEY, but without its state. The restored Dappnode becomes a new tailnet device. It gets new Tailscale IPs and a new MagicDNS name (often with a -1 suffix), its subnet routes and exit node must be approved again, and it needs a new sign-in or a still-valid auth key. The old device stays in the admin console.

Approach

Add one backup item to dappnode_package.json:

{ "name": "tailscaled-state", "path": "/var/lib/tailscale/tailscaled.state", "service": "tailscale" }

Why this file, based on the Tailscale v1.104.7 source:

  • The image sets TS_STATE_DIR=/var/lib/tailscale. containerboot passes it to tailscaled as --statedir (cmd/containerboot/tailscaled.go), and tailscaled then uses <statedir>/tailscaled.state as its state file (cmd/tailscaled/tailscaled.go, statePathOrDefault). The file lives in the state volume.
  • This file holds the irreplaceable data: the machine key, the login profiles and the per-profile prefs. Those prefs include the persisted node key, node ID and Tailnet Lock key (types/persist).
  • Tailscale state encryption with a TPM is not active here: it is only on when a policy enables it and a TPM is available. The file is therefore portable to new hardware.
  • Everything else in /var/lib/tailscale can be rebuilt or fetched again: the log buffers and tailscaled.log.conf, derpmap.cached.json, certs/, ssh/ host keys, tka-profiles/, profile-data/ and Taildrop files/. Leaving it out keeps the backup a few KB and avoids copying log buffers that are written while the package runs.
  • service: tailscale is required. Without it, Dappmanager uses the first container, which may be reporter.

Live-copy safety: Dappmanager reads the file while the package runs. FileStore.WriteState writes through atomicfile.WriteFile (temp file, fsync, rename), so the file is never half-written. In steady state, tailscaled rewrites the file only when its state changes, such as a pref change or key rotation.

Restore: Dappmanager installs the same version, stops the containers, extracts tailscaled.state into /var/lib/tailscale (other files there stay) and starts the containers. The image uses TS_AUTH_ONCE=true, so containerboot runs tailscale up only when the daemon reports NeedsLogin. With the restored identity, the daemon reaches Running and containerboot only reapplies TS_ROUTES and TS_EXTRA_ARGS with tailscale set.

The README has a new "Backup and restore" section. It warns that restoring the file onto a second machine while the old one runs leaves two machines with one node identity. Dappnode's full restore asks the user to keep the old node off. The section also tells users not to separate the copies with tailscale logout, which signs out the shared device on both. To give a node a new identity, remove the package with its data and sign in again.

Adding backup also makes Dappmanager show the package's Backup tab.

Compatibility with dappmanager versions without full backup

The released Dappmanager only has the per-package Backup tab, and it works with this item as is:

  • Backup: docker cp of tailscaled.state from the running container. The file is replaced atomically, so the copy is always one complete version.
  • Restore: docker exec ... mkdir -p /var/lib/tailscale, docker cp of the file into the running container, then docker restart. tailscaled runs as root, so the root-owned 0600 file is fine. tailscaled does not save its state on shutdown: LocalBackend.shutdown only logs out ephemeral nodes, and FileStore writes only from WriteState when a value changes. The restart therefore keeps the restored file, and tailscaled loads it.
  • Differences from a full restore, now documented in the README ("Compatibility with Dappmanager versions without full backup"): the tab restarts the package right away and does not ask whether the old node is off, so the old node must be switched off before the restore. If the package on the new Dappnode already signed in (interactively or with TS_AUTHKEY) before the restore, that registration stays as a separate offline device in the admin console and must be removed by hand.

No compose, image or version changes; the release workflow bumps the patch version on merge.

Test instructions

Checked locally: the package image (arm64 build) in two containers on --network none (userspace networking, no login, nothing reached Tailscale). The Backup tab flow was replayed with the exact docker cp / docker exec mkdir -p / tar / docker restart commands from backupGet.ts, backupRestore.ts and packageRestart.ts, run as root like the Dappmanager. Container A's state was backed up while A ran and restored into running container B, which has its own machine key. After the restart, and after a second restart, B's tailscaled.state still held A's _machinekey, owned 0:0, mode 0600, and tailscaled ran normally. A signed-in node could not be tested without a real login.

Static checks done:

  • dappnode_package.json validates against the Dappmanager manifest schema (packages/schemas/src/schemas/manifest.schema.json) with Ajv.
  • git diff --check passes.

Not run on a real node. To verify on a test Dappnode:

  1. Install this build and sign in to Tailscale. Note the device name, Tailscale IP and approved routes in the admin console.
  2. Create a full backup. The package must show as covered, with item tailscaled-state and no warning.
  3. Restore the backup onto a freshly installed Dappnode, with the original node switched off.
  4. Check that the admin console still shows one device with the same name, IP and routes, now online from the new machine, and that it did not ask to sign in again. Check that subnet routing to 172.33.0.0/16 and the Dappnode DNS still work from another tailnet device.
  5. Optional: the package's Backup tab downloads a tar that contains tailscaled-state. Restoring it there followed by the package restart keeps the same device.

Open points:

  • If TS_AUTHKEY is set and still valid, the package can start during the install step before Dappmanager stops it to restore data. It may then register a short-lived extra device with that key. The restored state then takes over, and the extra device has to be removed from the admin console by hand. Installing restored packages stopped would avoid this, but that is a Dappmanager change.
  • If the node key expired before the restore (key expiry enabled), the node rejoins as the same device but needs a new sign-in. With a valid TS_AUTHKEY, containerboot does this automatically.

Declare /var/lib/tailscale/tailscaled.state as a manifest backup item so full Dappnode backups keep the node identity and a restored node rejoins the tailnet as the same device without signing in again.
@tropibot

tropibot Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Dappnode bot has built and pinned the built packages to an IPFS node, for commit: 9a2d255

This is a development version and should only be installed for testing purposes.

  1. Package tailscale.dnp.dappnode.eth

Install link

Hash: /ipfs/QmdBGg8ojJQNMQw5qKxbq427x67EhNsBo2pskJ4EbXFtrj

(by dappnodebot/build-action)

@tropibot

tropibot Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

🛠️ Package harness hit an infrastructure error

MCP tool 'dappnode_fetch_install_preview' timed out

Package Verdict Reason Duration Cleanup
tailscale.dnp.dappnode.eth 🛠️ Infrastructure error Mcp unavailable (mcp_unavailable) 46s ⏭️ Skipped

Run overview

Context Value
Pull request dappnode/DAppNodePackage-tailscale#58
Tested commit 9a2d2554225a
Candidate artifact Install on DAppNode · /ipfs/QmdBGg8ojJQNMQw5qKxbq427x67EhNsBo2pskJ4EbXFtrj
Baseline request automatic
Worker dappnode-near-5
Run ID gh-pr-58-9a2d2554225a-089969f2201da3e0
Execution 2026-11-23T11:28:22.311639349+00:00 → 2026-11-23T11:29:08.470035911+00:00 (✅ Completed)

Baseline vs candidate

Check Baseline Candidate
Version 0.3.4 not reported
Install ✅ Passed · 0s ❌ Failed · 0s
Hard check ✅ Passed · 3 stable samples ❌ Failed · 0 stable samples
Containers 2 observed 0 observed
Stabilization 10s 0s
Log collection ✅ Passed · 2 containers ❌ Failed · 0 containers

Hard-check reasons

  • Baseline: none
  • Candidate: candidate_containers_unstable

Container comparison

  • Added: none
  • Removed: none
  • Baseline inventory: none
  • Candidate inventory: none
  • Baseline non-running states: none
  • Candidate non-running states: none
  • Deterministic regressions: ✅ none
Container inventory

Baseline

Container Service State Image Created
DAppNodePackage-tailscale.tailscale.dnp.dappnode.eth tailscale ✅ Running tailscale.tailscale.dnp.dappnode.eth:0.3.4 1794986923
DAppNodePackage-reporter.tailscale.dnp.dappnode.eth reporter ✅ Running reporter.tailscale.dnp.dappnode.eth:0.3.4 1794986923

Candidate

No container snapshot was available.

Runtime analysis advisory

⚪ Inconclusive — Log analysis was unavailable

Analyzer Status Summary
Heuristic ⚪ Inconclusive Log analysis was unavailable
Baseline evidence ⚪ Inconclusive Analysis unavailable
Candidate evidence ⚪ Inconclusive Analysis unavailable

✅ No new runtime findings were reported.

Analyzer diagnostics
  • run ended before comparative log analysis

Cleanup and diagnostics

Check Result
Cleanup ⏭️ Skipped
Leftover packages none
Cleanup error none
Phase Code Message
Candidate preview mcp_unavailable MCP tool 'dappnode_fetch_install_preview' timed out

Deterministic checks decide the verdict. Runtime log analysis is advisory. TropiBot publishes bounded summaries and never posts raw logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant