-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
stepfunctions: ItemReader and ResultWriter do not grant KMS permissions #32144
Comments
Hi @BadMagic100 , thanks for reaching out. I tried to repro the scenario and it succeeded with synthesizing policies as well as deployment. Sharing the code as well as template snippet for your reference - const inputBucket = new Bucket(this,'DistributedMapInputBucket', {
encryption: BucketEncryption.KMS,
enforceSSL: true
});
const outputBucket = new Bucket(this, 'DistributedMapOutputBucket', {
encryption: BucketEncryption.KMS,
enforceSSL: true
});
const stateMachineObj = new StateMachine(this, 'Test', {
definitionBody: DefinitionBody.fromChainable(new DistributedMap(this, 'Map', {
itemReader: new S3JsonItemReader({
bucket: inputBucket,
key: "some-object"
}),
resultWriter: new ResultWriter({
bucket: outputBucket,
prefix: "some-prefix"
}),
}).itemProcessor(new Pass(this, 'pass')))
});
new CfnOutput(this, 'InputBucketName', { value: inputBucket.bucketName });
new CfnOutput(this, 'OutputBucketName', { value: stateMachineObj.stateMachineArn }); Synthesized template for Policy - "TestRoleDefaultPolicyAD214F97": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:AbortMultipartUpload",
"s3:GetObject",
"s3:ListMultipartUploadParts",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":s3:::",
{
"Ref": "DistributedMapOutputBucket1136E660"
},
"/*"
]
]
}
},
{
"Action": "s3:GetObject",
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":s3:::",
{
"Ref": "DistributedMapInputBucketFDAB2D5D"
},
"/*"
]
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "TestRoleDefaultPolicyAD214F97",
"Roles": [
{
"Ref": "TestRole17AB2208"
}
]
},
"Metadata": {
"aws:cdk:path": "StepfunctionIssueStack/Test/Role/DefaultPolicy/Resource"
}
},
"Test7BFAF513": {
"Type": "AWS::StepFunctions::StateMachine",
"Properties": {
"DefinitionString": {
"Fn::Join": [
"",
[
"{\"StartAt\":\"Map\",\"States\":{\"Map\":{\"Type\":\"Map\",\"End\":true,\"ItemProcessor\":{\"ProcessorConfig\":{\"Mode\":\"DISTRIBUTED\",\"ExecutionType\":\"STANDARD\"},\"StartAt\":\"pass\",\"States\":{\"pass\":{\"Type\":\"Pass\",\"End\":true}}},\"ItemReader\":{\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
":states:::s3:getObject\",\"ReaderConfig\":{\"InputType\":\"JSON\"},\"Parameters\":{\"Bucket\":\"",
{
"Ref": "DistributedMapInputBucketFDAB2D5D"
},
"\",\"Key\":\"some-object\"}},\"ResultWriter\":{\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
":states:::s3:putObject\",\"Parameters\":{\"Bucket\":\"",
{
"Ref": "DistributedMapOutputBucket1136E660"
},
"\",\"Prefix\":\"some-prefix\"}}}}}"
]
]
},
"RoleArn": {
"Fn::GetAtt": [
"TestRole17AB2208",
"Arn"
]
}
},
"DependsOn": [
"TestRoleDefaultPolicyAD214F97",
"TestRole17AB2208"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete",
"Metadata": {
"aws:cdk:path": "StepfunctionIssueStack/Test/Resource"
}
}, In statemachine above, the ItemReader and ResultWrite have the required permissions needed to access the bucket. Deployment also succeeds without error - I assume this is what you are looking for. Let me know if this does not help or your usecase and ask is different |
Yes, this repro is right and you are correct that it can synthesize and deploy. What you will find is if you try to execute the step function it will fail because the buckets are encrypted and the step function execution role cannot read/write from them. The permissions for For now I am using a workaround like below to get the correct policies. inputBucket.encryptionKey?.grant(stateMachineObj, 'kms:DescribeKey');
inputBucket.encryptionKey?.grantEncrypt(stateMachineObj);
outputBucket.encryptionKey?.grantEncryptDecrypt(ststeMachineObj); |
Describe the bug
Generally, states added to a state machine will grant all necessary policy permissions to the execution role of the state machine. When using the
DistributedMap
construct, however, the necessary permissions for working with encrypted buckets are left out.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
The step function should grant necessary KMS permissions on its returned policies.
Current Behavior
The step function does not grant necessary KMS permissions on its returned policies. Example error:
Reproduction Steps
Possible Solution
ResultWriter and ItemReader should add key read/write actions to their
providePolicyStatements
(both linked), similar toBucket.grantRead
andBucket.grantWrite
hereAdditional Information/Context
No response
CDK CLI Version
2.164.1
Framework Version
No response
Node.js Version
18
OS
macOS
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: