Repository navigation
fix(ec2): a block device mapping AWS refuses is refused, not materialized (#671) - #680
Merged
Merged
Conversation
Every mapping substrate could parse was accepted and materialized, so IaC carrying an invalid mapping got a green test here and a failure on real AWS. Six refusals now answer InvalidBlockDeviceMapping with a 400, before anything is written. Two are documented verbatim (an Ebs structure naming neither VolumeSize nor SnapshotId; Throughput on a non-gp3 type). Iops on standard/st1/sc1 rests on the sibling launch-template shape. An unparseable numeric value, a duplicate DeviceName and a VirtualName beside an Ebs member are substrate's own reading. Both type-scoped rules key off the explicitly named VolumeType, never the resolved one: substrate defaults absent to gp2 while real EC2 inherits from the AMI, so keying off the resolved type would be a false deny. Per-type numeric ranges are deliberately not encoded for the same reason. The validator runs after the template merge — so a template-carried mapping is refused at RunInstances time, and one validator covers requests, templates, template versions and fleet launches — and before ensureDefaultVPC, so a refusal leaves no VPC, subnet, security group or volume behind. EC2BlockDeviceMapping gains VolumeSizeRaw/IOPSRaw/ThroughputRaw because the parser discarded them, leaving an unparseable value indistinguishable from an absent one; adding fields is replay-safe.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #671.
RunInstancesaccepted every block device mapping it could parse, so IaC carrying a mapping real EC2 rejects got a green test here and a failure on AWS — the same class of defect an emptyImageIdused to have, and the worst kind for a tool that exists to validate infrastructure code before it reaches AWS. Six refusals now answerInvalidBlockDeviceMappingwith a 400, before anything is written.Ebsstructure naming neitherEbs.VolumeSizenorEbs.SnapshotIdEbsBlockDevice.VolumeSize: "You must specify either a snapshot ID or a volume size."Ebs.Throughputon an explicitly named type other thangp3gp3volumes."Ebs.Iopson an explicitly namedstandard,st1orsc1Ebs.VolumeSize,Ebs.IopsorEbs.ThroughputDeviceNameVirtualNamebeside anyEbs.*memberScope: only what the API model states
Both type-scoped rules key off the explicitly named
VolumeType, never the resolved one. Substrate resolves an absent type togp2, but on real EC2 it comes from the AMI's own mapping — commonlygp3— so refusingThroughputon a mapping that named no type would refuse a launch real EC2 accepts. For the same reason the per-type numeric size and IOPS ranges the reference lists are not encoded: they change, and a stale range is a false deny a caller cannot work around. And aVolumeSizeis not compared against the named snapshot's, becauseEC2Snapshot.VolumeSizeis a constant at its single producer and there is noCreateSnapshot— the comparison would test the constant. Follow-up filed for that one.A mapping carrying no
Ebsstructure at all — a bareDeviceName— is still accepted and still takes the 8 GiB default: the size-or-snapshot requirement is documented on a member of theEbsstructure, so with no structure it has no subject.NoDeviceand aVirtualName-only instance store mapping are untouched.Ebs.Iopsuses a short deny list rather than AWS'sio1 | io2 | gp3allow list. The "supported forio1,io2, andgp3volumes only" sentence is onLaunchTemplateEbsBlockDeviceRequest.Iops, not on theEbsBlockDeviceshapeRunInstancesaccepts, and that same member's own paragraph — on both shapes — explains whatIopsmeans "forgp2volumes". AWS contradicts itself inside one member, so substrate refuses only the three types that appear in neither list.Placement
The validator sits between the
ImageIdcheck and theensureDefaultVPCbranch, and both sides of that position are load-bearing:RunInstancestime rather than materialized — and one validator covers requests, templates, template versions and fleet launches alike, since a fleet reaches mappings only through a template.ensureDefaultVPC, which commits a VPC, subnet, security group, internet gateway, route table and four index mutations. A refusal past that point leaves state the next request in the same test sees, which is worse than no validation at all.CreateLaunchTemplatedeliberately does not refuse: its response carries a documentedwarningmember of typeValidationWarningthat exists precisely for "parameters or parameter combinations that are not valid", and its Errors section lists none — so a 400 there would be substrate's invention. Rendering that element is a follow-up.Recording the raw values
EC2BlockDeviceMappinggainsVolumeSizeRaw,IOPSRawandThroughputRaw. The parser discarded them, so by validation timeEbs.VolumeSize=60GBwas indistinguishable from an absent size — and a literal0is not the same thing as absent, which is exactly what the size-or-snapshot rule is about. They are persisted rather than derived because a launch template carries its mappings into state and the original parameters are gone by the time aRunInstancesnames it. Adding fields to a persisted struct is replay-safe: an older event log unmarshals them empty, which reads as "nothing unparseable" — the behavior those logs already had.Provenance
InvalidBlockDeviceMappingis documented in EC2's client-error table ("A block device mapping parameter is not valid. The returned message indicates the incorrect value."). The HTTP status is a class-level inference — the table says only that client errors are "accompanied by a 400-series HTTP response code" — and every per-case message is substrate's own, since AWS publishes no wording. Each message names the offending device, because a request can carry many mappings and the code alone does not say which was refused.Fail-before
All 8 refusal subtests plus both ordering tests fail on the pre-fix tree:
Tests
TestEC2_BlockDeviceMapping_Invalid— 8 rows, one per refusal, asserting 400 + code + exact message.TestEC2_BlockDeviceMapping_ValidIsAccepted— 7 rows pinning the non-refusals, so the scope decision is a test rather than a comment: a bare device name; a snapshot with no size;Iops/Throughputwith noVolumeType;Iopsongp2;NoDevicebeside an instance store mapping; a suppressed device sharing a name with a volume; a size outside the documented range.TestEC2_BlockDeviceMapping_RefusalWritesNothing— no volume, VPC, subnet or instance after a refusal.TestEC2_BlockDeviceMapping_TemplateMappingRefusedAtLaunch—CreateLaunchTemplatereturns 200; theRunInstancesnaming it is refused.TestJourney_EC2InvalidBlockDeviceMappingRefused— SDK tier,smithy.APIErrorwith the code, then zero VPCs and zero volumes.Two existing parser rows are re-labelled as API-unreachable rather than deleted: the unparseable-size row still pins the parser's half of the contract, and the
virtualName-beside-Ebsrow still pins the materializer's totality over replayed or pre-existing state.Compatibility
A
RunInstancesor fleet launch that v0.104.0 and earlier accepted may now fail withInvalidBlockDeviceMapping. The likeliest case by far is a mapping naming aVolumeTypeand no size, which previously produced an 8 GiB volume of that type. No CloudFormation, CDK or Terraform fixture in the repo carries a block device mapping.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race, all packages),go run ./cmd/gen-service-reference -check,bash scripts/check-doc-versions.sh,go test -C test/e2e ./...,npm --prefix docs run build— all clean.