Repository navigation
feat(relay): authenticate registered alternate poll shims - #3462
derickdsouza wants to merge 2 commits into
Conversation
An explicit binding of the current x-watch shim bytes plus exec-target identity lets a harbor-style wrapper stay armed across bootstrap, while homes without a registration keep the stock byte-static path.
Confidence Score: 4/5The inconsistent shim-to-target binding should be fixed before merging; the path-boundary and execution-race concerns are additional non-blocking hardening work. Registration authenticates the shim and supplied target independently, allowing watcher dispatch to execute a program that the alternate shim does not identify. Files Needing Attention: bin/fm-x-watch-register.sh, bin/fm-x-lib.sh, bin/fm-watch.sh
|
| if fmx_poll_shim_stock_valid "$CHECK" "$FM_HOME" "$FM_ROOT"; then | ||
| echo "error: shim matches the stock Relay poll identity; an alternate shim is required" >&2 | ||
| exit 1 | ||
| fi | ||
| fm_pr_regular_destination_on_device_or_absent "$TRUST" "$STATE_DEVICE" \ | ||
| || { echo "error: poll trust path is unavailable" >&2; exit 1; } | ||
|
|
||
| SHIM_HASH=$(fmx_sha256 "$CHECK") || { echo "error: poll shim hash is unavailable" >&2; exit 1; } | ||
| TARGET_HASH=$(fmx_sha256 "$TARGET") || { echo "error: exec target hash is unavailable" >&2; exit 1; } | ||
|
|
||
| umask 077 | ||
| TMP=$(mktemp "$STATE/.fm-x-watch-poll-trust.XXXXXX") || exit 1 | ||
| trap '[ -z "$TMP" ] || rm -f -- "$TMP"' EXIT HUP INT TERM | ||
| printf '%s\n%s\n%s\n%s\n' fm-x-watch-poll-v1 "$SHIM_HASH" "$TARGET" "$TARGET_HASH" > "$TMP" || exit 1 |
There was a problem hiding this comment.
| case "$TARGET" in | ||
| "$STATE"|"$STATE"/*) | ||
| echo "error: exec target must not live under state/" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac |
There was a problem hiding this comment.
State exclusion uses lexical paths
A target containing parent traversal or a symlinked parent can resolve beneath state/ while passing this prefix check, allowing mutable runtime state to be registered as executable code. How this was verified: The target validator accepts absolute paths containing .., and neither registration nor validation resolves parent directories before enforcing the boundary.
| [ -f "$FMX_POLL_TRUST_TARGET" ] && [ ! -L "$FMX_POLL_TRUST_TARGET" ] || return 1 | ||
| hash=$(fmx_sha256 "$FMX_POLL_TRUST_TARGET") || return 1 | ||
| [ "$hash" = "$FMX_POLL_TRUST_TARGET_HASH" ] |
There was a problem hiding this comment.
Validated target path remains mutable
If a deployment or other same-user process replaces the wrapper after hashing but before dispatch, the watcher reopens the mutable pathname and executes bytes outside the trust binding. How this was verified: Validation returns only the pathname, and the watcher later passes that path to run_check_capture without snapshotting or revalidation.
Intent
Build a deliberate trust-binding mechanism so firstmate authenticates a REGISTERED alternate relay-poll shim - the harbor telegram-hitl wrapper - as a first-class X-mode poll path, per the captain's ruling of 2026-09-01 (adopt).
state/x-watch.check.sh is generated by fm-bootstrap.sh (x_mode_setup) from fm-x-lib.sh's fmx_poll_shim_content, and the watcher validates it byte-statically, rejecting any other bytes as an unauthenticated state check. Harbor's telegram-hitl extension rewrites the shim to exec its wrapper bin/fm-x-poll-harbor.sh, which itself wraps stock bin/fm-x-poll.sh; firstmate correctly refuses, and harbor's deploy re-arms it periodically. The captain adopted the integration: firstmate grows the authentication path.
Requirements:
Constraints:
Prior run 01M1F4W5VBPZXV5PMAD4TNAQ4T completed through push to the fork then was aborted at PR. Fork PR derickdsouza#1 already exists for this head; attach the no-mistakes signature to that fork-internal PR rather than opening another PR.
What Changed
bin/fm-x-watch-register.sh, the sole writer of astate/x-watch.poll-trustbinding record (mode 0600, never auto-created) that pins the current shim bytes plus the absolute path and sha256 of its exec target.fm-bootstrap.sh'sx_mode_setupnow resolve the poll exec target through the newfmx_poll_exec_target/fmx_poll_shim_registered_validhelpers: a still-matching registration is preserved across bootstrap regeneration and dispatched by the watcher, while stale or tampered bindings are rejected exactly like unregistered rewrites, with the rejection message naming the re-register command as the remedy.fmx_poll_shim_validwith the splitfmx_poll_shim_stock_valid, and document the registration path in thedocs/configuration.mdRelay section,docs/scripts.md, andAGENTS.md, with colocated tests intests/fm-x-watch-register.test.shcovering stock, registered, unregistered, and tampered-target variants.Testing
Pipeline
Updates from git push no-mistakes
⏭️ **intent** - skipped
Step was skipped.
⏭️ **Rebase** - skipped
Step was skipped.
⏭️ **Review** - skipped
Step was skipped.
⏭️ **Test** - skipped
Step was skipped.
⏭️ **Document** - skipped
Step was skipped.
⏭️ **Lint** - skipped
Step was skipped.
⏭️ **Push** - skipped
Step was skipped.