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

fix(core): parsing an ARN with a slash after a colon in the resource part fails #15166

Merged
merged 2 commits into from
Jun 21, 2021

Conversation

skinny85
Copy link
Contributor

@skinny85 skinny85 commented Jun 17, 2021

New-style ARNs are of the form 'arn:aws:s4:us-west-1:12345:/resource-type/resource-name'.
We didn't handle that correctly in parseArn(), and instead returned an undefined resource,
which funnily enough should never happen according to our types.
Introduce the concept of ARN formats,
represented by an enum in core,
and replace the Stack.parseArn() method by a new one Stack.splitArn(),
taking that enum as a required second argument.

Spotted in https://github.com/aws/aws-cdk/pull/15140/files#r653112073


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@skinny85 skinny85 requested a review from rix0rrr June 17, 2021 00:57
@skinny85 skinny85 self-assigned this Jun 17, 2021
@gitpod-io
Copy link

gitpod-io bot commented Jun 17, 2021

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  • ARNs need to be roundtrippable: we need to be able to formatArn() the information we got out of parseArn() and get the same ARN back. We might need to add modernArn: boolean to ArnComponents or something (or maybe typeSep = ':' | ':/').
  • We need parseArnIfToken() to produce CloudFormation expressions which, when evaluated, would produce the same value as parseArn() would do on a literal string.

For the latter, given eval-cfn.ts we could probably have each test exercise both forms of parsing, so that might be a worthwhile thing to add: https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/core/test/evaluate-cfn.ts/#L8

@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 17, 2021

The double test would look somewhat like:

function assertArnParsesProperlyTo(arn: string, expectedComponents: ArnComponents, parseOptions: ...) {
  const components = stack.parseArn(arn);
  expect(components).toEqual(expectedComponents);

  const tokenExprs = stack.parseArn(new Intrinsic({ Ref: TheArn }), ...parseOptions);
  const tokenComponents = evaluateCFN(tokenExprs, { TheArn: arn });
  expect(tokenComponents).toEqual(expectedComponents);
}

(or something)

@skinny85 skinny85 force-pushed the fix/arn-parse-slash-after-colon branch from a018778 to d20c24b Compare June 18, 2021 01:55
@skinny85
Copy link
Contributor Author

@rix0rrr included your comments. Please take another look!

@skinny85 skinny85 requested a review from rix0rrr June 18, 2021 01:56
@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Jun 18, 2021
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provisional approval provided you come up with a good name for the new parameter :)

packages/@aws-cdk/core/test/arn.test.ts Show resolved Hide resolved
packages/@aws-cdk/core/test/arn.test.ts Show resolved Hide resolved
packages/@aws-cdk/core/test/arn.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/arn.ts Outdated Show resolved Hide resolved
@skinny85 skinny85 force-pushed the fix/arn-parse-slash-after-colon branch 2 times, most recently from c23413e to e6da9af Compare June 18, 2021 23:14
Comment on lines +198 to +204
'arn:aws:s3:::my_corporate_bucket/object.zip': {
partition: 'aws',
service: 's3',
region: '',
account: '',
resource: 'my_corporate_bucket/object.zip',
arnFormat: ArnFormat.NO_RESOURCE_NAME,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the most interesting test case. I can be convinced that it should return arnFormat : ArnFormat.SLASH_RESOURCE_NAME, resource: 'my_corporate_bucket', sep: '/', and resourceName: 'object.zip' instead of what it's returning right now.

Copy link
Contributor

@rix0rrr rix0rrr Jun 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current interpretation is correct.

arn:aws:s3:::my_corporate_bucket/object.zip is really addressing a file in a bucket, with a fully qualified name. It makes sense that my_corporate_bucket/object.zip is the value of resource.

What I personally don't like is that resource varyingly means the TYPE of the resource, or the NAME of the resource itself (depending on ARN format), but... c'est la vie, not something we can reasonably change anymore...

@skinny85
Copy link
Contributor Author

@rix0rrr I've decided to go with the option of introducing the ArnFormat concept. I'm really happy with how it turned out - I think the API of parsing ARNs is now much cleaner than it was before.

Let me know what you think!

@skinny85 skinny85 requested a review from rix0rrr June 18, 2021 23:25
…part fails

New-style ARNs are of the form 'arn:aws:s4:us-west-1:12345:/resource-type/resource-name'.
We didn't handle that correctly in parseArn(), and instead returned an `undefined` resource,
which funnily enough should never happen according to our types.

Introduce the concept of ARN formats,
represented by an enum in core,
and replace the `Stack.parseArn()` method by a new one `Stack.splitArn()`,
taking that enum as a required second argument.

Spotted in https://github.com/aws/aws-cdk/pull/15140/files#r653112073
@skinny85 skinny85 force-pushed the fix/arn-parse-slash-after-colon branch from e6da9af to d3c1ce0 Compare June 21, 2021 19:36
@skinny85 skinny85 removed the pr/do-not-merge This PR should not be merged at this time. label Jun 21, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 21, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: e37d4dc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@skinny85
Copy link
Contributor Author

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Jun 21, 2021

Command refresh: success

Pull request refreshed

@mergify mergify bot merged commit 16b8a4e into aws:master Jun 21, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 21, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@skinny85 skinny85 deleted the fix/arn-parse-slash-after-colon branch June 21, 2021 21:21
Seiya6329 pushed a commit to Seiya6329/aws-cdk that referenced this pull request Jun 22, 2021
…part fails (aws#15166)

New-style ARNs are of the form `'arn:aws:s4:us-west-1:12345:/resource-type/resource-name'`.
We didn't handle that correctly in `parseArn()`, and instead returned an `undefined` resource,
which funnily enough should never happen according to our types.
Introduce the concept of ARN formats,
represented by an enum in core,
and replace the `Stack.parseArn()` method by a new one `Stack.splitArn()`,
taking that enum as a required second argument.

Spotted in https://github.com/aws/aws-cdk/pull/15140/files#r653112073

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
matthewsvu pushed a commit to matthewsvu/aws-cdk that referenced this pull request Jun 22, 2021
…part fails (aws#15166)

New-style ARNs are of the form `'arn:aws:s4:us-west-1:12345:/resource-type/resource-name'`.
We didn't handle that correctly in `parseArn()`, and instead returned an `undefined` resource,
which funnily enough should never happen according to our types.
Introduce the concept of ARN formats,
represented by an enum in core,
and replace the `Stack.parseArn()` method by a new one `Stack.splitArn()`,
taking that enum as a required second argument.

Spotted in https://github.com/aws/aws-cdk/pull/15140/files#r653112073

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…part fails (aws#15166)

New-style ARNs are of the form `'arn:aws:s4:us-west-1:12345:/resource-type/resource-name'`.
We didn't handle that correctly in `parseArn()`, and instead returned an `undefined` resource,
which funnily enough should never happen according to our types.
Introduce the concept of ARN formats,
represented by an enum in core,
and replace the `Stack.parseArn()` method by a new one `Stack.splitArn()`,
taking that enum as a required second argument.

Spotted in https://github.com/aws/aws-cdk/pull/15140/files#r653112073

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants