Skip to content

Auth key stays listed as active after expiring it when the browser clock is behind #703

Backlog

Description

@decky-grande

Description

After expiring an auth key on Settings → Auth keys, the key often stays in the list as active, still showing its Expire button, even though Headscale has expired it. Reloading a little later shows it as expired.

Headscale sets an expired key's expiration to its own current time. The page then decides whether a key is past its expiry by comparing that timestamp with the browser's clock (new Date(key.expiration) < new Date() in overview.tsx and auth-key-row.tsx). If the browser's clock is even slightly behind the Headscale server's, the just-expired key still counts as active, and nothing re-renders it once that moment passes.

To reproduce, with the browser's clock about 2 seconds behind the server:

  1. Open Settings → Auth keys and clear the status filter.
  2. Expire an active key.
  3. The row shows Expires: now and keeps its Expire button.

Seen on Headplane 0.8.2 against Headscale 0.29.8, and reproduced on main (4d97ffd) against Headscale 0.29.5 using the test harness, with the browser's clock set 2 seconds behind.

A fix would decide expiry on the server, in the loader, where the clock matches the one Headscale used when Headplane and Headscale share a host or keep their clocks in sync.

Headplane Version

0.8.2 (also on main at 4d97ffd)

Headscale Version

0.29.8

Activity

  1. pullfrog commented on Dec 2, 2026

    @pullfrog

    Assessment

    Actionable. The root cause is as described: the auth keys page decides expiry with the browser's clock in two places.

    • app/routes/settings/auth-keys/overview.tsx (the status filter) compares new Date(key.expiration) < new Date().
    • app/routes/settings/auth-keys/auth-key-row.tsx compares expiration < new Date() for the Expired label and to hide the Expire button.

    Headscale stamps an expired key's expiration with its own time.Now(), so a browser clock even slightly behind still sees the key as unexpired. The row never updates because the browser clock never crosses that timestamp. Reloading only helps once the browser clock catches up.

    Status: already fixed by #704

    #704 ("fix(ui): decide auth key expiry on the server") is open against main at 4d97ffd and implements exactly the approach this issue describes. It is mergeable; at the time of writing the build, unit, and version-independent integration jobs pass, and the 0.27.1/0.28.0/0.29.5 integration jobs plus the Nix check are still running. No separate implementation is needed unless review asks for changes.

    What #704 changes

    • overview.tsx loader: takes now = Date.now() on the server and annotates every key with expired: new Date(key.expiration).getTime() <= now.
    • overview.tsx component: the status filter reads key.expired instead of the browser clock, so the default Active view also drops a just-expired key.
    • auth-key-row.tsx: reads authKey.expired for the label and the Expire button instead of calling new Date().
    • tests/integration/headplane/auth-keys.test.ts: expires a key, then asserts the loader lists it as expired. It fails before the change.
    • CHANGELOG.md: one user-facing line under # Next → ## Fixes.

    Milestones

    1. Review fix(ui): decide auth key expiry on the server #704 for correctness and the type change (PreAuthKey & { expired: boolean }), including the userOptions type guard in overview.tsx.
    2. Wait for the integration matrix to pass on 0.27.1, 0.28.0, and 0.29.5. The loader path differs by version (listAll on 0.28+, per-user fetches on 0.27), so all three matter.
    3. Confirm the changelog line sits under ## Fixes and reads as prose for operators.
    4. Decide whether to handle no-expiry keys in the same change or as a follow-up (see below).

    Edge cases and follow-ups

    • No-expiry keys: Headscale returns 0001-01-01T00:00:00Z for a key created without an expiration (the contract test a key without an expiration gets the zero time covers this). fix(ui): decide auth key expiry on the server #704's comparison marks those keys expired, which is the page's current behavior, not a regression. A proper fix would use isNoExpiry() from app/utils/node-info.ts and render Never in the Expires cell. That is a separate bug worth its own issue unless the reviewer wants it here.
    • Natural expiry while the page is open: the loader flag is a snapshot. A key that expires after the page loads stays active until a revalidation; the live store will not fire because the expiration field does not change. This limitation predates the fix and can be a follow-up if it matters.
    • Headplane ↔ Headscale clock skew: the fix assumes the Headplane server clock is at or ahead of Headscale's, as the issue notes. If Headplane's clock is behind, the same symptom can occur server-side. The <= comparison helps at the exact boundary but not with real skew, and Headscale exposes no server-time source to correct against.
    • Test coverage: the integration test locks in the server decision. A component test for the row would need a data router and Base UI; the PR's manual harness check with a browser clock 2 seconds behind covers that wiring, which is consistent with this repo's testing bar.

    Verification

    • pnpm test:unit
    • pnpm vitest run --project integration:app tests/integration/headplane/auth-keys.test.ts (needs Docker)
    • pnpm run typecheck
    • pnpm run lint
    • pnpm run format or pnpm exec oxfmt --check <changed paths>
    • Manual: pnpm harness up <scenario> --headplane with the browser clock set behind the server, then expire a key and confirm the row reads Expired just now with no Expire button.
    Task list (4/4 completed)

    Pullfrog  | Implement plan ➔ | View workflow run | via Pullfrog | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

  2. linear-code commented on Dec 2, 2026

    @linear-code
  3. moved this from Todo to In Progress in Headplaneon Dec 2, 2026
  4. added
    Authentication
    Bug
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthenticationBug

    Type

    No type

    Projects

    • Status
      In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions