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

aws-cdk: bootstrapping fails due to permissions boundary name not matching the IAM conventions #26320

Closed
przemolb opened this issue Jul 11, 2023 · 8 comments · Fixed by #26378
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@przemolb
Copy link

Describe the bug

cdk bootstrap command doesn't accept IAM policy names with forward slash (/) in it.

Expected Behavior

cdk should accept IAM name with forward slashes in its name

Current Behavior

When I try to run cdk bootstrap command with permissions boundry with forward slash in its name, cdk fails:

cdk bootstrap --custom-permissions-boundary aaa/bbb
Boostrapping environment ...
Trusted accounts deployment ...
Trusted accounts for lookup ...
Using default execution policy of ...

Environment .... failed bootstrapping: Error: The permissions boundary name aaa/bbb does not match the IAM conventions.
   ...
   ...
   at sync exec4 (...node_modules/aws-cdk/lib/index.js:490:52657)

Reproduction Steps

The error and code I refer to runs on companys laptop and I cannot copy/paste full message here.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.87.0

Framework Version

No response

Node.js Version

v18.12.1

OS

MacOS

Language

Go

Language Version

1.20.1

Other information

No response

@przemolb przemolb added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2023
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label Jul 11, 2023
@peterwoodworth
Copy link
Contributor

How do you have an IAM policy name with a slash in it?
Screenshot 2023-07-11 at 11 49 20 AM

The regex we use is the same as described in the linked documentation

private validatePolicyName(permissionsBoundary: string) {
// https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreatePolicy.html
const regexp: RegExp = /[\w+=,.@-]+/;
const matches = regexp.exec(permissionsBoundary);
if (!(matches && matches.length === 1 && matches[0] === permissionsBoundary)) {
throw new Error(`The permissions boundary name ${permissionsBoundary} does not match the IAM conventions.`);
}
}

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2023
@peterwoodworth
Copy link
Contributor

If you have slashes, that's probably part of the optional path. You want to supply the friendly name, which is what would appear after the path.

@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jul 11, 2023
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Jul 11, 2023

Hmm the place this value ends up is here

- Fn::Sub: 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/${InputPermissionsBoundary}'

If a policy has a path, is that path required when specifying the arn? The documentation is unclear to me, though specifying the path obviously doesn't hurt.

Fixing this to accept paths should probably only consist of updating the regex linked above, and adding/updating tests - feel free to check out our contributing guide if you'd like to help out 🙂

@przemolb
Copy link
Author

przemolb commented Jul 11, 2023

feel free to check out our [contributing guide](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)
if you'd like to help out slightly_smiling_face

I'd love to but unfortunately my contract doesn't allow me to contribute. 😞
Sad but true.

@przemolb
Copy link
Author

przemolb commented Jul 12, 2023

In this particular code:

  - Fn::Sub: 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/${InputPermissionsBoundary}'

what we need to put into ${InputPermissionsBoundary} is, i.e.,

sth/sthelse/anotherthing/anotherthing2/blahblah

(of course, the number of forward slashes can vary)

@przemolb
Copy link
Author

przemolb commented Jul 19, 2023

@peterwoodworth
Once this PR has succesfully passed all the tests, what is the approximate timeline to get this released and available to everyone?

@peterwoodworth
Copy link
Contributor

We usually release once a week or so, so once this is merged it will probably take a week at most

mrgrain added a commit to lpizzinidev/aws-cdk that referenced this issue Jul 21, 2023
mrgrain added a commit to lpizzinidev/aws-cdk that referenced this issue Jul 21, 2023
mergify bot added a commit to lpizzinidev/aws-cdk that referenced this issue Jul 21, 2023
@mergify mergify bot closed this as completed in #26378 Jul 21, 2023
mergify bot pushed a commit that referenced this issue Jul 21, 2023
Policy names with slashes (`/`) are not allowed when bootstrapping.

For example:
```
cdk bootstrap --custom-permissions-boundary aaa/bbb
```
Would fail:
```
Error: The permissions boundary name aaa/bbb does not match the IAM conventions.
```

This fix allows to specify paths in the policy name.

Closes #26320.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

bmoffatt pushed a commit to bmoffatt/aws-cdk that referenced this issue Jul 29, 2023
Policy names with slashes (`/`) are not allowed when bootstrapping.

For example:
```
cdk bootstrap --custom-permissions-boundary aaa/bbb
```
Would fail:
```
Error: The permissions boundary name aaa/bbb does not match the IAM conventions.
```

This fix allows to specify paths in the policy name.

Closes aws#26320.

----

*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
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants