Skip to content

ec2: an invalid block device mapping is accepted instead of refused with InvalidBlockDeviceMapping #671

Closed

Description

@scttfrdmn

Context

v0.103.0 (#666) made RunInstances parse and materialize BlockDeviceMapping.N.*. It
validates none of it: a mapping that real EC2 would refuse with InvalidBlockDeviceMapping
is accepted and produces a volume.

The tolerant reads #666 chose on purpose (an unparseable number reads as zero rather than
failing the launch, matching what ec2ParseNetworkInterface does for DeviceIndex) are
part of what this issue should revisit now that there is state to validate against.

Cases AWS refuses that substrate currently accepts:

  • A data volume naming neither Ebs.VolumeSize nor Ebs.SnapshotId. The
    EbsBlockDevice reference is explicit: "You must specify either a snapshot ID or a volume
    size." Substrate silently defaults to 8 GiB.
  • Ebs.VolumeSize smaller than the snapshot's size.
  • A VirtualName alongside Ebs.* members on one mapping — a contradictory mapping. EC2: RunInstances' inline BlockDeviceMapping.N.Ebs.* is parsed nowhere and never reaches DescribeVolumes #666
    deliberately honors the EBS half rather than dropping a volume the caller sized, which was
    the right call when the alternative was silence, but AWS refuses it outright.
  • Ebs.Iops on a volume type that does not take provisioned IOPS, and Ebs.Throughput on
    anything but gp3.
  • A size outside the type's documented range, and an IOPS value outside it.
  • A duplicate DeviceName across two mappings.

Why it was deferred out of #666

Validation needs the state it validates to exist first: before #666 there was no parsed
mapping to check and no volume to compare a snapshot size against. The fix also has a
compatibility edge that deserves its own release note — a request substrate accepted in
v0.103.0 will start failing — which is a poor fit for a PR whose headline is "the parameter
is no longer discarded".

Acceptance criteria

  • Each case above is refused with InvalidBlockDeviceMapping and a message checked
    against AWS's own wording where it is observable, or documented as substrate's own
    where it is not (per the house provenance rule).
  • The error code and HTTP status are verified against the EC2 API reference, not recalled.
  • Validation happens before any volume is written, so a refused launch leaves no partial
    state — asserted by a test that refuses and then lists volumes.
  • A launch template carrying an invalid mapping is refused at RunInstances time, and it
    is decided and documented whether CreateLaunchTemplate refuses it too (AWS validates
    some template fields lazily; check rather than assume).
  • The tolerant numeric reads are revisited: either an unparseable VolumeSize becomes an
    error, or the tolerance is documented as deliberate with the reason.
  • docs/services.md — the "not modeled" paragraph of the launch-time storage subsection
    loses this item.
  • CHANGELOG.md under ## [Unreleased], with a compatibility note: a mapping v0.103.0
    accepted may now be refused.

Activity

  1. modified the milestones: v0.104.0, v0.105.0 on Aug 20, 2026
  2. scttfrdmn commented on Aug 20, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to milestone v0.105.0. v0.104.0 ships the #662 privilege-boundary fix alone, matching how #660 shipped as v0.102.0 — a false-allow in the authorization path gets a release to itself.

    Scope decision (settled): validate only what the API model states

    Refuse the cases AWS's API reference makes explicit:

    • a data volume naming neither Ebs.VolumeSize nor Ebs.SnapshotId;
    • a duplicate DeviceName across two mappings;
    • a VirtualName combined with Ebs.* members on one mapping;
    • Throughput on a non-gp3 volume type;
    • Iops on a type that takes none.

    Do not encode the per-type numeric size/IOPS ranges from the user-guide table. Those ranges drift as AWS raises limits, and a stale range refuses a request real EC2 accepts — a false deny baked into the emulator, which is the failure mode substrate can least afford. That removes "a size outside the type's documented range, and an IOPS value outside it" from the list above.

    Message provenance

    • InvalidBlockDeviceMapping appears in the "Client error codes for specific actions" table, with the message text described only as "The returned message indicates the incorrect value". AWS documents no wording, so substrate's per-case messages are its own and the code comment must say so, per the house provenance rule.
    • Documented wording does exist elsewhere and should be quoted: EbsBlockDevice gives "You must specify either a snapshot ID or a volume size" for the size-vs-snapshot case, and "This parameter is valid only for gp3 volumes" for Throughput.
    • AWS documents no rule at all for a duplicate DeviceName, nor for VirtualName beside Ebs.*. Both refusals rest on substrate's own reading of the model and should be labelled that way in the comment rather than presented as observed behaviour.

    Answering the fourth acceptance criterion

    CreateLaunchTemplate answers an invalid mapping with a ValidationWarning on a successful response, not a client error. So CreateLaunchTemplate should not refuse; refusal happens at RunInstances time only. That resolves the "check rather than assume" half of the criterion.

    Validate-then-write

    runInstancesWithTags is already validate-then-write in shape — every &AWSError return precedes the first state.Put. Two things break it:

    • ensureDefaultVPC (emulator/ec2_plugin.go:502-521) mutates state before the security-group validation at :542, so a refused launch can already leave a default VPC behind.
    • The per-instance loop Puts instance 1 before building instance 2, so a Count > 1 launch that fails partway leaves instance 1 written.

    Both need addressing for the "a refused launch leaves no partial state" criterion to hold as written.

    One more note

    EC2Snapshot.VolumeSize is hardcoded to 8 at its single producer (createImage, emulator/ec2_plugin.go:3225). So a size-vs-snapshot comparison currently exercises a constant — the test can pass without the comparison being correct. Either the producer records a real size first, or the test seeds the snapshot record directly and says why.

  3. added 20 commits that reference this issue on Sep 14, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions