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
Owner

Rolls up the executions/script-page rework and the self-signed TLS trust work.

Script page & executions

  • Linux/macOS remote shell fixed (raw PTY I/O so input reaches the shell).
  • Triggers: groups-only targets, time-zone dropdown, enable/disable.
  • Jobs grouped under a RunId; new executions endpoints.
  • Script page reworked around option A: groups-only multi-select Run box, inline
    output removed, and an Executions -> Targets -> Target -> Output drill-in with a
    full-width, searchable log.

Self-signed TLS trust

  • The bootstrap token carries the CA fingerprint (secret.);
    enrollment is connection-first and pins the fetched CA to it, closing the
    first-contact MITM window. A real/edge cert validates and installs nothing.
  • Root renews in place with the same key, and the periodic CA refresh runs over
    the authenticated connection — so root renewal is seamless for enrolled agents;
    only a true key rotation re-tokens.

Backend 104, Shared 89, Agent 60 tests pass; svelte-check clean.

Rolls up the executions/script-page rework and the self-signed TLS trust work. **Script page & executions** - Linux/macOS remote shell fixed (raw PTY I/O so input reaches the shell). - Triggers: groups-only targets, time-zone dropdown, enable/disable. - Jobs grouped under a RunId; new executions endpoints. - Script page reworked around option A: groups-only multi-select Run box, inline output removed, and an Executions -> Targets -> Target -> Output drill-in with a full-width, searchable log. **Self-signed TLS trust** - The bootstrap token carries the CA fingerprint (secret.<sha256-of-root>); enrollment is connection-first and pins the fetched CA to it, closing the first-contact MITM window. A real/edge cert validates and installs nothing. - Root renews in place with the same key, and the periodic CA refresh runs over the authenticated connection — so root renewal is seamless for enrolled agents; only a true key rotation re-tokens. Backend 104, Shared 89, Agent 60 tests pass; svelte-check clean.
gsadmin added 6 commits 2026-08-11 09:47:14 +00:00
- 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>
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>
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>
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>
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>
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>
gsadmin merged commit ee4f02c9c4 into main 2026-08-11 09:47:17 +00:00
Sign in to join this conversation.