Skip to content

fix(ec2): CreateVolume invents neither a size nor a zone (#712) - #723

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/712-createvolume-parameter-rules
Aug 22, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/712-createvolume-parameter-rules

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #712

What AWS documents, and what #712 got wrong

CreateVolume puts two combination rules on its parameters and marks every member involved Required: No, because each requirement is on a pair:

  • Size — "You must specify either a snapshot ID or a volume size."
  • AvailabilityZone / AvailabilityZoneId — said once on each member: "Either AvailabilityZone or AvailabilityZoneId must be specified, but not both."

#712's premise is corrected in passing: it quotes AWS as documenting "Size is required unless SnapshotId is specified" and AvailabilityZone as required. Neither sentence exists. The rules are the combination ones above, which is why both members read Required: No.

What substrate did

It read neither rule, and answered HTTP 200 in every broken case:

request before now
no Size, no SnapshotId 8 GiB volume InvalidParameterCombination, 400
Size=-1, Size=eight, Size=8.5 8 GiB volume InvalidParameterValue, 400, quoting the value
no zone at all zone <region>a InvalidParameterCombination, 400
both zone spellings zone name wins, ID ignored InvalidParameterCombination, 400
AvailabilityZoneId alone ignored → zone a resolved to the zone's name

The size parse was if n, err := strconv.Atoi(s); err == nil && n > 0 with no else — a discarded error and a discarded out-of-range value. Each of these reported success, so the volume was real, at a size and in a zone the caller never asked for, and the first visible symptom was an attach failing later with nothing to point at. All three refusals land before the state write; TestEC2_CreateVolume_RefusalWritesNothing pins that five refused calls leave DescribeVolumes empty.

AvailabilityZoneId, and the zone-ID bug it exposed

The ID resolves through the same derivation DescribeAvailabilityZones renders from, so a zone ID read out of one operation is one the other accepts — pinned by round-tripping all three zones.

Making a zone ID an input for the first time exposed the derivation: it produced ue11-az1 for us-east-1 — wrong prefix, doubled digit — where AWS publishes use1-az1, and the code's own comment claimed use1. Nothing caught it because zone IDs were only ever emitted, and a test that read one back and filtered on it was self-consistent whatever the string said. A consumer fixture carrying the real use1-az1 would have been refused.

AWS's table refutes AWS's own summarising sentence ("the first three letters of the Region code, followed by the number at the end"): that rule gives aps2 for ap-southeast-2, and the table says apse2. The real shape is the first segment verbatim, one letter per compass word, then the trailing number. TestEC2_ZoneIDPrefixMatchesAWSPublishedTable pins 18 rows copied from the table, with ap-southeast-2 and ap-northeast-1 as the rows that settle it.

Two deliberate asymmetries, documented rather than left to be discovered:

  • A zone name is recorded as given and not validated; a zone ID must resolve, because it has to be translated into the name the record and every response carry. Validating names is a wider change than the pair rule and one substrate has never made on any zone-taking operation.
  • An unresolvable zone ID answers InvalidParameterValue, not the combination code — the pair is well-formed, the value is not.

Provenance

Both refusal codes are substrate's reading. CreateVolume's Errors section is empty — it publishes no operation-specific error at all — so #712's acceptance criterion "verify the code against the reference" cannot be met as written. InvalidParameterCombination's EC2 client-error gloss is the only candidate whose shape fits: "The request includes an incorrect combination of parameters, or a missing parameter."

The zone-ID prefix comes from AWS's published table, chosen over AWS's prose describing it. AWS also states "we independently map Availability Zones to codes for each AWS account", so the real name→ID pairing is per-account; substrate always maps zone a to -az1, and the docs say plainly not to use substrate to verify that code treats the mapping as account-specific.

Also fixed: a wall-clock-dependent test

DescribeSpotPriceHistory renders its timestamp from the time controller at scale 1.0, so the RFC3339 value changes at every second boundary. #695's timestamp subtest read the value out of one response and filtered on it in the next, failing whenever a second elapsed between them — about one run in sixty, on main. It runs against a frozen clock now (scale zero; reachable only in-process, since POST /v1/control/scale refuses a non-positive scale).

Out of scope, stated in the docs

AWS's per-volume-type size ranges (gp2 1–16384, io1 4–16384, st1/sc1 125–16384, standard 1–1024) are still unenforced, and Iops/Throughput keep their existing tolerance for an unparseable value — Size differs because its absence differs: a volume must have a size, while omitting Iops is the ordinary case for the five types that do not take one. The launch path keeps ec2DefaultVolumeSizeGiB, where a mapping omitting a size is legal; its doc comment now says it no longer backs CreateVolume.

Verification

Fail-before established empirically in a throwaway worktree at 6f0f579: all five new CreateVolume tests failed, 22 subtests — and the failing subtest names (ue11-az2, ue11-az3) are what exposed the zone-ID bug.

gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./...   # 0 issues
make test                                                                 # green, race on
make coverage                                                             # 83.2% emulator
make docs-reference docs-reference-check docs-versions                     # up to date
npm --prefix docs run build                                               # 317 hrefs / 326 ids, none dangling
go vet -C test/e2e ./... && go test -C test/e2e ./...                     # green

AWS puts two combination rules on CreateVolume and marks every member
involved Required: No, because each requirement is on a *pair*: "You must
specify either a snapshot ID or a volume size" and, said once on each
member, "Either AvailabilityZone or AvailabilityZoneId must be specified,
but not both." Substrate read neither. A request naming no size got a
silent 8 GiB volume, one naming Size=-1 or Size=eight got the same, and
one naming no zone got <region>a — each with HTTP 200 and a volume ID, so
the volume was real, at a size and in a zone the caller never asked for,
and the first symptom was an attach failing later with nothing to point at.

AvailabilityZoneId is read for the first time; it resolves through the same
derivation DescribeAvailabilityZones renders from. That made the zone-ID
shape load-bearing on the request side and exposed the derivation's own
bug: it produced ue11-az1 for us-east-1 where AWS publishes use1-az1.

Both refusal codes are substrate's reading — CreateVolume's Errors section
is empty — from InvalidParameterCombination's gloss, the only one naming a
missing parameter in an either/or.

Closes #712
@scttfrdmn
scttfrdmn merged commit 1318a51 into main Aug 22, 2026
15 checks passed
@scttfrdmn
scttfrdmn deleted the feat/712-createvolume-parameter-rules branch August 22, 2026 02:35
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.66667% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_plugin.go 94.66% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

ec2: CreateVolume with neither Size nor SnapshotId produces an 8 GiB volume where AWS refuses

1 participant