Skip to content

Require IMDSv2 on every launch path (#1588) - #1613

Merged
scttfrdmn merged 3 commits into
mainfrom
hardening/instance-side
Nov 13, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
hardening/instance-side

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1588

What

Every RunInstances call spawn makes now requires IMDSv2: HttpTokens=required, HttpEndpoint=enabled, and HttpPutResponseHopLimit 1. The settings come from one helper, pkg/aws.IMDSMetadataOptions (imds.go).

Path How
spawn launch, nested spawn (the head runs spawn launch), spawn app (DCV/web/desktop), spawn image, burst, batch queue, job arrays, foreground sweeps applyLaunchSettings in Client.Launch now sets it unconditionally
Detached sweep members carrying launch settings LaunchSettings.Apply, the same function. It ignores imdsv2_enforced=false from older CLIs
Detached sweep members with legacy params (no settings) buildRunInstancesInput sets it before the settings are applied
Pipeline stages buildStageRunInstancesInput
Egress proxy Now uses the same helper (it was already hop 1)
pkg/launcher.Provision (lagotto, spore-host-mcp) Through Client.Launch. lagotto picks it up on its next spawn bump

Hop limit 2, path by path

  • spawn task run with container: the task runs in docker run on the default bridge network, one hop further from IMDS than the host. Adapters whose own tooling does the S3 I/O inside the container (resources.s3_read_write, e.g. Snakemake's S3 plugin) need the task role.
  • pkg/launcher with Options.ContainerScript (pkg/userdata container launches): docker run bridged, and the container is the workload. Its only credential is the instance profile. A caller's explicit IMDSv2HopLimit wins.
  • Kept at 1:
    • Web apps: their port is public, and the app role reads the wildcard TLS key.
    • DCV container apps: they run with --network host.
    • Everything else.
  • spawn launch --imds-hop-limit N (1-64) covers user workloads that need more. Compliance mode still forces 1.

Compatibility. The CLI now always writes imdsv2_enforced: true into the launch settings, so a sweep orchestrator deployed before this PR also enforces IMDSv2 for members launched by a new CLI.

Gates

  • TestEveryRunInstancesRequiresIMDSv2 (repo root) discovers every ec2.RunInstancesInput literal in non-test code. It fails any whose function neither sets MetadataOptions nor calls applyLaunchSettings; DryRun literals are exempt. I watched it fail when I removed the pipeline line.
  • TestApplyLaunchSettingsAlwaysRequiresIMDSv2 and TestLaunchSettingsAlwaysCarryIMDSv2Enforced (pkg/aws), TestEveryMemberRequiresIMDSv2 (sweep Lambda), TestStageRequiresIMDSv2, TestTaskLaunchConfig_IMDSHopLimit, TestProvisionHopLimit.
  • The API snapshot gains IMDSMetadataOptions and three constants. These are additions only.

No IAM changes. There is no spored policy change, so no sporedPolicySchema bump.

Not covered here: spawn-ts (src/aws/ec2.ts RunInstancesCommand) lives in its own repo and needs the same change.

Live checks needed before merge (owner)

These are RunInstances-side changes, and the Lambdas need redeploying: sweep-orchestrator, and pipeline-orchestrator (root module). Run in 435415984226, with --ttl 15m on every launch.

  1. spawn launch --ttl 15m --ami <an Ubuntu 22.04 AMI> (an AMI with ImdsSupport unset). aws ec2 describe-instances --query 'Reservations[].Instances[].MetadataOptions' should show HttpTokens=required, HttpPutResponseHopLimit=1. spawn connect should work and spored should heartbeat, which proves spored works under IMDSv2.
  2. Repeat with --imds-hop-limit 2 and expect hop 2. With --imds-hop-limit 0, the default applies. With --imds-hop-limit 65, expect a refusal before any AWS call.
  3. spawn task run with a container: spec that runs aws sts get-caller-identity inside the container. Expect hop 2, and the call succeeds from the container.
  4. spawn app launch of a web kind (e.g. code-server). Expect hop 1. From inside the container, curl -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60' gets no token. The app itself still loads.
  5. After redeploying the sweep orchestrator, run a detached sweep with 2 rows (--detach --ttl 15m). Both members should show HttpTokens=required, hop 1. Optionally, replay an old schedule (legacy params) and expect the same.
  6. After redeploying the pipeline orchestrator, run a 1-stage pipeline. The stage instance should show HttpTokens=required, hop 1.
  7. A lagotto or pkg/launcher launch built against this branch should show required, hop 1.
  8. Leak-check: no instances left from any of these.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_config.go 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check (spore-host-dev, 2026-11-13). The build integrated #1612, #1613, #1614 and #1616 on main.

Not run live: Windows (#1617), the egress proxy (#1618), the release manifest (#1619), retiring a reused DCV/MPI group, and interactive spawn connect.

scttfrdmn and others added 3 commits November 13, 2026 14:24
MetadataOptions (HttpTokens=required, endpoint enabled, hop limit 1)
was set only in compliance mode. It is now set unconditionally in
applyLaunchSettings (Client.Launch, and every detached member's
LaunchSettings.Apply), in the sweep orchestrator for legacy params, in
the pipeline orchestrator, and through one helper in the egress proxy.
That covers spawn launch, sweeps, nested spawn, spawn app, spawn task
and pkg/launcher (lagotto).

Hop limit 2 only where a bridged container is the workload and uses
the instance role: spawn task run with a container, and pkg/launcher
with a ContainerScript. Web apps stay at 1. spawn launch gains
--imds-hop-limit. The CLI always sends imdsv2_enforced=true so an
orchestrator deployed before this change also enforces it.

A root AST gate discovers every RunInstancesInput literal and fails
one whose function does not set MetadataOptions.
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 13, 2026 22:25
@scttfrdmn
scttfrdmn force-pushed the hardening/instance-side branch from 12eaaf6 to 00215bb Compare November 13, 2026 22:25
@scttfrdmn
scttfrdmn merged commit 6f55f5f into main Nov 13, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the hardening/instance-side branch November 13, 2026 22:49
@scttfrdmn scttfrdmn mentioned this pull request Nov 14, 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.

security: IMDSv2 and hop limit 1 are set only in compliance mode; other launch paths leave IMDS at the AMI or account default

1 participant