@@ -45,6 +45,7 @@ const DEFAULT_INPUTS = {
45
45
'aws-region' : FAKE_REGION ,
46
46
'mask-aws-account-id' : 'TRUE'
47
47
} ;
48
+ const DEFAULT_MULTILINE_INPUTS = { }
48
49
const ASSUME_ROLE_INPUTS = { ...CREDS_INPUTS , 'role-to-assume' : ROLE_ARN , 'aws-region' : FAKE_REGION } ;
49
50
50
51
const mockStsCallerIdentity = jest . fn ( ) ;
@@ -90,6 +91,10 @@ describe('Configure AWS Credentials', () => {
90
91
. fn ( )
91
92
. mockImplementation ( mockGetInput ( DEFAULT_INPUTS ) ) ;
92
93
94
+ core . getMultilineInput = jest
95
+ . fn ( )
96
+ . mockImplementation ( mockGetInput ( DEFAULT_MULTILINE_INPUTS ) ) ;
97
+
93
98
core . getIDToken = jest
94
99
. fn ( )
95
100
. mockImplementation ( ( ) => {
@@ -624,6 +629,49 @@ describe('Configure AWS Credentials', () => {
624
629
} )
625
630
} ) ;
626
631
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
+
627
675
test ( 'only role arn and region provided to use GH OIDC Token' , async ( ) => {
628
676
process . env . GITHUB_ACTIONS = 'true' ;
629
677
process . env . ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token' ;
@@ -664,6 +712,51 @@ describe('Configure AWS Credentials', () => {
664
712
expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_STS_SESSION_TOKEN ) ;
665
713
} ) ;
666
714
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
+
667
760
test ( 'role assumption fails after maximun trials using OIDC Provider' , async ( ) => {
668
761
process . env . GITHUB_ACTIONS = 'true' ;
669
762
process . env . ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token' ;
@@ -704,6 +797,57 @@ describe('Configure AWS Credentials', () => {
704
797
} )
705
798
} ) ;
706
799
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
+
707
851
test ( 'workflow name sanitized in role assumption tags' , async ( ) => {
708
852
core . getInput = jest
709
853
. fn ( )
0 commit comments