Skip to content

vet AMI deep-content scanning: scan the image (SBOM + CVE), don't just gate on a pre-placed record #32

Closed

Description

@scttfrdmn

Context

The AMI-gating epic (#13) Layer 1 is otherwise shipped: `vet ami-reference` writes the golden `attest:pcr` tags, and `vet gate ami-… --tag-vetted` writes the locked `attest:vetted` tag fail-closed (ground's launch-gating + lockdown SCPs enforce/protect them, adversarially simulator-tested). The runtime binding (nitro/tpm `--expected-from-ami`) is also done.

The one remaining capability gap: `vet gate ami-…` evaluates a pre-existing verification record and writes the tag — but vet does not scan the AMI's own contents. `vet verify ami-…` today treats the AMI ref like any artifact: it looks for a pre-placed SBOM in `.vet/sboms/` and runs OSV against it, but there is no code that inspects the AMI/EBS-snapshot itself. (See `internal/verify/verify.go` — `artifactHash` returns empty for AMI refs; no Inspector/snapshot/syft-on-image path exists. This is deferred-by-design per the current CHANGELOG/README, not a regression.)

So an operator wanting real CVE gating on an AMI must scan it out-of-band and hand-place the SBOM. That's the gap.

Open decision (do first)

CVE/SBOM source for an AMI — two viable approaches, pick one (or make it pluggable):

  1. Amazon Inspector — fetch findings via the Inspector API for the AMI/instance; convert to the gate's CVE inputs. No snapshot handling; depends on Inspector being enabled.
  2. EBS snapshot → syft — snapshot the AMI's volume, mount/read it, run syft to generate the SBOM, then the existing OSV path. Self-contained but heavier (snapshot lifecycle, live AWS, IAM).

Both need live AWS and so can't be exercised in CI without real resources — mirror the suite's pattern: small injectable interfaces + fakes for the logic, the live wiring gated/manual.

Scope

  • Decide the scan source (Inspector vs snapshot→syft vs pluggable) — security/ops review.
  • Implement `vet verify ami-…` to scan the image and populate the verification record (SBOM + CVE), instead of requiring a pre-placed SBOM.
  • Unit-test the logic behind injectable interfaces (fake Inspector/EC2); document the live runbook + any new IAM actions in `docs/required-permissions.md`.
  • Update CHANGELOG + the AMI-gating notes; cross-link vet verify --check-cves is a no-op: CVE gating silently passes vulnerable artifacts #13.

Explicitly out of scope / non-gaps

  • AWS Allowed AMIs as the launch-enforcement primitive — decided against in favor of the per-AMI tag primitive (rationale: `ground/policies/SECURITY.md`; per-AMI granularity vs per-owner coarseness). Not unfinished work.
  • Golden-PCR computation — enclave/NitroTPM PCRs cannot be computed offline from an AMI; they're captured from a trusted reference boot (by design).

Tracked under #13.

Activity

  1. added
    type:feature
    priority:medium
    on Jun 25, 2026
  2. scttfrdmn commented on Jun 25, 2026

    @scttfrdmn
    ContributorAuthor

    Live both-source test (2026-06-25) — both paths exercised against real AWS, then torn down

    Ran a real comparison in account 942542972736 (us-east-1) on a throwaway t3.micro from stock AL2023 (ami-00948338a4aeec604). All resources tagged ephemeral=true and fully torn down + verified gone (instance terminated, snapshot deleted, Inspector disabled, IAM role/profile removed; an ephemeral=true sweep returned empty). Cost: well under $1.

    Path B — snapshot → syft → OSV

    • Snapshot lifecycle: CreateSnapshot works, fast (seconds to request). ✅
    • Package extraction: 492 real rpm packages enumerated off the running image (rpm -qa, equivalent to syft on the mounted snapshot). ✅
    • ⚠️ Finding-quality gotcha: querying OSV /v1/query with ecosystem Linux returns 0 vulns for distro packages (bash 5.2.15, bind-libs 9.18.49, openssl, curl at their AL2023 versions). OSV's Linux ecosystem is upstream-kernel-scoped, not Amazon-ALAS-aware — so a naive syft→OSV reports a distro AMI as falsely clean. The syft path needs a distro-aware matcher (e.g. Grype with its ALAS feed, or correct ecosystem mapping), not the raw OSV-Linux path vet uses today for language packages.

    Path A — Amazon Inspector v2

    • Enable latency: ENABLING → ENABLED took ~6 min.
    • Findings on the fresh instance: 1 — but a network finding ("Port 22 reachable from an Internet Gateway", MEDIUM), not package CVEs.
    • ⚠️ Coverage gotcha: scanStatus = INACTIVE, reason UNMANAGED_EC2_INSTANCE. Despite SSM registration, Inspector did not run the package/CVE scan — it needs the instance to be a managed instance (its own SSM-association posture) first, or you use Inspector agentless EC2 scanning, which internally EBS-snapshots the volume (i.e. Inspector's agentless mode is the snapshot path, AWS-managed).

    Verdict — pluggable source interface is the right call

    Dimension Inspector v2 snapshot → syft
    Scan code to write ~none (managed) snapshot lifecycle + SBOM + matcher
    Distro (ALAS) accuracy native needs distro-aware matcher (raw OSV Linux = false-clean)
    Latency enable ~6 min + scan; managed-instance gating snapshot seconds + local syft
    Cost account-level + per-resource billable EBS snapshot storage (cents)
    On-demand per-AMI indirect (needs covered/agentless) direct
    Live gotcha found UNMANAGED_EC2_INSTANCE blocks pkg scan OSV Linux ≠ ALAS

    Both have real, different sharp edges, confirming the two should be pluggable sources behind one interface (as this issue proposed). Notable: Inspector's agentless mode and the syft path converge on the same EBS-snapshot mechanism — so the build could share a snapshot substrate and differ only in the matcher/finding source.

    Recommended scope refinement for the build:

    1. Define a CVESource interface; impls: inspector (agentless, ALAS-native) and snapshot+grype (self-contained, ALAS feed).
    2. Do not use raw OSV Linux for distro AMIs — wire a distro-advisory matcher.
    3. Both need live AWS → small injectable interfaces + fakes in CI, live wiring manual (suite pattern).
  3. scttfrdmn commented on Jun 25, 2026

    @scttfrdmn
    ContributorAuthor

    Status — slices 1–4 merged; slice 5 (live adapters) in progress

    The whole architecture and all bug-prone logic is now on main, fully unit-tested, no AWS in CI:

    Slice What PR
    1 Pluggable cve.Source seam (OSV default) #33
    2 GrypeSource (distro-aware) + vet verify --cve-source auto|osv|grype routing #34
    3 internal/amiscan orchestration + read-only EC2 ImageInspector (resolves backing snapshot) #35
    4 Live Mounter volume-lifecycle core — guaranteed teardown on every failure path #36

    Slice 5 (in progress): the thin live AWS adapters behind the slice-4 seams —

    • VolumeManager → EC2 CreateVolume(from snapshot) / AttachVolume / DetachVolume / DeleteVolume
    • RemoteScanner → SSM SendCommand (mount read-only + syft) + S3 (ferry the SBOM back; a full-AMI SBOM exceeds SSM's inline output cap)

    Plus vet verify ami-… --deep-scan wiring so an AMI target runs the snapshot→syft→grype path end to end.

    Prerequisite for live validation (operator-provided, by design): a running, SSM-managed, syft-equipped helper Linux instance to attach the scan volume to. vet deliberately does not create/terminate the helper (keeps teardown to a volume + attachment only) — see slice 4. Live validation against a real AMI with verified teardown follows the adapters.

  4. scttfrdmn commented on Jun 25, 2026

    @scttfrdmn
    ContributorAuthor

    Live validation (2026-06-25) — vet ami-scan proven end to end; one real bug found + fixed

    Ran the full pipeline against a real AL2023 AMI (ami-00948338a4aeec604) in account 942542972736, with an operator-style helper (throwaway t3.micro: SSM-managed, syft 1.18.1 + awscli, instance-profile s3:PutObject to a staging bucket). All resources torn down + verified gone (helper terminated, bucket 404, IAM NoSuchEntity, zero stray vet:ephemeral volumes).

    Bug found by the live test (now fixed)

    First run failed at mount: special device /dev/sdfp1 does not exist. On Nitro instances an EBS volume attached as /dev/sdf surfaces as an NVMe device (/dev/nvme1n1), so the remote script's name-based device guessing was wrong. Fixed: the remote script now discovers the freshly-attached disk via lsblk (the unmounted disk that isn't the running root) and mounts its largest partition. Re-run log confirms: scanning /dev/nvme1n1p1 (requested /dev/sdf) → mount → syft → Success.

    What was proven

    • Pipeline: resolve backing snapshot (snap-0ddddd…) → create volume → attach → SSM mount read-only → syft → upload to S3 → store locally. ✅
    • Real artifact: a 3.1 MB, 1549-component CycloneDX SBOM with the AL2023 distro metadata (amzn) that the lossy package list drops — i.e. exactly what the grype source needs (and what a naive OSV Linux query is false-clean on).
    • Teardown safety, proven live: on the first run's failure, vet's deferred release still detached + deleted the scan volume (zero leak) — the slice-4 guarantee, confirmed against real AWS. (One volume was orphaned later by my own 2-min shell timeout killing vet mid-run, not a vet defect; I cleaned it up manually.)

    The fix ships as a follow-up commit to the slice-5 remote script. vet#32 is complete — the AMI deep-content-scan gap (the last open item of the AMI-gating epic, #13) is closed and live-validated.

  5. scttfrdmn commented on Jun 25, 2026

    @scttfrdmn
    ContributorAuthor

    Complete. All six slices merged (#33–#38) plus the live-validation fix (#39). vet ami-scan resolves an AMI's backing snapshot → mounts a read-only copy on an operator helper → syfts → stores an SBOM that vet verify --check-cves gates on via the distro-aware grype source. Live-validated end to end against a real AL2023 AMI (1549-component SBOM), with volume teardown proven on both success and failure paths. Both CVE sources remain pluggable (--cve-source osv|grype); Amazon Inspector stays a documented alternative source.

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

    priority:mediumtype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions