Skip to content

CRITICAL: PrivateTmp=true hides /tmp/SPAWN_COMPLETE from spored — completion-based on-complete/pre-stop never fire #66

Closed

Description

@scttfrdmn

Summary

The spored systemd unit sets PrivateTmp=true. systemd then gives the daemon a private /tmp namespace, so the completion file the rest of the system writes to the real /tmp/SPAWN_COMPLETE is invisible to spored. Its os.Stat("/tmp/SPAWN_COMPLETE") looks inside the private mount, never sees the file, and --on-complete (stop/terminate/hibernate) + --pre-stop based on the completion signal never fire.

This is the second half of why Tier 2 pre-stop / on-complete failed (the first half was #65, the monitor loop never running). Even with #65 fixed and the monitor ticking every minute, completion was never detected.

The completion contract requires a shared /tmp

The default completion file is /tmp/SPAWN_COMPLETE (pkg/provider tag default, spored status shows it). It is written by:

  • end users over SSH (touch /tmp/SPAWN_COMPLETE)
  • spawn connect <name> -- "touch /tmp/SPAWN_COMPLETE"
  • nf-spawn task wrappers writing the completion sentinel
  • any in-instance workload signaling done

All of those write the host /tmp. With PrivateTmp=true, spored cannot see any of them.

Reproduction (real AWS, confirmed 2026-06-06)

t3.small, --on-complete stop --pre-stop "touch /tmp/prestop-ran.txt", monitor fix (#65) applied so the loop ticks every minute:

  1. touch /tmp/SPAWN_COMPLETE over SSH → 11 monitor ticks pass, no "Completion signal detected", instance stays running, no pre-stop file.
  2. sudo systemctl show spored -p PrivateTmp → PrivateTmp=yes.
  3. ls /proc/$(MainPID)/root/tmp/SPAWN_COMPLETE → No such file (daemon's private tmp), while real /tmp/SPAWN_COMPLETE exists.
  4. Touch the file inside the daemon's private tmp (/proc/$PID/root/tmp/SPAWN_COMPLETE) → next tick detects completion → pre-stop runs → instance stops. ✅

That last step is the smoking gun: completion logic works; the daemon was simply looking in the wrong /tmp.

Fix

Remove PrivateTmp=true from the spored systemd unit. spored is a root daemon whose entire purpose is watching a host-side file and managing the instance; an isolated /tmp provides negligible hardening while silently breaking the product's core lifecycle contract.

Three unit definitions carry it:

  • scripts/spored.service:20
  • scripts/install-spored.sh:107
  • cmd/launch.go:2392 (inline heredoc baked into user-data)

(If any /tmp isolation is ever wanted later, it must be paired with a BindPaths=/tmp or a documented non-/tmp completion-file default — but the simplest correct fix is to drop PrivateTmp.)

Severity

CRITICAL. Combined with #65, completion-driven auto-stop/terminate has been completely non-functional for the default path. Instances that rely on --on-complete to shut themselves down run until TTL (or forever, pre-#65) — the exact unbounded-cost failure this product exists to prevent.

Related

Activity

  1. scttfrdmn commented on Jun 6, 2026

    @scttfrdmn
    ContributorAuthor

    Fixed in #67 (together with #65). Confirmed end-to-end on real AWS via the real user path:

    spawn connect spore66-validate -- "touch /tmp/SPAWN_COMPLETE" → with PrivateTmp removed (PrivateTmp=no), the daemon detected the host file at the next tick:

    18:51:55 monitor tick 8
    18:51:55 Completion signal detected: file /tmp/SPAWN_COMPLETE exists
    18:51:55 Grace period: waiting 5s before action
    18:52:00 Stopping instance (reason: Completion signal received)
    18:52:00 Running pre-stop hook (timeout: 5m0s): touch /tmp/prestop-ran.txt
    18:52:00 Pre-stop hook completed successfully
    18:52:07 Stop request sent
    

    Removed PrivateTmp=true from all three unit definitions (scripts/spored.service, scripts/install-spored.sh, cmd/launch.go). TestSporedUnit_NoPrivateTmp guards against reintroduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions