Skip to content

fix(nixos): cloudflared --token-file for pm/lab tunnels + lab /ready watchdog (#8933) - #8935

Merged
dezren39 merged 1 commit into
mainfrom
queue/15129-8933-token-file-watchdog
Nov 12, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/15129-8933-token-file-watchdog

Conversation

@dezren39

@dezren39 dezren39 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

What

Fixes #8933: neither NixOS Cloudflare Tunnel unit passes its tunnel token through the cloudflared command line anymore, and lab-tunnel gains the readiness recovery pm-tunnel already had.

  • pm-tunnel (nixos/services/pm-stack/default.nix): ExecStart now runs cloudflared … run --token-file /home/user/pm-stack/tunnel.token; the EnvironmentFile + ${TUNNEL_TOKEN} argv expansion is gone. Watchdog, wait-for-dns and --protocol http2 are untouched.
  • lab-tunnel (nixos/services/lab-tunnel/default.nix): same --token-file switch (~/lab-tunnel/tunnel.token), plus a loopback metrics//ready endpoint on port 20243 (pm-tunnel uses 20242) and a lab-tunnel-watchdog service + 2-minute timer mirroring pm-tunnel's pm-dispatch: POST /v1/sessions and /v1/tasks answer HTTP 502 — daily upstream sync dead since 2026-11-04 #6992 pattern (3 consecutive /ready failures restart the unit; any success resets the counter).
  • Watchdog script (nixos/services/lab-tunnel/lab-tunnel-watchdog.sh): the pm watchdog logic verbatim in shape, kept as a standalone file whose @curl@/@systemctl@/@readyUrl@ placeholders the module substitutes via lib.replaceStrings, so the exact shipped script is unit-testable with stubs.
  • pm-stack/deploy.sh: render now also writes the raw token to tunnel.token (mode 600) from the same SOPS secret (cloudflare_tunnel_token). The legacy tunnel.env rendering is kept for rollback to the pre-nixos: keep Cloudflare tunnel credentials out of argv and recover degraded lab tunnels #8933 unit; nothing consumes it now.

Token-file mechanism: cloudflared tunnel run supports --token-file (env form TUNNEL_TOKEN_FILE) in its credential resolution order — confirmed at triage (task 15128). No new secret store; secret-source ownership unchanged, and no credential value appears in this PR.

Tests

  • nixos/services/lab-tunnel/lab-tunnel-watchdog.test.sh — stubbed curl/systemctl against the shipped script: healthy (counter 0, no restart), degraded (restart exactly once at 3 consecutive failures, counter resets), probe-error counts as a failure, success after failures resets. 13/13 pass.
  • nixos/services/lab-tunnel/tunnel-units.test.sh — rendered-shape oracle from nixos: keep Cloudflare tunnel credentials out of argv and recover degraded lab tunnels #8933's acceptance: no TUNNEL_TOKEN / --token <value> in either module, --token-file wired in both, lab metrics port + watchdog + timer present, pm watchdog preserved, deploy.sh renders tunnel.token at mode 600. 15/15 pass.
  • nix eval of the amd host config renders both ExecStart lines with --token-file and no token expansion (verified in-session; the rendered strings are recorded on issue nixos: keep Cloudflare tunnel credentials out of argv and recover degraded lab tunnels #8933).
  • nixfmt applied to both modules; bash -n clean on deploy.sh and the watchdog script.

Deploy sequencing (binding)

The host token files must exist before the merged change is switched in, or both live tunnels fail to start. The merging lane renders ~/pm-stack/tunnel.token (from the pm-stack SOPS file) and ~/lab-tunnel/tunnel.token (from BWS cloudflare.tunnel.lab-cluster-token) at mode 600 first, then switches, then verifies both tunnels' /ready endpoints and the lab watchdog timer. Results are recorded on issue #8933.

Queue: task 15129 (follow-on of triage task 15128).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 12, 2026 15:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T15:21:51.067853Z 5f6a72a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

nixos: keep Cloudflare tunnel credentials out of argv and recover degraded lab tunnels

1 participant