File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -588,6 +588,25 @@ function getS3ObjectPermissions(action, state) {
588588 const prefix = state . Parameters . Prefix ;
589589 let arn ;
590590
591+ if ( action === 's3:listObjectsV2' ) {
592+ return [
593+ {
594+ action : 's3:Get*' ,
595+ resource : [
596+ `arn:aws:s3:::${ bucket } ` ,
597+ `arn:aws:s3:::${ bucket } /*` ,
598+ ] ,
599+ } ,
600+ {
601+ action : 's3:List*' ,
602+ resource : [
603+ `arn:aws:s3:::${ bucket } ` ,
604+ `arn:aws:s3:::${ bucket } /*` ,
605+ ] ,
606+ } ,
607+ ] ;
608+ }
609+
591610 if ( prefix ) {
592611 arn = `arn:aws:s3:::${ bucket } /${ prefix } /${ key } ` ;
593612 } else if ( bucket === '*' && key === '*' ) {
@@ -737,6 +756,9 @@ function getIamPermissions(taskStates) {
737756 case 'arn:aws:states:::s3:putObject' :
738757 case 'arn:aws:states:::aws-sdk:s3:putObject' :
739758 return getS3ObjectPermissions ( 's3:PutObject' , state ) ;
759+ case 'arn:aws:states:::s3:listObjectsV2' :
760+ case 'arn:aws:states:::aws-sdk:s3:listObjectsV2' :
761+ return getS3ObjectPermissions ( 's3:listObjectsV2' , state ) ;
740762
741763 default :
742764 if ( isIntrinsic ( state . Resource ) || ! ! state . Resource . match ( / a r n : a w s ( - [ a - z ] + ) * : l a m b d a / ) ) {
Original file line number Diff line number Diff line change @@ -3804,4 +3804,57 @@ describe('#compileIamRole', () => {
38043804 . PermissionsBoundary ;
38053805 expect ( boundary ) . to . equal ( 'arn:aws:iam::myAccount:policy/permission_boundary' ) ;
38063806 } ) ;
3807+
3808+
3809+ it ( 'should handle permissions listObjectsV2' , ( ) => {
3810+ const myBucket = 'myBucket' ;
3811+ serverless . service . stepFunctions = {
3812+ stateMachines : {
3813+ myStateMachine1 : {
3814+ id : 'StateMachine1' ,
3815+ definition : {
3816+ StartAt : 'A' ,
3817+ States : {
3818+ A : {
3819+ Type : 'Map' ,
3820+ ItemProcessor : {
3821+ ProcessorConfig : {
3822+ Mode : 'DISTRIBUTED' ,
3823+ } ,
3824+ } ,
3825+ StartAt : 'B' ,
3826+ States : {
3827+ B : {
3828+ Type : 'Task' ,
3829+ Resource : 'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello' ,
3830+ End : true ,
3831+ } ,
3832+ } ,
3833+ ItemReader : {
3834+ Resource : 'arn:aws:states:::s3:listObjectsV2' ,
3835+ Parameters : {
3836+ Bucket : myBucket ,
3837+ Prefix : 'hello' ,
3838+ } ,
3839+ } ,
3840+ End : true ,
3841+ } ,
3842+ } ,
3843+ } ,
3844+ } ,
3845+ } ,
3846+ } ;
3847+
3848+ serverlessStepFunctions . compileIamRole ( ) ;
3849+ const statements = serverlessStepFunctions . serverless . service . provider
3850+ . compiledCloudFormationTemplate . Resources . StateMachine1Role . Properties . Policies [ 0 ]
3851+ . PolicyDocument . Statement ;
3852+
3853+ expect ( statements ) . to . have . lengthOf ( 4 ) ;
3854+ expect ( statements [ 3 ] . Effect ) . to . equal ( 'Allow' ) ;
3855+ expect ( statements [ 3 ] . Action [ 0 ] ) . to . equal ( 's3:Get*' ) ;
3856+ expect ( statements [ 3 ] . Action [ 1 ] ) . to . equal ( 's3:List*' ) ;
3857+ expect ( statements [ 3 ] . Resource [ 0 ] ) . to . equal ( `arn:aws:s3:::${ myBucket } ` ) ;
3858+ expect ( statements [ 3 ] . Resource [ 1 ] ) . to . equal ( `arn:aws:s3:::${ myBucket } /*` ) ;
3859+ } ) ;
38073860} ) ;
You can’t perform that action at this time.
0 commit comments