Skip to content

Commit 8d592ea

Browse files
authored
fix(iam): policy statement tries to validate tokens (#13493)
Looking for guidance on error messaging and/or docs to update Fixes #13479 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e635dac commit 8d592ea

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/@aws-cdk/aws-iam/lib/policy-statement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export class PolicyStatement {
6464
constructor(props: PolicyStatementProps = {}) {
6565
// Validate actions
6666
for (const action of [...props.actions || [], ...props.notActions || []]) {
67-
if (!/^(\*|[a-zA-Z0-9-]+:[a-zA-Z0-9*]+)$/.test(action)) {
67+
68+
if (!/^(\*|[a-zA-Z0-9-]+:[a-zA-Z0-9*]+)$/.test(action) && !cdk.Token.isUnresolved(action)) {
6869
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.`);
6970
}
7071
}

packages/@aws-cdk/aws-iam/test/policy-document.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ describe('IAM policy document', () => {
102102
}).toThrow(/Action 'in:val:id' is invalid/);
103103
});
104104

105+
// https://github.com/aws/aws-cdk/issues/13479
106+
test('Does not validate unresolved tokens', () => {
107+
const stack = new Stack();
108+
const perm = new PolicyStatement({
109+
actions: [`${Lazy.string({ produce: () => 'sqs:sendMessage' })}`],
110+
});
111+
112+
expect(stack.resolve(perm.toStatementJson())).toEqual({
113+
Effect: 'Allow',
114+
Action: 'sqs:sendMessage',
115+
});
116+
});
117+
105118
test('Cannot combine Resources and NotResources', () => {
106119
expect(() => {
107120
new PolicyStatement({

0 commit comments

Comments
 (0)