Executions/script-page rework + self-signed TLS fingerprint pin & graceful root renewal #14

Merged
gsadmin merged 6 commits from dev into main 2026-08-11 09:47:17 +00:00

6 Commits

Author SHA256 Message Date
gsadmin 938f4e2ccb Graceful root renewal (same key) + authenticated CA refresh [skip ci]
So a root that reaches its renewal margin no longer breaks enrolled agents.

Server: the root is now renewed IN PLACE with the same key — only the
certificate validity is extended (RenewRoot). Same subject + key means the same
Subject Key Identifier, so the existing intermediate/leaf keep chaining to it;
agents that already trust the root keep validating across the handoff. A true
key rotation stays a deliberate re-enrollment event. (File persistence now loads
keys Exportable, matching the Windows-store backend, so the in-place renewal can
re-use the key.)

Agent: the periodic CA refresh (CaRefreshService) now runs over a NORMALLY-
VALIDATED connection (ServerTrust.RefreshCaAsync) and installs whatever the
trusted server serves — so a renewed root (or new intermediate) is picked up
before the old cert expires, no operator action. The fingerprint pin is enforced
only at first-contact enrollment (unauthenticated); ongoing refresh is
authenticated by the transport, so the persisted-pin machinery is gone. A full
key rotation simply can't validate and is left for a fresh token.

New test drives an in-place renewal and asserts the root cert changes, the key
does not, the intermediate/leaf are untouched, and a leaf still validates against
the ORIGINAL root. Backend 104, Shared 89, Agent 60 tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 05:41:44 -04:00
gsadmin 0d3a3e9da4 Pin the self-signed CA to a fingerprint carried in the bootstrap token [skip ci]
Closes the trust-on-first-use MITM window on self-signed enrollment, without any
extra plumbing.

Server: when the managed self-signed chain is active, the minted bootstrap token
becomes "secret.<sha256-of-root-CA>". The hash covers the whole string, so
enrollment validation is unchanged, and the fingerprint travels wherever the
token already goes (install command, MSI property, registry) — no separate
value, endpoint, or CLI flag.

Agent: enrollment is now connection-first. It attempts a normally-validated
connection; only if the server certificate does not validate (self-signed, first
contact) does it anchor trust — fetch the CA over the accept-any probe and pin it
to the fingerprint parsed from the token. Match -> install + retry (validating
against the just-verified chain, so it works in-process regardless of OS
trust-store timing). Mismatch / no fingerprint / 404 -> refuse to enroll. A real
or edge certificate simply validates and installs nothing (this also removes the
old unconditional double-install). The pin is persisted to runtime state so the
periodic CA refresh keeps THIS CA and refuses a later swap after the one-time
token is cleared; re-anchoring a rotated CA requires a fresh token.

Backend + agent build; Backend 103, Shared 89, Agent 60 tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 05:01:11 -04:00
gsadmin b07a077fbb Script page: groups-only Run + Executions drill-in, output off page [skip ci]
Reworks the script page around the executions model (option A):
- Run box: multi-select group checkboxes only (no per-device list); Run fans
  out across the deduped union of the selected groups as ONE execution
  (new multi-group run: CreateJobRequest.GroupIds -> RunOnGroupsAsync).
- The inline Targets/Run/Output/History sections are gone. In their place a
  single Executions drill-in: Executions -> a run's Targets (devices) -> a
  Target's Output, with a breadcrumb to step back.
- Output view is full-width and searchable, rendered line-by-line and kept
  intact (white-space: pre) so wide output like ifconfig scrolls horizontally
  instead of wrapping into a block. Fetched from stored job output and polled
  while the run is still active (replacing the live NATS stream on this page).

Backend builds; 103 tests pass; svelte-check clean (0/0).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 17:10:07 -04:00
gsadmin 42645b293d Executions backend: group a runs per-device jobs under a RunId [skip ci]
Foundation for the Script > Executions > Targets > Target > Output drill-in.
Every run (ad-hoc, group, or a trigger firing) stamps its jobs with a shared
RunId; legacy jobs (null RunId) are treated as single-target runs keyed by
their own JobId. New read endpoints:
- GET /api/scripts/{scriptId}/executions  — runs of a script, summarized
  (started, requester, total + per-state counts), newest first.
- GET /api/executions/{runId}             — the run and its target devices.
Output is fetched per target via the existing job-output endpoint.

Migration AddJobRunId (Sqlite/Postgres/SqlServer) adds the nullable column +
(ScriptId, RunId) index. Backend builds; 103 tests pass; svelte-check clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 16:59:32 -04:00
gsadmin c5c0432ad3 Fix Linux/macOS remote shell: raw PTY I/O so input reaches the shell [skip ci]
The forkpty session drove both directions through one FileStream over the PTY
master. On Unix, FileStream serializes its async read and write behind a single
semaphore, so the always-pending output ReadAsync held it and every input
WriteAsync blocked forever — the shell opened but keystrokes never arrived
(`Shell session ... opened (/bin/bash)`, then dead). Windows was fine because
ConPTY uses separate input/output pipes.

Drive the master fd with raw read(2)/write(2)/close(2) instead: the read loop
runs on a dedicated thread, writes take a short lock for ordering/partial
writes, and the two directions no longer contend. Agent builds on both TFMs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 16:47:55 -04:00
gsadmin c313cde7e7 Triggers: groups-only targets, time-zone dropdown, enable/disable [skip ci]
- Trigger target selector now offers All devices + groups only (no per-device
  list, which is unusable in large fleets).
- The cadence editor time zone is a dropdown (full IANA list via
  Intl.supportedValuesOf, shortlist fallback) instead of free text.
- Triggers can be disabled without deleting: new PATCH /api/triggers/{id} flips
  Enabled (re-enabling a recurring schedule advances NextRunUtc past due so it
  does not fire a backlog); the card shows an Enable/Disable button and dims
  disabled rows. The worker and lifecycle service already skip disabled
  triggers, so this actually gates firing.

Backend builds; 103 backend tests pass; svelte-check clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 16:36:20 -04:00