Skip to content

plugin: make registry plugins work end-to-end (verified live) - #347

Merged
scttfrdmn merged 10 commits into
mainfrom
fix/plugin-template-strict-syntax
Jul 14, 2026
Merged

scttfrdmn merged 10 commits into
mainfrom
fix/plugin-template-strict-syntax

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes the spore-sync / tailscale / globus registry plugins actually work, verified end-to-end against a live EC2 instance (launch → install → sync → stop → start → remove → terminate, leak-checked). Multiple fixes below were found by that testing.

Template syntax (Fixed)

One canonical syntax ({{ instance.<key> }} / config / outputs / pushed); anything else (Go-style {{ .Config.x }}, unknown namespace) is a hard error at render and spawn plugin validate, instead of silently rendering <no value>.

Full-lifecycle install (Changed)

spawn plugin install previously ran only local provision and never triggered the remote install/configure/start — so tailscale was inert, globus couldn't complete. Now one command runs both halves: local provision on the controller → new authenticated POST /v1/plugins/install on spored (resolved spec + config + pushed values, async + status poll) → runs the remote half. Pushed values are seeded before configure.

Local cleanup + reconcile (Fixed / Added)

  • Local deprovision steps never ran (even plugin remove only did the remote delete). A controller store (~/.spawn/plugins/) now records config + captured outputs + deprovision/reconcile steps; plugin remove and terminate replay deprovision (tearing down the mutagen session / globus endpoint). stop/hibernate intentionally don't.
  • New local.reconcile block: a stop/start reassigns the public IP, which a pinned mutagen session can't follow. spawn start replays reconcile steps with the new {{ instance.ip }} (waiting for the IP, retrying while SSH comes up). spore-sync uses it; globus omits it.

Found by live testing (all Fixed)

  • Local exec forced a PATH that omitted Homebrew → mutagen: command not found. Now inherits PATH/HOME.
  • Plugin commands passed the --instance ID straight to ssh; now resolve to user@ip (via spawn, never AWS directly), ec2-user default + --user.
  • Deprovision ran with the wrong instance context → orphaned the session silently; now replays with the real instance.*.
  • mutagen has no key flag (uses ambient SSH); install + reconcile load the launch key into ssh-agent.
  • spawn stop now confirms (-y/--yes), matching terminate.
  • cmd/plugin.go no longer imports the AWS SDK directly (tightened [audit] Guardrail: add a test forbidding NEW direct aws-sdk service imports in cmd/ (allowlist) #327 guardrail).

Known follow-ups (filed, not in this PR)

  • ssh-agent auto-load uses $SSH_AUTH_SOCK; a user with IdentityAgent in ~/.ssh/config (e.g. 1Password) routes SSH to a different agent — needs a config-aware approach.
  • Keyless SSM install path (this is SSH-only).
  • Reaper/spot termination can't reach the controller for local cleanup (best-effort gap).

Companion

Registry specs (canonical syntax + spore-sync reconcile) in spore-host/spore-plugins#6.

Testing

The plugin template engine silently rendered any non-canonical reference
(e.g. the Go-style {{ .Config.x }} / {{ .Instance.Name }}) to "<no value>",
so a mistyped or legacy spec would install with empty values and no error —
which had silently broken the tailscale and spore-sync registry plugins.

Enforce one canonical syntax everywhere:
- Render: non-canonical expressions route to __invalidref and return
  ErrInvalidRef instead of expanding to nothing.
- Validate: spawn plugin validate flags the same offline (shared
  templateTexts() walk feeds configReferences() + new invalidTemplateRefs()).
- cmd/plugin: populate instance.ip in the local provision context (was only
  id/name) so local steps like spore-sync's mutagen target can use it;
  folded name+IP into one DescribeInstances call.

Tests cover render + validate rejection of Go-style, unknown-namespace, and
malformed refs, and acceptance of the canonical forms.
@codecov

codecov Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Previously 'spawn plugin install' ran only a plugin's local provision steps on
the controller and never triggered the remote install/configure/start steps on
the instance. Remote-only plugins (tailscale) were inert; plugins split across
both halves (globus: local capture+push -> remote configure) could never
complete. This was the real reason the registry plugins had never worked
end-to-end.

Unify the flow so one command runs both halves:
- spored gains an authenticated POST /v1/plugins/install endpoint that accepts
  the resolved spec (YAML) + config + pushed values, validates the spec, and
  runs the remote half asynchronously (202 + status polling; keeps a slow
  install from tripping the server write timeout). Sending the resolved spec
  rather than a ref makes local-file refs work and avoids version skew.
- Runtime.InstallWithPushed seeds pushed values into initial state before the
  configure phase, so {{ pushed.<key> }} resolves without parking at
  WaitingForPush. Install is now a thin wrapper (nil pushed).
- BufferingPushClient records local-provision pushes in memory so the CLI can
  hand them to spored in the install request.
- CLI: local conditions -> local provision (buffering pushes) -> POST install
  over the SSH tunnel -> poll status until running/failed.

Known limitation (documented in code): the async launch-time path still parks
at WaitingForPush if a configure step needs a value only delivered later via
ReceivePush; the persisted state doesn't retain the spec to replay configure.
Unused by current registry plugins.

Tests: InstallWithPushed seeds-before-configure, missing-pushed-parks-waiting,
install endpoint end-to-end (202 -> running, pushed value reaches configure),
endpoint rejects an invalid spec, and the buffering push client.
@scttfrdmn scttfrdmn changed the title plugin: reject non-canonical template references loudly plugin: strict template syntax + full-lifecycle install Jul 12, 2026
A plugin's local deprovision steps were never executed — not even by
'spawn plugin remove', which only called spored's DELETE (remote state).
RunDeprovision had zero callers. So spore-sync left a mutagen sync session and
globus left a registered endpoint on the controller with no way to clean up.

Deprovision often needs a provision-time value (globus:
{{ outputs.endpoint_id }}) that lived only in controller memory during install,
so wiring alone isn't enough — the controller must persist it.

- Add pkg/plugin.LocalStore: controller-side records under
  ~/.spawn/plugins/<instance>/<plugin>.json holding config, captured outputs,
  and the deprovision steps. Path components validated against traversal.
- spawn plugin install writes a record after local provision (when the plugin
  has deprovision steps), best-effort.
- spawn plugin remove replays local deprovision (rebuilding ctx from the record:
  instance.* + config + outputs) before the remote DELETE, then drops the record.
- spawn terminate (single + job-array) replays local deprovision for every
  recorded plugin on the instance before terminating, keyed on both instance ID
  and Name (either may have been used at install).
- spawn stop/hibernate deliberately do NOT deprovision (resumable — the local
  footprint should survive a stop/start cycle); documented inline.

Known gap (documented): reaper/spot-initiated termination can't reach the
controller, so it can't run local deprovision — mirrors the #247 DNS orphan
class. Tests cover LocalStore save/load/list/delete, missing-instance, unsafe
identifiers, and delete-missing.
@scttfrdmn scttfrdmn changed the title plugin: strict template syntax + full-lifecycle install plugin: make registry plugins work end-to-end (strict syntax + full-lifecycle install + local cleanup) Jul 12, 2026
Ran the full spore-sync flow against a real EC2 instance (install -> bidirectional
sync -> remove -> terminate). It worked end-to-end, but surfaced three real bugs
the unit tests couldn't:

1. Local provision PATH: the local executor forced a fixed PATH that omitted
   /opt/homebrew/bin (Apple Silicon Homebrew), so 'mutagen: command not found'.
   Now inherit the caller's PATH + HOME (not credentials) while still dropping
   other env vars.

2. --instance as SSH host: plugin commands passed the --instance value straight
   to ssh, so an EC2 instance ID (which every other spawn command accepts) never
   connected — only a hostname/IP worked. Now resolve an instance ID to its
   public IP, connect as ec2-user by default, add --user to override. Applied to
   install/list/status/remove.

3. Deprovision ran with the wrong instance context: the controller record keyed
   on the instance ID but discarded the resolved Name, so 'mutagen sync terminate
   spore-{{ instance.name }}' targeted the wrong session and silently orphaned it
   (masked by the spec's '|| true'). Now persist the real instance.* map
   (id/name/ip) in the record and replay deprovision with it. VERIFIED live: both
   'plugin remove' and 'terminate' now actually kill the mutagen session (1 -> 0).

Also: fix the doubled 'v' in the install banner (spec.Version already has 'v').

Corrected a wrong code comment on the stop path: a stop/start reassigns the
public IP, which a pinned mutagen session can't follow — recovery needs 'spawn
start' to reconcile the session (follow-up), not just leaving it parked.

Verified: go build/vet/gofmt clean; pkg/plugin + cmd tests green (excl.
pre-existing TestCatalogValid #392); LocalStore test now asserts the instance
map round-trips. Live test instances terminated, leak-checked (0 sessions, 0
records, 0 instances).
More fixes/features surfaced and verified by the live spore-sync test — a
stop/start reassigns the instance's public IP, which a pinned mutagen session
can't follow, so the sync silently dies after a restart.

- local.reconcile block: plugins can declare controller-side steps to re-point
  an IP-bound footprint. spawn start replays them with the new {{ instance.ip }}
  (retrying with backoff while SSH comes up) for any recorded plugin on the
  instance. spore-sync uses it to terminate+recreate its mutagen session;
  address-independent plugins (globus) omit it. Validated + template-scanned like
  the other step blocks.
- spawn start now waits for the new public IP (not just state=running, which
  reports before the IP is attached) before reconciling.
- ssh-agent: mutagen has no key flag and uses ambient SSH, so install + reconcile
  now load the instance's launch key into ssh-agent (resolved from --key or the
  key pair via the same lookup spawn connect uses). This was the real reason a
  clean-shell reconcile failed with Permission denied.
- plugin instance lookup now goes through spawn (aws.NewClient + resolveInstance)
  instead of raw ec2.DescribeInstances — the plugin layer never talks to AWS
  directly. Drops the last AWS-SDK import from cmd/plugin.go (tightened the #327
  guardrail allowlist).
- spawn stop now confirms before stopping (-y/--yes to skip), matching terminate.

VERIFIED LIVE end-to-end (t4g.small, us-east-1, terminated + leak-checked):
install -> sync -> stop (empty agent) -> start -> reconcile re-points the session
to the NEW IP, auto-loads the key, reconnects, live sync resumes. The one
f.txt 'conflict' observed is correct two-way-safe behavior (edited on both sides
while disconnected), not a regression — new/non-conflicting files sync fine.

Tests: LocalStore reconcile round-trip + IP update; build/vet/gofmt clean;
pkg/plugin + pkg/pluginruntime + cmd green (excl. pre-existing #392).
@scttfrdmn scttfrdmn changed the title plugin: make registry plugins work end-to-end (strict syntax + full-lifecycle install + local cleanup) plugin: make registry plugins work end-to-end (verified live) Jul 12, 2026
The previous ssh-agent approach ran bare `ssh-add`, which targets $SSH_AUTH_SOCK
— but a user with `IdentityAgent` in ~/.ssh/config (e.g. 1Password, whose agent
is read-only) routes ssh auth to a DIFFERENT agent that ssh-add can't touch and
that mutagen's ssh WILL use. So the key landed in the wrong agent and SSH-based
local steps still failed. (Confirmed on this machine: agent empty, 1Password
IdentityAgent configured.)

Replace it with a spawn-managed ssh_config include:
- pkg/sshkey/config.go: EnsureHostIdentity(home, ip, keyPath) writes a marked
  `Host <ip> / IdentityFile <key> / IdentitiesOnly yes` block into
  ~/.spawn/ssh_config and adds a single `Include` to ~/.ssh/config (prepended so
  it wins over catch-all Host stanzas). Idempotent upsert; RemoveHostIdentity
  deletes a block. An IdentityFile is honored by every ssh regardless of the
  configured agent, and IdentitiesOnly stops other keys being offered first.
- install sets the block for the instance IP; reconcile re-points it to the new
  IP on start (and removes the stale old-IP block); remove/terminate delete it.

VERIFIED LIVE on this machine (1Password IdentityAgent, ssh-agent EMPTY
throughout): install -> mutagen connects via the IdentityFile -> stop -> start ->
block re-pointed to the new IP, session reconnects, live sync resumes ->
terminate removes the block. The agent was never used.

Tests: pkg/sshkey/config_test covers write+Include, idempotent upsert,
multi-host + remove, missing-file no-op, and that an existing ~/.ssh/config is
preserved with the Include prepended. build/vet/gofmt clean; suites green (excl.
pre-existing #392).
Local plugin steps run with a minimal environment (PATH+HOME only) so scripts
can't scoop up the caller's AWS/other credentials. But that also blocks the
legitimate case: a plugin that needs a controller-side secret to mint a remote
credential — e.g. Tailscale's Model A, where the controller exchanges an OAuth
client secret for a short-lived auth key. (It was also inconsistent: local
conditions saw the full env, local provision saw the stripped env.)

Add local.env_passthrough: []string — the plugin names exactly which controller
vars its local steps may read, and spawn injects only those (resolved from its
own environment) on top of PATH/HOME. Off by default; unset names are skipped.
Threaded through provision (from the spec) and deprovision/reconcile (persisted
in the LocalRecord). Validated as POSIX env-var names.

Tests prove: only the opted-in var reaches the step, a listed AWS secret does
NOT leak, an unset passthrough var is skipped, and default (no passthrough) still
strips the parent env. build/vet/gofmt clean; suites green (excl. #392).
… plugins

A plugin with local.provision but no deprovision/reconcile record (e.g.
tailscale, whose local step only mints an auth key) still triggers
ensureHostIdentity, which writes a spawn-managed ssh_config Host block for the
instance IP. But cleanup only ran via runLocalDeprovision (gated on a stored
record), so tailscale left a stale Host entry pointing at a dead IP after
terminate.

spawn terminate (single + job-array) now removes the identity block for the
instance's public IP unconditionally (removeHostIdentityForIP), independent of
whether any plugin left a deprovision record. Found during the live tailscale
end-to-end test (which otherwise passed: node joined the tailnet, tagged +
ephemeral, auto-removed on terminate).
The real Globus blocker, finally found: spored runs plugin remote steps as root,
and Globus Connect Personal refuses to run as root ("Running Globus Connect
Personal as root is not supported") — it also stores config under the user's
~/.globusonline. All the earlier relaytool/TTY/stdin/early-boot theories were red
herrings; the plain error was there once a real attempt ran as root.

Add a per-step opt-in so a remote step runs as the instance's local login user:
- pkg/plugin: Step.AsUser (`as_user: true`).
- pkg/pluginruntime: RemoteExecutor carries the local user (from
  spawn:local-username, threaded via NewRuntime); an as_user run step executes
  `su - <user> -c <script>` (login shell → correct HOME/PATH/env, matching the
  #63 pre-stop run-as-user pattern) instead of `sh -c`. Username validated;
  unknown user → run as root with a warning (older instances).
- agent wires config.LocalUsername into the runtime.

Tests: as_user with no local user falls back to root, plain steps unaffected,
invalid username rejected. build/vet/gofmt clean; pkg/plugin + pkg/pluginruntime
green.

VERIFIED LIVE end-to-end (companion spore-plugins change marks the GCP steps
as_user): `spawn plugin install globus-personal-endpoint` reaches running, the
endpoint shows GCP Connected: True, and real files transfer BOTH directions
between this controller and the instance endpoint; `spawn plugin remove` deletes
the endpoint (404). Instance terminated + leak-checked.
The stop-confirmation change (spawn stop now prompts, -y to skip) broke
TestTier0_StateTransitions: it ran 'spawn stop <id>' non-interactively, which now
aborts (instance stays running) instead of stopping. Pass -y and fix the stale
comment that said stop takes no -y.
@scttfrdmn
scttfrdmn merged commit eff8b77 into main Jul 14, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/plugin-template-strict-syntax branch July 14, 2026 04:11
scttfrdmn added a commit that referenced this pull request Jul 14, 2026
Roll up the plugin + launch-hardening work merged since v0.72.0 (#347, #348):
plugin lifecycle (as_user, env_passthrough, ssh_config identity, reconcile,
full-lifecycle install, orphan cleanup, strict template syntax) and launch
robustness (deterministic readiness gate, username normalization + log-in-as-you,
progress UX, connect hint, DNS curl -4/retry, silent-key-substitution fix).
MINOR: backward-compatible features + fixes, no breaking changes.
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