Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid S3 arn error thrown for valid format #1121

Open
FelixMarcus opened this issue Dec 20, 2023 · 1 comment
Open

Invalid S3 arn error thrown for valid format #1121

FelixMarcus opened this issue Dec 20, 2023 · 1 comment

Comments

@FelixMarcus
Copy link

What?

Smithy middleware-endpoint is unable to properly recognise an S3 bucket arn following the format:

arn:aws:s3:::bucket_name

...despite it being the the expected standard.

Instead, it will throw an error of Invalid ARN: ${bucketName} was an invalid ARN.

Expected Behaviour

S3 ARN values without an account id should be valid and thus not throw an error.

Where?

Tested on:

node@v18.19.0

Using:

  • @aws-sdk/client-s3@3.472.0
  • @aws-sdk/middleware-sdk-s3@3.470.0
  • @smithy/middleware-endpoint@2.2.3

Example

N.B. s3BucketExampleArn is passed in via cloudformation as an environment variable, and shows up correctly in the logs - matching an existing bucket in the accounts.

import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';

const input = {
      Body: JSON.stringify(payloads),
      Bucket: s3BucketExampleArn,
      Key: `example-key`,
    };
const command = new PutObjectCommand(input);
await this.s3Client.send(command);
/usr/src/app/node_modules/@smithy/middleware-endpoint/dist-cjs/service-customizations/s3.js:39
        throw new Error(`Invalid ARN: ${bucketName} was an invalid ARN.`);
              ^
Error: Invalid ARN: arn:aws:s3:::s3BucketExampleArn was an invalid ARN.
    at isArnBucketName (/usr/src/app/node_modules/@smithy/middleware-endpoint/dist-cjs/service-customizations/s3.js:39:15)
    at resolveParamsForS3 (/usr/src/app/node_modules/@smithy/middleware-endpoint/dist-cjs/service-customizations/s3.js:9:37)
    at resolveParams (/usr/src/app/node_modules/@smithy/middleware-endpoint/dist-cjs/adaptors/getEndpointFromInstructions.js:47:63)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getEndpointFromInstructions (/usr/src/app/node_modules/@smithy/middleware-endpoint/dist-cjs/adaptors/getEndpointFromInstructions.js:15:28)
    at async /usr/src/app/node_modules/@smithy/middleware-endpoint/dist-cjs/endpointMiddleware.js:9:26
    at async /usr/src/app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/region-redirect-endpoint-middleware.js:14:24
    at async /usr/src/app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/region-redirect-middleware.js:9:20
    at async /usr/src/app/node_modules/@aws-sdk/client-s3/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26
@bitIO
Copy link
Contributor

bitIO commented Apr 2, 2024

It seems this function

export const isArnBucketName = (bucketName: string): boolean => {
is not following the standard since it expects the account to be present even though arn:aws:s3:::my-bucket is a valid arn

bitIO added a commit to bitIO/smithy-typescript that referenced this issue Apr 3, 2024
As stated in this issue smithy-lang#1121 arn check should not check s3 arns contain nor account nor region since they are not part of s3 arns
kuhe added a commit that referenced this issue Apr 4, 2024
* fix(middleware-endpoint): check for s3 arn parts

As stated in this issue #1121 arn check should not check s3 arns contain nor account nor region since they are not part of s3 arns

* test(middleware-endpoint): add unit tests and fix backwards compatibility

---------

Co-authored-by: George Fu <kuhe@users.noreply.github.com>
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

No branches or pull requests

2 participants