Skip to content

fix(kinesis): a stream can be named by its ARN (#966) - #998

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/kinesis-stream-arn
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/kinesis-stream-arn

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #966.

The defect

Fifteen of the seventeen Kinesis operations substrate models publish StreamARN beside StreamName, both Required: No, under a Note that is byte-identical on all fifteen pages:

When invoking this API, 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, and it is what an AWS SDK client constructed from an ARN sends, and what a CloudFormation Ref, 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:

Publishes StreamARN
Yes, with StreamName (14) DeleteStream, DescribeStream, DescribeStreamSummary, UpdateShardCount, MergeShards, SplitShard, PutRecord, PutRecords, GetShardIterator, AddTagsToStream, RemoveTagsFromStream, ListTagsForStream, EnableEnhancedMonitoring, DisableEnhancedMonitoring
Yes, with no StreamName (1) GetRecords — its stream is implied by the required ShardIterator
No (2) CreateStream (the service's one operation-wide Required: Yes StreamName; it mints an ARN rather than resolving one) and ListStreams (names no single stream, so it publishes neither member)

StreamId appears 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 *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. 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 its ListStreams index entry. A cross-account UpdateShardCount, MergeShards or AddTagsToStream therefore 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.

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 why GetRecords needs 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+:

  • a remaining / 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 on CreateStream either: applying it only here would make a stream substrate itself lets a caller create unaddressable by its own ARN;
  • an empty Region matches the pattern's .*, 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

A contradiction in AWS's own documentation, recorded rather than resolved

API_GetRecords publishes StreamARN and no StreamName — 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 StreamARN pattern, 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 is InternalFailureException, which substrate does not raise).

Compatibility

  • ResourceNotFoundException moves from HTTP 404 to 400 and ResourceInUseException from 409 to 400 at every Kinesis operation. A consumer branching on the status rather than the code saw something no Kinesis endpoint sends.
  • A missing stream reference answers InvalidArgumentException rather than InvalidParameterException at the fifteen operations that publish StreamARN. CreateStream's own guard is unchanged.
  • A StreamARN naming 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.
  • The tagging API refuses a malformed stream ARN it previously reported as absent — a non-twelve-digit account or a non-aws partition is now InvalidArgumentException.

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 named orders exists 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 answer 200 where these tests require ResourceNotFoundException. 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.

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.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e617c65 into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/kinesis-stream-arn branch September 17, 2026 07:38
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.

kinesis: no handler decodes StreamARN, so a caller holding a stream ARN cannot address the stream

1 participant