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(iam): policy statement tries to validate tokens #13493

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-iam/lib/policy-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export class PolicyStatement {
constructor(props: PolicyStatementProps = {}) {
// Validate actions
for (const action of [...props.actions || [], ...props.notActions || []]) {
if (!/^(\*|[a-zA-Z0-9-]+:[a-zA-Z0-9*]+)$/.test(action)) {

if (!/^(\*|[a-zA-Z0-9-]+:[a-zA-Z0-9*]+)$/.test(action) && !cdk.Token.isUnresolved(action)) {
throw new Error(`Action '${action}' is invalid. An action string consists of a service namespace, a colon, and the name of an action. Action names can include wildcards.`);
}
}
Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-iam/test/policy-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ describe('IAM policy document', () => {
}).toThrow(/Action 'in:val:id' is invalid/);
});

// https://github.com/aws/aws-cdk/issues/13479
test('Does not validate unresolved tokens', () => {
const stack = new Stack();
const perm = new PolicyStatement({
actions: [`${Lazy.string({ produce: () => 'sqs:sendMessage' })}`],
});

expect(stack.resolve(perm.toStatementJson())).toEqual({
Effect: 'Allow',
Action: 'sqs:sendMessage',
});
});

test('Cannot combine Resources and NotResources', () => {
expect(() => {
new PolicyStatement({
Expand Down