Skip to content

feat: AMI content-scan orchestration (internal/amiscan) — vet#32 slice 3 - #35

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/ami-snapshot-scan
Jun 25, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/ami-snapshot-scan

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Third slice of vet#32. Ships the testable half of the live AMI content-scan: the orchestration that resolves an AMI's backing snapshot, drives the scan, and guarantees teardown. No resources created in CI.

Why this shape

An AMI's contents aren't directly scannable — you reach them through snapshot → volume → attach → mount → syft. That lifecycle is (a) bug-prone — every created resource must be torn down, even on failure — and (b) inherently live-only — the mount can't be meaningfully faked. So the slice splits the problem:

  • Orchestration (resolve snapshot, drive steps, guarantee teardown) → internal/amiscan, fully fake-tested. This is where the bugs are.
  • Two seams: ImageInspector (read-only EC2 DescribeImages) and Mounter (the live step). The inspector's production impl ships here; the live Mounter is the next slice.

What

  • amiscan.Scanner.Scan resolves the AMI's backing EBS snapshot, mounts it, and returns the SBOM path (not a verdict) — the caller feeds it to a grype cve.Source, keeping CVE matching in internal/cve and AWS plumbing in amiscan.
  • ImageInspector (EC2 DescribeImages, read-only): root-device-preferred snapshot resolution, first-EBS fallback. Resolution logic validated read-only against a real AL2023 AMI (/dev/xvda → snap-0ddddd…); no resources created.
  • Guaranteed teardown: a mount that yields no SBOM is still released (no leak); on any pre-mount failure, no release is returned. Both unit-tested.

Tests

  • amiscan_test.go: happy path, non-AMI ref, inspector error, no-backing-snapshot, mount error, no-SBOM-releases-and-fails (leak safety).
  • ec2_inspector_test.go: root-preference, first-EBS fallback, not-found, API error, instance-store (no EBS).

Next slice

The live Mounter impl: create a volume from the snapshot, attach it to a helper instance, mount, syft the filesystem, then tear it all down. It creates real resources, so it lands with live validation + verified teardown (the discipline used for the Inspector test), not in CI.

Note: gofmt flags internal/sign/sign.go on the current toolchain — pre-existing drift, untouched here.

An AMI's contents aren't directly scannable — you reach them through
snapshot -> volume -> attach -> mount -> syft. That lifecycle is bug-prone
(every created resource must be torn down, even on failure) and inherently
live-only (the mount can't be faked). So this slice ships the testable half.

- internal/amiscan.Scanner orchestrates the scan behind two seams:
  - ImageInspector: read-only EC2 DescribeImages, resolves the AMI's backing
    snapshot (root-device-preferred, first-EBS fallback). Production impl +
    fake-tested resolution logic.
  - Mounter: the live-only snapshot->filesystem->SBOM step (interface only here).
- Scan returns an SBOM PATH, not a verdict — the caller feeds it to a grype
  cve.Source, keeping CVE matching in internal/cve and AWS plumbing in amiscan.
- Guaranteed teardown: a mount with no SBOM is still released; on any pre-mount
  failure no release is returned. Leak-safety is unit-tested.
- EC2 inspector resolution validated read-only against a real AL2023 AMI
  (root /dev/xvda -> snap-0ddddd...). No resources created.

The live Mounter impl (EBS attach + mount + syft + teardown) is the next slice;
it creates real resources, so it lands with live validation, not in CI.

Tests: internal/amiscan/{amiscan,ec2_inspector}_test.go — happy path, non-AMI
ref, inspector error, no-snapshot, mount error, no-SBOM-releases-and-fails;
inspector root-preference/fallback/not-found/api-error/no-EBS. All green.
@scttfrdmn
scttfrdmn merged commit d49c369 into main Jun 25, 2026
2 checks passed
@scttfrdmn
scttfrdmn deleted the feat/ami-snapshot-scan branch June 25, 2026 21:10
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.

1 participant