Repository navigation
feat: AMI content-scan orchestration (internal/amiscan) — vet#32 slice 3 - #35
Merged
Merged
Conversation
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
internal/amiscan, fully fake-tested. This is where the bugs are.ImageInspector(read-only EC2DescribeImages) andMounter(the live step). The inspector's production impl ships here; the liveMounteris the next slice.What
amiscan.Scanner.Scanresolves the AMI's backing EBS snapshot, mounts it, and returns the SBOM path (not a verdict) — the caller feeds it to a grypecve.Source, keeping CVE matching ininternal/cveand AWS plumbing inamiscan.ImageInspector(EC2DescribeImages, 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.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
Mounterimpl: 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.