@@ -45,6 +45,7 @@ const DEFAULT_INPUTS = {
4545 'aws-region' : FAKE_REGION ,
4646 'mask-aws-account-id' : 'TRUE'
4747} ;
48+ const DEFAULT_MULTILINE_INPUTS = { }
4849const ASSUME_ROLE_INPUTS = { ...CREDS_INPUTS , 'role-to-assume' : ROLE_ARN , 'aws-region' : FAKE_REGION } ;
4950
5051const mockStsCallerIdentity = jest . fn ( ) ;
@@ -90,6 +91,10 @@ describe('Configure AWS Credentials', () => {
9091 . fn ( )
9192 . mockImplementation ( mockGetInput ( DEFAULT_INPUTS ) ) ;
9293
94+ core . getMultilineInput = jest
95+ . fn ( )
96+ . mockImplementation ( mockGetInput ( DEFAULT_MULTILINE_INPUTS ) ) ;
97+
9398 core . getIDToken = jest
9499 . fn ( )
95100 . mockImplementation ( ( ) => {
@@ -624,6 +629,49 @@ describe('Configure AWS Credentials', () => {
624629 } )
625630 } ) ;
626631
632+ test ( 'Web identity token file with a inline session policy' , async ( ) => {
633+ const CUSTOM_SESSION_POLICY = "{ super_secure_policy }" ;
634+ core . getInput = jest
635+ . fn ( )
636+ . mockImplementation ( mockGetInput ( { 'role-to-assume' : ROLE_ARN , 'aws-region' : FAKE_REGION , 'web-identity-token-file' : '/fake/token/file' , 'inline-session-policy' : CUSTOM_SESSION_POLICY } ) ) ;
637+
638+ await run ( ) ;
639+ expect ( mockStsAssumeRoleWithWebIdentity ) . toHaveBeenCalledWith ( {
640+ RoleArn : 'arn:aws:iam::111111111111:role/MY-ROLE' ,
641+ RoleSessionName : 'GitHubActions' ,
642+ DurationSeconds : 6 * 3600 ,
643+ Policy : CUSTOM_SESSION_POLICY ,
644+ WebIdentityToken : 'testpayload'
645+ } )
646+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 1 , FAKE_ACCOUNT_ID ) ;
647+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 2 , FAKE_STS_ACCESS_KEY_ID ) ;
648+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_STS_SECRET_ACCESS_KEY ) ;
649+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 4 , FAKE_STS_SESSION_TOKEN ) ;
650+ } ) ;
651+
652+ test ( 'Web identity token file with a managed session policies' , async ( ) => {
653+ const MANAGED_SESSION_POLICIES = [ "arn:aws:iam::111111111111:policy/foo" , "arn:aws:iam::111111111111:policy/bar" ] ;
654+ core . getInput = jest
655+ . fn ( )
656+ . mockImplementation ( mockGetInput ( { 'role-to-assume' : ROLE_ARN , 'aws-region' : FAKE_REGION , 'web-identity-token-file' : '/fake/token/file' } ) ) ;
657+ core . getMultilineInput = jest
658+ . fn ( )
659+ . mockImplementation ( mockGetInput ( { 'managed-session-policies' : MANAGED_SESSION_POLICIES } ) )
660+
661+ await run ( ) ;
662+ expect ( mockStsAssumeRoleWithWebIdentity ) . toHaveBeenCalledWith ( {
663+ RoleArn : 'arn:aws:iam::111111111111:role/MY-ROLE' ,
664+ RoleSessionName : 'GitHubActions' ,
665+ DurationSeconds : 6 * 3600 ,
666+ PolicyArns : [ { arn : MANAGED_SESSION_POLICIES [ 0 ] } , { arn : MANAGED_SESSION_POLICIES [ 1 ] } ] ,
667+ WebIdentityToken : 'testpayload'
668+ } )
669+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 1 , FAKE_ACCOUNT_ID ) ;
670+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 2 , FAKE_STS_ACCESS_KEY_ID ) ;
671+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_STS_SECRET_ACCESS_KEY ) ;
672+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 4 , FAKE_STS_SESSION_TOKEN ) ;
673+ } ) ;
674+
627675 test ( 'only role arn and region provided to use GH OIDC Token' , async ( ) => {
628676 process . env . GITHUB_ACTIONS = 'true' ;
629677 process . env . ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token' ;
@@ -664,6 +712,51 @@ describe('Configure AWS Credentials', () => {
664712 expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_STS_SESSION_TOKEN ) ;
665713 } ) ;
666714
715+ test ( 'GH OIDC With inline session policy' , async ( ) => {
716+ const CUSTOM_SESSION_POLICY = "{ super_secure_policy }" ;
717+ process . env . GITHUB_ACTIONS = 'true' ;
718+ process . env . ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token' ;
719+ core . getInput = jest
720+ . fn ( )
721+ . mockImplementation ( mockGetInput ( { 'role-to-assume' : ROLE_ARN , 'aws-region' : FAKE_REGION , 'inline-session-policy' : CUSTOM_SESSION_POLICY } ) ) ;
722+
723+ await run ( ) ;
724+ expect ( mockStsAssumeRoleWithWebIdentity ) . toHaveBeenCalledWith ( {
725+ RoleArn : 'arn:aws:iam::111111111111:role/MY-ROLE' ,
726+ RoleSessionName : 'GitHubActions' ,
727+ DurationSeconds : 3600 ,
728+ Policy : CUSTOM_SESSION_POLICY ,
729+ WebIdentityToken : 'testtoken'
730+ } ) ;
731+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 1 , FAKE_STS_ACCESS_KEY_ID ) ;
732+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 2 , FAKE_STS_SECRET_ACCESS_KEY ) ;
733+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_STS_SESSION_TOKEN ) ;
734+ } ) ;
735+
736+ test ( 'GH OIDC With managed session policy' , async ( ) => {
737+ const MANAGED_SESSION_POLICIES = [ "arn:aws:iam::111111111111:policy/foo" , "arn:aws:iam::111111111111:policy/bar" ] ;
738+ process . env . GITHUB_ACTIONS = 'true' ;
739+ process . env . ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token' ;
740+ core . getInput = jest
741+ . fn ( )
742+ . mockImplementation ( mockGetInput ( { 'role-to-assume' : ROLE_ARN , 'aws-region' : FAKE_REGION } ) ) ;
743+ core . getMultilineInput = jest
744+ . fn ( )
745+ . mockImplementation ( mockGetInput ( { 'managed-session-policies' : MANAGED_SESSION_POLICIES } ) )
746+
747+ await run ( ) ;
748+ expect ( mockStsAssumeRoleWithWebIdentity ) . toHaveBeenCalledWith ( {
749+ RoleArn : 'arn:aws:iam::111111111111:role/MY-ROLE' ,
750+ RoleSessionName : 'GitHubActions' ,
751+ DurationSeconds : 3600 ,
752+ PolicyArns : [ { arn : MANAGED_SESSION_POLICIES [ 0 ] } , { arn : MANAGED_SESSION_POLICIES [ 1 ] } ] ,
753+ WebIdentityToken : 'testtoken'
754+ } ) ;
755+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 1 , FAKE_STS_ACCESS_KEY_ID ) ;
756+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 2 , FAKE_STS_SECRET_ACCESS_KEY ) ;
757+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_STS_SESSION_TOKEN ) ;
758+ } ) ;
759+
667760 test ( 'role assumption fails after maximun trials using OIDC Provider' , async ( ) => {
668761 process . env . GITHUB_ACTIONS = 'true' ;
669762 process . env . ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token' ;
@@ -704,6 +797,57 @@ describe('Configure AWS Credentials', () => {
704797 } )
705798 } ) ;
706799
800+ test ( 'inline session policy provided' , async ( ) => {
801+ const CUSTOM_SESSION_POLICY = "{ super_secure_policy }" ;
802+ core . getInput = jest
803+ . fn ( )
804+ . mockImplementation ( mockGetInput ( { ...ASSUME_ROLE_INPUTS , 'inline-session-policy' : CUSTOM_SESSION_POLICY } ) ) ;
805+
806+ await run ( ) ;
807+ expect ( mockStsAssumeRole ) . toHaveBeenCalledWith ( {
808+ RoleArn : ROLE_ARN ,
809+ RoleSessionName : 'GitHubActions' ,
810+ DurationSeconds : 6 * 3600 ,
811+ Tags : [
812+ { Key : 'GitHub' , Value : 'Actions' } ,
813+ { Key : 'Repository' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_REPOSITORY } ,
814+ { Key : 'Workflow' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_WORKFLOW } ,
815+ { Key : 'Action' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_ACTION } ,
816+ { Key : 'Actor' , Value : GITHUB_ACTOR_SANITIZED } ,
817+ { Key : 'Commit' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_SHA } ,
818+ { Key : 'Branch' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_REF } ,
819+ ] ,
820+ Policy : CUSTOM_SESSION_POLICY
821+ } )
822+ } ) ;
823+
824+ test ( 'managed session policy provided' , async ( ) => {
825+ const MANAGED_SESSION_POLICIES = [ "arn:aws:iam::111111111111:policy/foo" , "arn:aws:iam::111111111111:policy/bar" ] ;
826+ core . getInput = jest
827+ . fn ( )
828+ . mockImplementation ( mockGetInput ( { ...ASSUME_ROLE_INPUTS } ) ) ;
829+ core . getMultilineInput = jest
830+ . fn ( )
831+ . mockImplementation ( mockGetInput ( { 'managed-session-policies' : MANAGED_SESSION_POLICIES } ) )
832+
833+ await run ( ) ;
834+ expect ( mockStsAssumeRole ) . toHaveBeenCalledWith ( {
835+ RoleArn : ROLE_ARN ,
836+ RoleSessionName : 'GitHubActions' ,
837+ DurationSeconds : 6 * 3600 ,
838+ Tags : [
839+ { Key : 'GitHub' , Value : 'Actions' } ,
840+ { Key : 'Repository' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_REPOSITORY } ,
841+ { Key : 'Workflow' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_WORKFLOW } ,
842+ { Key : 'Action' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_ACTION } ,
843+ { Key : 'Actor' , Value : GITHUB_ACTOR_SANITIZED } ,
844+ { Key : 'Commit' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_SHA } ,
845+ { Key : 'Branch' , Value : ENVIRONMENT_VARIABLE_OVERRIDES . GITHUB_REF } ,
846+ ] ,
847+ PolicyArns : [ { arn : MANAGED_SESSION_POLICIES [ 0 ] } , { arn : MANAGED_SESSION_POLICIES [ 1 ] } ] ,
848+ } )
849+ } ) ;
850+
707851 test ( 'workflow name sanitized in role assumption tags' , async ( ) => {
708852 core . getInput = jest
709853 . fn ( )
0 commit comments