Skip to content
Open
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 @@ -669,24 +669,7 @@
]
},
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":batch:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":job-definition/*"
]
]
"Ref": "JobDefinition24FFE3ED"
}
]
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,11 @@ export class BatchSubmitJob extends sfn.TaskStateBase {
}

private configurePolicyStatements(): iam.PolicyStatement[] {
const useWildcard = isJsonPathOrJsonataExpression(this.props.jobQueueArn) || isJsonPathOrJsonataExpression(this.props.jobDefinitionArn);
return [
// Resource level access control for job-definition requires revision which batch does not support yet
// Using the alternative permissions as mentioned here:
// https://docs.aws.amazon.com/batch/latest/userguide/batch-supported-iam-actions-resources.html
new iam.PolicyStatement({
resources: isJsonPathOrJsonataExpression(this.props.jobQueueArn) ? ['*'] : [
Stack.of(this).formatArn({
service: 'batch',
resource: 'job-definition',
resourceName: '*',
}),
resources: useWildcard ? ['*'] : [
this.props.jobDefinitionArn,
this.props.jobQueueArn,
],
actions: ['batch:SubmitJob'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import { Template } from '../../../assertions';
import { Match, Template } from '../../../assertions';
import * as batch from '../../../aws-batch';
import * as ec2 from '../../../aws-ec2';
import * as ecs from '../../../aws-ecs';
Expand Down Expand Up @@ -590,3 +590,29 @@ test('supports passing jobQueueArn as JsonPath or JSONata', () => {
},
});
});

test('scopes down permissions to specific job definition and queue ARNs', () => {
const task = new BatchSubmitJob(stack, 'ScopedTask', {
jobDefinitionArn: batchJobDefinition.jobDefinitionArn,
jobName: 'MyJob',
jobQueueArn: batchJobQueue.jobQueueArn,
});

new sfn.StateMachine(stack, 'SM2', {
definition: task,
});

Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: Match.arrayWith([
Match.objectLike({
Action: 'batch:SubmitJob',
Effect: 'Allow',
Resource: Match.arrayWith([
{ Ref: 'JobDefinition24FFE3ED' },
]),
}),
]),
},
});
});
Loading