Repository navigation
feat(ec2): DescribeTags, the operation whose whole job is finding resources by tag (#688) - #700
Merged
Merged
Conversation
…ources by tag (#688) DescribeTags reached the dispatcher's default arm and answered InvalidAction/400 while four bundled managed policies granted ec2:DescribeTags — a policy permitted an operation nothing served. Five filters, all evaluated, with the wildcards AWS's Example 4 documents for this operation, and no tag-key — alone in the describe family, because key already asks that question. MaxResults 5-1000 (refused outside the range, not clamped), an offset NextToken, and a deterministic (resourceId, resourceType, key) sort, which is stricter than AWS because StateManager.List promises no ordering and an offset token over an unordered list could answer one replayed request two ways. The scan reads thirteen resource types where CreateTags writes nine: an image, snapshot, launch template or fleet takes its tags from its own create call's TagSpecification, so reporting only the writable types would hide tags a caller had successfully applied.
Codecov Report❌ Patch coverage is
📢 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 #688.
DescribeTags— the EC2 operation whose whole job is finding resources by tag — reached thedispatcher's
default:arm and answeredInvalidAction/ HTTP 400, while four bundledmanaged policies granted
ec2:DescribeTags:AmazonVPCFullAccessandAmazonVPCReadOnlyAccessname it outright (emulator/iam_managed.go:785,:878), andAmazonEC2FullAccessandAmazonEC2ReadOnlyAccessreach it throughec2:*andec2:Describe*. A policy permitted an operation nothing served.Real EC2 offers three routes to a resource's tags: this operation, a
tag:<key>filter oneach describe, and Resource Groups Tagging. Substrate served the third in full and the second
on five operations (#685/#686/#687, earlier in this milestone). This is the first.
What it does
New
emulator/ec2_describetags.goplus one dispatch arm besideCreateTags/DeleteTags.TagDescription—resourceId,resourceType,key,value— undertagSet>item, plusnextToken,omitempty. Its own struct rather thanec2TagItem, whichcarries no resource. No
omitemptyonvalue: AWS's Example 1 renders<value/>for atag whose value is empty, and an SDK tells a present-but-empty element from an absent one.
key,resource-id,resource-type,value,tag:<key>. This is the only operation in the family with anempty
acceptedlist.tag-key. Alone in the describe family, this operation documents none — itskeyfilter already matches a key whatever its value. So
tag-keyis refused here while itis accepted on every neighbour. That is AWS's set, not an omission, and it has a test and a
comment saying so, because it reads like one.
ec2FilterAccepts.AWS's Example 4 states it outright for this operation: "You can use wildcards with filters,
so you could specify the value as
?ebserverto find tags with the keywebserverorWebserver." This is the first site outsideDescribeInstanceTypeOfferingsto honour them(ec2: filter values match exactly everywhere except DescribeInstanceTypeOfferings, where AWS documents wildcards for all of them #697 is the rest).
MaxResults5–1000 — AWS's range for this operation, whereDescribeLaunchTemplateVersions' floor is 1, so the constant cannot be shared. A valueoutside the range is refused, not clamped. The token is
DescribeLaunchTemplateVersions'wire shape: a decimal offset,
InvalidParameterValueon a malformed one, an out-of-rangeoffset clamped to an empty last page, and no token on the last page.
(resourceId, resourceType, key)before paging.Two decisions worth reading
The scan is deliberately wider than what
CreateTagscan write.ec2TaggableResourcecovers nine prefixes; the scan reads thirteen, adding
image,snapshot,launch-templateand
fleet— types whose tags arrive through their own create call'sTagSpecification.Nandcannot be set through
CreateTagsat all (#689 adds the snapshot arm, #695 the rest).Reporting only the writable types would hide tags a caller had successfully applied.
TestEC2_DescribeTags_ScanIsWiderThanCreateTagspins both halves of the asymmetry together,so #689 has a test to change rather than a surprise to find.
placement-groupis the one type carrying aTagsfield left out: nothing writes it, and itsrecords are keyed by group name where AWS's
TagDescriptionreports an ID, so the sharedkey-tail helper would report the wrong identifier. (This corrects the plan's own note, which
also listed
keypair—EC2KeyPairhas noTagsfield at all.)The sort is stricter than AWS, which says its order "might vary" and that applications
should not rely on it.
StateManager.Listpromises no ordering either(
emulator/types.go:123-124), so an offset token over an unordered list could skip or repeata tag between pages, and two replays of one recorded request could answer differently. A
deterministic emulator cannot answer one request two ways.
One helper rather than thirteen:
ec2StatePrefix(namespace, accountID, region)plus a{namespace, resourceType}table, since every EC2 key is<ns>:<account>/<region>/<id>. TheresourceTypespelling is written beside each namespace rather than derived —sgissecurity-groupandnatisnatgateway, and neither could be computed.Fail-before
Recorded before the fix, by deleting the dispatch arm and
emulator/ec2_describetags.go— i.e.the pre-#688 tree — with the harness asserting the arm appeared exactly once,
go veting theresult so a non-compiling tree would be BROKEN rather than a result, and restoring by file copy
with sha256 byte-identity printed for both files.
Every one failed the same way:
InvalidAction/EC2Plugin: unknown action DescribeTags,HTTP 400 (
emulator/ec2_plugin.go:245-250).Tests
Eight unit tests through HTTP, because the whole defect was on the wire, plus an SDK
journey (
test/e2e/journey_ec2_describetags_test.go) — the only tier that shows a realclient's shape agreeing with substrate's, since the SDK decides how
Filtersserialize andhow
tagSetdecodes into[]types.TagDescription. It walks the region withec2.NewDescribeTagsPaginator, whose loop terminates only because the last page carries notoken, and asserts
ResourceTypeagainst the SDK's own enum constants — a spelling substrateinvented would otherwise arrive as an unknown enum value rather than failing loudly.
Docs
docs/services.mdgains aDescribeTagsrow, a row in the per-operation evaluated/inerttable, and a Finding a resource by tag subsection carrying the wider-than-
CreateTagsscan, the no-
tag-keyrule, and the stricter-than-AWS ordering with its reason. Threeexisting statements are now reconciled rather than left standing:
DescribeTagsat all" → all three routes now served.DescribeInstanceTypeOfferings; it is now the twooperations whose reference pages state wildcards outright.
DescribeSecurityGroups;DescribeTagsroutes through the same shared matcher, so it inherits the rule rather than choosing it —
said so in both the docs and the code comment.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race, ok),make coverage,make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...andgo test -C test/e2e ./...all clean.docs-versionscaught a pinnedv0.106.0in the newprose on the first pass; it now links the issue instead.