Skip to content

Reaper: stop executing tag-sourced strings as root, and deny the control tag keys to the instance role #830

Closed

Description

@scttfrdmn

Security issue. Detail is in private advisory GHSA-8q3p-qcv8-2pr4 rather than here;
this issue tracks the remediation only.

The reaper's graceful pre-stop tier runs an instance tag's contents through SSM
AWS-RunShellScript, which executes as root, and the spored instance role can write
that tag on any spawn:managed instance in the account. Found while verifying the
su -c username splice from the audit, which turns out to be the smaller half of it.

Three parts, in dependency order:

  • lambda/ttl-reaper/main.go:1036 — validate c.localUsername with
    security.ValidateUsername before interpolating it, and build the command in argv
    form instead of a su -c string. The module does not import pkg/security at
    all today; its go.mod already requires github.com/spore-host/spawn, so this
    costs nothing. pkg/launcher/bootstrap.go:172 and pkg/agent/sys_linux.go:244
    are the two correct siblings to match.
  • lambda/ttl-reaper/main.go:1021-1038 — decide what the hook runs as when
    spawn:local-username is absent. Today it runs as root, which contradicts
    --pre-stop runs as root, should run as the instance user #63 ("run the hook as this user"). Skipping the hook is the fail-closed choice;
    the reaper terminates regardless, so the hard-deadline guarantee (Guardrail: TTL must always terminate — never add a TTL→stop mode #72) is
    unaffected either way.
  • pkg/aws/iam.go:921-933 and the DCV copy at :1296-1305 — deny the reaper's
    control tag keys to the instance role (spawn:ttl-deadline,
    spawn:last-heartbeat, spawn:pre-stop, spawn:local-username) with
    ForAllValues:StringNotEquals on aws:TagKeys. The existing comment reasons
    that the spawn:managed condition means a spore "cannot pull a foreign instance
    into scope" — true, but re-tagging an instance already in scope is the attack.
    Same surface as the deadline-tampering half of Implement spore.host authenticity key: signed spore tag that all spore tools verify before touching an instance #76.

Gates to go with it: the username path needs a test that drives a hostile tag value
(rule 2 — construct the state, don't reach it through the happy path), and the tag-key
denial needs simulate-principal-policy showing the control keys denied and an
ordinary spawn:-prefixed tag still allowed, since aws:TagKeys with
ForAllValues is easy to write in a way that denies every tag write including
spored's own.

Not a latent-only finding: the cross-account reaper role in 435415984226 holds a
working SendCommand, so the path is live there. The production role in 966362334030
has no SendCommand grant at all, which blocks it there by accident rather than by
design — see #818.

Activity

  1. scttfrdmn commented on Oct 11, 2026

    @scttfrdmn
    ContributorAuthor

    Two corrections and one addition from verifying the live state, before any code lands.

    1. Not exploitable in production today, contrary to what I wrote on this issue.
    I said "the cross-account reaper role in 435415984226 holds a working SendCommand, so
    the path is live there." The grant is there; the code path is not reached. spawn-ttl-reaper-production
    sets no REAPER_GRACEFUL, and tryGracefulPreStop is called only under if r.graceful
    (main.go:614), so the whole graceful tier is dead code in the deployed function. It
    arms the moment #187 is enabled as documented — a one-env-var change — so this is latent,
    not closed. Checking a grant without checking the invocation is the same mistake I made on
    #818 in the other direction.

    2. Two of the four tag keys I listed cannot be denied. spored writes
    spawn:last-heartbeat itself every cycle (pkg/agent/agent.go:711) and both writes and
    deletes spawn:ttl-deadline on the spored ttl set path (cmd/spored/main.go:1090-1096,
    via ttl.SetTags). Denying those would break idle detection and spored ttl while
    reading as a hardening. The deny list is therefore three keys — spawn:pre-stop,
    spawn:pre-stop-timeout, spawn:local-username — all of which are set once at launch by
    the CLI and have no in-instance writer. Deadline tampering stays contained by the
    unconditional max-age ceiling (#76) instead, which is the right tool precisely because
    that key has a legitimate writer. There is now a gate that fails if a denied key gains an
    in-instance writer; it catches this exact mistake.

    3. The IAM half does need remediation, unlike #818. spored-instance-role in
    435415984226 carries the vulnerable shape today: ec2:CreateTags conditioned only on
    spawn:managed=true, and zero Deny statements. The role is rewritten on each launch, so
    a launch from a build containing the fix updates it, but a long-lived role keeps the old
    grant until then.

    The reaper code fix is the independent and higher-priority half: it closes the root
    escalation on its own, without waiting for the policy to reach any instance. Deploying the
    reaper is a live change and I have not made it.

    One thing the gates found that the audit did not: security.ValidateUsername accepts
    root, so su - root -c … was a no-op privilege drop. The reaper now refuses it
    explicitly.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions