Skip to content

Commit 2e7d786

Browse files
committed
feat(stepfunctions-tasks): scope down batch:SubmitJob permissions to specific job definition
Previously, SubmitBatchJob granted batch:SubmitJob on all job definitions (job-definition/*). Now the permission is scoped to the specific job definition ARN with a wildcard revision suffix, following least privilege principles. When the job definition ARN is a dynamic expression (JsonPath/Jsonata), it falls back to the wildcard resource. Closes #37214
1 parent 08b9280 commit 2e7d786

File tree

1 file changed

+9
-8
lines changed
  • packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/batch

1 file changed

+9
-8
lines changed

packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/batch/submit-job.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,18 @@ export class BatchSubmitJob extends sfn.TaskStateBase {
307307
}
308308

309309
private configurePolicyStatements(): iam.PolicyStatement[] {
310+
const jobDefinitionResource = isJsonPathOrJsonataExpression(this.props.jobDefinitionArn)
311+
? Stack.of(this).formatArn({
312+
service: 'batch',
313+
resource: 'job-definition',
314+
resourceName: '*',
315+
})
316+
: `${this.props.jobDefinitionArn.replace(/:\d+$/, '')}:*`;
317+
310318
return [
311-
// Resource level access control for job-definition requires revision which batch does not support yet
312-
// Using the alternative permissions as mentioned here:
313-
// https://docs.aws.amazon.com/batch/latest/userguide/batch-supported-iam-actions-resources.html
314319
new iam.PolicyStatement({
315320
resources: isJsonPathOrJsonataExpression(this.props.jobQueueArn) ? ['*'] : [
316-
Stack.of(this).formatArn({
317-
service: 'batch',
318-
resource: 'job-definition',
319-
resourceName: '*',
320-
}),
321+
jobDefinitionResource,
321322
this.props.jobQueueArn,
322323
],
323324
actions: ['batch:SubmitJob'],

0 commit comments

Comments
 (0)