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(stepfunctions): permission race condition on state machine deletion #5466

Merged
merged 6 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,11 @@
"Arn"
]
}
}
},
"DependsOn": [
"StateMachineRoleDefaultPolicyDF1E6607",
"StateMachineRoleB840431D"
]
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@
"Arn"
]
}
}
},
"DependsOn": [
"StateMachineRoleDefaultPolicyDF1E6607",
"StateMachineRoleB840431D"
]
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@
"Arn"
]
}
}
},
"DependsOn": [
"StateMachineRoleDefaultPolicyDF1E6607",
"StateMachineRoleB840431D"
]
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@
"Arn"
]
}
}
},
"DependsOn": [
"StateMachineRoleDefaultPolicyDF1E6607",
"StateMachineRoleB840431D"
]
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
"Arn"
]
}
}
},
"DependsOn": [
"StateMachineRoleB840431D"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@
"Arn"
]
}
}
},
"DependsOn": [
"StateMachineRoleDefaultPolicyDF1E6607",
"StateMachineRoleB840431D"
]
}
}
}
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class StateMachine extends StateMachineBase {
definitionString: Stack.of(this).toJsonString(graph.toGraphJson()),
});

resource.node.addDependency(this.role);

for (const statement of graph.policyStatements) {
this.addToRolePolicy(statement);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { expect, haveResource, ResourcePart } from '@aws-cdk/assert';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
Expand Down Expand Up @@ -250,6 +250,37 @@ export = {
});

test.done();
}
},

'State machines must depend on their roles'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const task = new stepfunctions.Task(stack, 'Task', {
task: {
bind: () => ({
resourceArn: 'resource',
policyStatements: [
new iam.PolicyStatement({
resources: ['resource'],
actions: ["lambda:InvokeFunction"],
})
],
})
}
});
new stepfunctions.StateMachine(stack, 'StateMachine', {
definition: task
});

// THEN
expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', {
DependsOn: [
'StateMachineRoleDefaultPolicyDF1E6607',
'StateMachineRoleB840431D'
]
}, ResourcePart.CompleteDefinition));

test.done();
},

};
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,11 @@
"Arn"
]
}
}
},
"DependsOn": [
"comamazonawscdkcustomresourcess3assertproviderwaiterstatemachineRoleDefaultPolicy9882AB39",
"comamazonawscdkcustomresourcess3assertproviderwaiterstatemachineRole39E8529F"
]
}
},
"Parameters": {
Expand Down