Skip to content

Evaluate plugin conditions.remote on the spore before install (#1040) - #1054

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1040
Oct 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1040

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1040

What was wrong

conditions.remote (spore-plugins AUTHORING.md: "Pre-flight checks before install") was read only by Validate. spored's runtime never evaluated it, and neither did spawn plugin install, so a remote type: platform or type: command check was silently skipped.

conditions.local was evaluated (spawn plugin install → CheckLocalConditions), but it had no tests and three smaller gaps, which this PR fixes too: condition commands were never rendered even though Validate scans them for {{ config.* }} references, platform os matching was case-sensitive, and an empty run passed because sh -c "" exits 0.

What changes

  • One evaluator for both sides (pkg/plugin/conditions.go: CheckConditions / CheckCondition). It has a case for every type Validate accepts and fails on any other type instead of skipping it. That matters because spored's launch-time declarations reach Install without going through the push API's Validate. The two sides differ only in how they run commands (ConditionHost):
    • The controller inherits the caller's environment, which the registry's local conditions rely on (test -n "$GITHUB_TOKEN").
    • spored runs the command exactly like a root run step.
  • spored (Runtime.InstallWithProvenance): checks conditions.remote before the install phase, with a 10s budget. A failure marks the plugin failed, and the condition's message leads state.Error. This covers both POST /v1/plugins/install and launch-time declarations.
  • New POST /v1/plugins/preflight: evaluates conditions.remote synchronously and installs nothing. It returns 200 {"status":"ok"} or 412 {"status":"failed","error":"<message>: <detail>"}. A condition that references {{ pushed.* }} can't be evaluated yet at this point, so it is deferred to the install-time check rather than failed.
  • spawn plugin install calls preflight before running local provision steps. A spore that fails a remote condition is reported before the controller mints a Tailscale key or creates a Globus endpoint for an install that can't succeed. An older spored answers 405 (the path matches DELETE /v1/plugins/{name}) or 404. In that case spawn warns and continues, and the install-time check (on a new spored) still catches the failure through waitForPluginReady. The readiness wait moves earlier along with it.

Agreement with #1041 (plugin.CheckSporeOS)

Tests

  • pkg/plugin/conditions_test.go: the pass/fail gate discovers the types from the validator (plugin.ConditionTypes()). It fails when discovery finds nothing, and also when a validated type has no case or a case names an unvalidated type. Also covered: unknown types fail and run nothing, message-less failures name the type, evaluation stops at the first failure, rendering is shell-escaped and an unresolved reference is a failure, an empty command fails, the platform normalisation table, and real-sh local conditions (inherited env, platform, unknown type).
  • pkg/pluginruntime/conditions_test.go: for each discovered type, a passing condition lets the install step run and reach running, and a failing one leaves the plugin failed with the message and no install step run. Also covered: an unknown type fails the install, the registry's os: linux follows the spore OS (linux/windows/darwin), the preflight API returns 200/412 per type and records no state, and pushed references are deferred at preflight but enforced at install.
  • cmd/plugin_preflight_test.go: postPluginPreflight maps 200 → nil, 412 → errRemoteCondition carrying the message, and an older spored's real mux 405 → errPreflightUnsupported.

Each test was watched failing against a revert that compiles (each revert vetted before running). The reverts:

  • if false && on the runtime check
  • unknown type returns nil
  • exact-string MatchesOS
  • the command error ignored
  • the platform check disabled
  • rendering skipped
  • preflight 412 → 200
  • deferPushed disabled
  • CheckLocalConditions → nil
  • the client's 412 → nil
  • 405 not mapped
  • a type added to validConditionTypes with no evaluator case
  • the empty → linux mapping removed

make check: fmt, vet and staticcheck are clean for the touched files. Hermetic tests all pass except the known Docker-daemon-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker (no daemon locally; unrelated). check-nested (9 modules) and check-tidy pass, and GOOS=windows go vet is clean for the touched packages. Semgrep (--config=auto, files staged so they're scanned) reports 0 findings on the changed files.

Caveats

  • No registry plugin currently declares a remote type: command condition (the issue suggested some do). All 12 declare only platform os: linux, and the command conditions in the registry are all local. So in practice the new behaviour for registry plugins is the Linux check, which matters for a Windows spore, and Refuse plugins on Windows spores, up front and with the reason (#1001) #1041 covers that.
  • The ordering change in runPluginInstall (preflight and readiness wait before local provision) isn't unit-tested end to end, because the function needs SSH. The pieces it calls are tested.
  • A platform condition with no os still passes (the field is optional and Validate accepts its absence).
  • Not merged. No AWS resources were used.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

conditions.remote was validated and never evaluated, so a plugin's remote
platform or command pre-flight check was silently ignored.

- pkg/plugin: one condition evaluator (CheckConditions/CheckCondition) shared
  by the controller and spored, with a case for every type Validate accepts
  and a failure for any other. Platform os matching is case/space-insensitive.
  Condition commands are rendered (shell-escaped) like run steps.
- spored: InstallWithProvenance checks conditions.remote before the install
  phase; a failure marks the plugin failed with the condition's message. A new
  POST /v1/plugins/preflight evaluates them without installing anything.
- spawn plugin install: calls preflight before running local provision steps
  and reports a failed condition; an older spored (405/404) gets a warning.
  Local conditions use the shared evaluator, rendered with resolved config.
@scttfrdmn
scttfrdmn merged commit ee929b2 into main Oct 16, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1040 branch October 16, 2026 23:52
@scttfrdmn scttfrdmn mentioned this pull request Oct 17, 2026
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.

plugin: conditions.remote is validated but never evaluated

1 participant