Repository navigation
fix(kinesis): a stream can be named by its ARN (#966) - #998
Merged
Merged
Conversation
Fifteen of the seventeen Kinesis operations substrate models publish StreamARN
beside StreamName, both Required: No, under a Note byte-identical on all fifteen
pages: "you must use either the StreamARN or the StreamName parameter, or both.
It is recommended that you use the StreamARN input parameter when you invoke
this API." Substrate declared StreamName alone in fifteen separate request
structs, so a caller sending only the ARN reached an empty-name guard and was
refused, under InvalidParameterException -- a code Kinesis publishes nowhere at
all. The recommended form was the one form that could not work.
The account and Region now come from the ARN rather than the request context, by
one parser that takes no *RequestContext at all, and the three state helpers now
take a resolved target instead of one, so a handler cannot reach the caller's own
account by accident. Every key a request touches is derived from that single
resolution -- the stream record, its per-shard records, and its ListStreams index
entry -- so a cross-account UpdateShardCount, MergeShards or AddTagsToStream
writes to the target rather than copying it into the caller's namespace, and a
cross-account DeleteStream removes the target's index entry rather than the
caller's. The tagging API's kinesis arm goes through the same parser, so the two
cannot disagree about which stream an ARN names or where its tags live.
What the published pattern arn:aws.*:kinesis:.*:\d{12}:stream/\S+ states is
enforced and no more: a consumer ARN is refused, StreamName's own character class
is not applied to the name inside an ARN because nothing applies it on
CreateStream either, and an empty-Region ARN resolves to a key nothing is written
at rather than being refused for a shape the pattern admits.
Two members that disagree are refused, which is substrate's reading -- no page
says what happens -- and only the name segments are compared, since an ARN in
another account is the whole point of the change. A request carrying neither is
refused too, replacing the "StreamName is required" guard.
GetRecords publishes StreamARN and no StreamName and carries the boilerplate Note
anyway; that contradiction is AWS's and is recorded rather than resolved. Its
optional StreamARN is checked against the iterator that names its stream.
ResourceNotFoundException moves from 404 to 400 and ResourceInUseException from
409 to 400: every error on all seventeen pages is published at 400.
docs/services.md records which forms each operation accepts, replacing #954's
note that StreamARN is not accepted, and lists the five implemented operations
the table had omitted.
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 #966.
The defect
Fifteen of the seventeen Kinesis operations substrate models publish
StreamARNbesideStreamName, bothRequired: No, under a Note that is byte-identical on all fifteen pages:Substrate declared
StreamNamealone in fifteen separate request structs, so a caller sending only the ARN reached an empty-name guard and was refused — underInvalidParameterException, a code Kinesis publishes nowhere at all. The recommended form was the one form that could not work, and it is what an AWS SDK client constructed from an ARN sends, and what a CloudFormationRef, a Lambda event-source mapping and an IAM policy resource all carry.The audit the issue asks for
Every operation checked against its own reference page:
StreamARNStreamName(14)DeleteStream,DescribeStream,DescribeStreamSummary,UpdateShardCount,MergeShards,SplitShard,PutRecord,PutRecords,GetShardIterator,AddTagsToStream,RemoveTagsFromStream,ListTagsForStream,EnableEnhancedMonitoring,DisableEnhancedMonitoringStreamName(1)GetRecords— its stream is implied by the requiredShardIteratorCreateStream(the service's one operation-wideRequired: YesStreamName; it mints an ARN rather than resolving one) andListStreams(names no single stream, so it publishes neither member)StreamIdappears on all fifteen as "Not Implemented. Reserved for future use." and is left alone.What changed
The account and Region come from the ARN, not the request context. One parser,
kinesisParseStreamARN, takes no*RequestContextat all, and the three state helpers now take a resolved target instead of one — so a handler cannot reach the caller's own account by accident. The compiler enforces what a convention would only ask for. Every key a request touches is derived from that single resolution: the stream record, its per-shard records, and itsListStreamsindex entry. A cross-accountUpdateShardCount,MergeShardsorAddTagsToStreamtherefore writes to the target rather than copying it into the caller's namespace, and a cross-accountDeleteStreamremoves the target's index entry rather than the caller's.That is the arrangement #826 established for SQS and DynamoDB, #845 for the tagging resolver, #918 for CloudFront, #922 for KMS, #925 for SNS and #912 for Step Functions. The in-file precedent was already there:
getShardIterator's token has always carried the account and Region, which is whyGetRecordsneeds no request context of its own.The tagging API's kinesis arm goes through the same parser, so Kinesis's fifteen operations and Resource Groups Tagging cannot disagree about which stream an ARN names or where its tags live. It is stricter than before as a result — an ARN whose account is not twelve digits, or whose partition does not begin
aws, is now refused rather than resolved to a key nothing is written at.Exactly the published pattern is enforced, and no more.
arn:aws.*:kinesis:.*:\d{12}:stream/\S+:/means the ARN names a consumer (stream/{name}/consumer/{name}:{timestamp}), which substrate does not model, so it is refused — the test the tagging arm has applied since it was written;StreamName's own[a-zA-Z0-9_.-]+class is deliberately not applied to the name inside an ARN, because nothing applies it onCreateStreameither: applying it only here would make a stream substrate itself lets a caller create unaddressable by its own ARN;.*, so such an ARN resolves to a key nothing is written at and reports the stream absent rather than being refused for a shape AWS's own pattern accepts — the decision Eleven Step Functions operations resolve a resource by the ARN's last segment plus the caller's own account and Region #912 recorded for an express execution ARN.Stated as substrate's readings
InvalidArgumentException/400. No Kinesis page says what happens, and serving either of them is how a caller's bug stays hidden — the judgement Step Functions: all three tag operations take the account from the request, not the ARN, so a foreign-account ARN tags the caller's own state machine #910 and Eleven Step Functions operations resolve a resource by the ARN's last segment plus the caller's own account and Region #912 applied to a well-formed ARN of the wrong resource type. Only the name segments are compared: an ARN whose account or Region differ from the caller's is not a disagreement but the whole point of the change, and it wins.InvalidArgumentExceptionis published on all fifteen operations whereInvalidParameterExceptionis published on none. The ~33 remainingInvalidParameterExceptionsites are the body-decode guards and are Twenty-seven plugins answer twenty-one different codes for an unparseable body, and at least three are codes the service does not publish #950's.GetRecords' redundantStreamARNis validated against its iterator rather than ignored, since ignoring it would serve records from a stream the request did not name.A contradiction in AWS's own documentation, recorded rather than resolved
API_GetRecordspublishesStreamARNand noStreamName— and carries the boilerplate Note anyway, naming a parameter the same page does not document. Substrate follows the shape.Provenance
From AWS: the Note, verbatim and identical on all fifteen pages; the
StreamARNpattern, byte-identical everywhere it is published;InvalidArgumentException's description ("A specified parameter exceeds its restrictions, is not supported, or can't be used");ResourceNotFoundException's ("The requested resource could not be found. The stream might not be specified correctly.");StreamId's "Not Implemented. Reserved for future use."; and every error on every one of the seventeen pages being published at HTTP 400 (the service's only 500 isInternalFailureException, which substrate does not raise).Compatibility
ResourceNotFoundExceptionmoves from HTTP 404 to 400 andResourceInUseExceptionfrom 409 to 400 at every Kinesis operation. A consumer branching on the status rather than the code saw something no Kinesis endpoint sends.InvalidArgumentExceptionrather thanInvalidParameterExceptionat the fifteen operations that publishStreamARN.CreateStream's own guard is unchanged.StreamARNnaming another account or Region now addresses that stream rather than being refused. A test that relied on the refusal, or that passed an ARN expecting it to be ignored, changes answer.awspartition is nowInvalidArgumentException.Verification
The nine-command gate, all green. Coverage 84.6% emulator / 84.1% total, up from 84.5% / 84.0%.
132 new subtests in
emulator/kinesis_stream_arn_test.go, all over the wire per #765 and asserting the status and the code per #923. The assertions that distinguish a decoded ARN from a resolved one are the point: a stream namedordersexists in the caller's own account and Region in every case, so a resolver that read the name from the ARN and the account from the request context would answer200where these tests requireResourceNotFoundException. The cross-account and cross-Region positives create the two streams with different shard counts, so an assertion that the call merely succeeded cannot pass by accident.