Skip to content

Commit 7070ae5

Browse files
committed
fix(permissionsBoundary): apply permissionsBoundary
1 parent 5e81304 commit 7070ae5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/deploy/stepFunctions/compileIamRole.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ function getIamStatements(iamPermissions, stateMachineObj) {
563563
module.exports = {
564564
compileIamRole() {
565565
logger.config(this.serverless, this.v3Api);
566+
const service = this.serverless.service;
567+
const permissionsBoundary = service.provider.rolePermissionsBoundary;
566568
this.getAllStateMachines().forEach((stateMachineName) => {
567569
const stateMachineObj = this.getStateMachine(stateMachineName);
568570
if (stateMachineObj.role) {
@@ -601,10 +603,16 @@ module.exports = {
601603
'iam-role-statemachine-execution-template.txt'),
602604
);
603605

604-
const iamRoleJson = iamRoleStateMachineExecutionTemplate
606+
let iamRoleJson = iamRoleStateMachineExecutionTemplate
605607
.replace('[PolicyName]', this.getStateMachinePolicyName())
606608
.replace('[Statements]', JSON.stringify(iamStatements));
607609

610+
if (permissionsBoundary) {
611+
const jsonIamRole = JSON.parse(iamRoleJson);
612+
jsonIamRole.Properties.PermissionsBoundary = permissionsBoundary;
613+
iamRoleJson = JSON.stringify(jsonIamRole);
614+
}
615+
608616
const stateMachineLogicalId = this.getStateMachineLogicalId(
609617
stateMachineName,
610618
stateMachineObj,

lib/deploy/stepFunctions/compileNotifications.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,31 @@ describe('#compileNotifications', () => {
522522
expect(logMessage.startsWith('State machine [Beta1] : notifications are not supported on Express Workflows.'))
523523
.to.equal(true);
524524
});
525+
526+
it('should handle permissionsBoundary', () => {
527+
serverless.service.stepFunctions = {
528+
stateMachines: {
529+
myStateMachine1: {
530+
id: 'StateMachine1',
531+
definition: {
532+
StartAt: 'A',
533+
States: {
534+
A: {
535+
Type: 'Task',
536+
Resource:
537+
'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello',
538+
End: true,
539+
},
540+
},
541+
},
542+
},
543+
},
544+
};
545+
serverless.service.provider.rolePermissionsBoundary = 'arn:aws:iam::myAccount:policy/permission_boundary';
546+
serverlessStepFunctions.compileIamRole();
547+
const boundary = serverlessStepFunctions.serverless.service.provider
548+
.compiledCloudFormationTemplate.Resources.StateMachine1Role.Properties
549+
.PermissionsBoundary;
550+
expect(boundary).to.equal('arn:aws:iam::myAccount:policy/permission_boundary');
551+
});
525552
});

0 commit comments

Comments
 (0)