@@ -15,6 +15,7 @@ import (
1515 "github.com/aws/aws-sdk-go-v2/credentials"
1616 "github.com/aws/aws-sdk-go-v2/credentials/stscreds"
1717 "github.com/aws/aws-sdk-go-v2/service/sts"
18+ "github.com/aws/aws-sdk-go-v2/service/sts/types"
1819 "github.com/golang/mock/gomock"
1920 . "github.com/onsi/ginkgo/v2"
2021 . "github.com/onsi/gomega"
@@ -523,3 +524,167 @@ var _ = Describe("isIsolatedBackplaneAccess", func() {
523524 })
524525 })
525526})
527+
528+ var _ = Describe ("PolicyARNs Integration" , func () {
529+ var (
530+ testSessionPolicyArn string
531+ )
532+
533+ BeforeEach (func () {
534+ testSessionPolicyArn = "arn:aws:iam::123456789012:policy/TestSessionPolicy"
535+ })
536+
537+ Context ("when creating RoleArnSession with SessionPolicyArn" , func () {
538+ It ("should set PolicyARNs for customer roles" , func () {
539+ // Test the logic from common.go lines 327-337
540+ roleChainResponse := assumeChainResponse {
541+ AssumptionSequence : []namedRoleArn {
542+ {
543+ Name : CustomerRoleArnName ,
544+ Arn : "arn:aws:iam::123456789012:role/customer-role" ,
545+ },
546+ },
547+ CustomerRoleSessionName : "customer-session" ,
548+ SessionPolicyArn : testSessionPolicyArn ,
549+ }
550+
551+ // Simulate the logic from getIsolatedCredentials
552+ assumeRoleArnSessionSequence := make ([]awsutil.RoleArnSession , 0 , len (roleChainResponse .AssumptionSequence ))
553+ for _ , namedRoleArnEntry := range roleChainResponse .AssumptionSequence {
554+ roleArnSession := awsutil.RoleArnSession {RoleArn : namedRoleArnEntry .Arn }
555+ if namedRoleArnEntry .Name == CustomerRoleArnName || namedRoleArnEntry .Name == OrgRoleArnName {
556+ roleArnSession .RoleSessionName = roleChainResponse .CustomerRoleSessionName
557+ } else {
558+ roleArnSession .RoleSessionName = "test@example.com"
559+ }
560+
561+ // Default to no policy ARNs
562+ roleArnSession .PolicyARNs = []types.PolicyDescriptorType {}
563+ if namedRoleArnEntry .Name == CustomerRoleArnName {
564+ roleArnSession .IsCustomerRole = true
565+ // Add the session policy ARN for selected roles
566+ if roleChainResponse .SessionPolicyArn != "" {
567+ roleArnSession .PolicyARNs = []types.PolicyDescriptorType {
568+ {
569+ Arn : aws .String (roleChainResponse .SessionPolicyArn ),
570+ },
571+ }
572+ }
573+ } else {
574+ roleArnSession .IsCustomerRole = false
575+ }
576+ roleArnSession .Name = namedRoleArnEntry .Name
577+
578+ assumeRoleArnSessionSequence = append (assumeRoleArnSessionSequence , roleArnSession )
579+ }
580+
581+ Expect (len (assumeRoleArnSessionSequence )).To (Equal (1 ))
582+
583+ customerRole := assumeRoleArnSessionSequence [0 ]
584+ Expect (customerRole .IsCustomerRole ).To (BeTrue ())
585+ Expect (customerRole .Name ).To (Equal (CustomerRoleArnName ))
586+ Expect (len (customerRole .PolicyARNs )).To (Equal (1 ))
587+ Expect (* customerRole .PolicyARNs [0 ].Arn ).To (Equal (testSessionPolicyArn ))
588+ })
589+
590+ It ("should not set PolicyARNs for non-customer roles" , func () {
591+ roleChainResponse := assumeChainResponse {
592+ AssumptionSequence : []namedRoleArn {
593+ {
594+ Name : "Support-Role-Arn" ,
595+ Arn : "arn:aws:iam::123456789012:role/support-role" ,
596+ },
597+ },
598+ CustomerRoleSessionName : "customer-session" ,
599+ SessionPolicyArn : testSessionPolicyArn ,
600+ }
601+
602+ // Simulate the logic from getIsolatedCredentials
603+ assumeRoleArnSessionSequence := make ([]awsutil.RoleArnSession , 0 , len (roleChainResponse .AssumptionSequence ))
604+ for _ , namedRoleArnEntry := range roleChainResponse .AssumptionSequence {
605+ roleArnSession := awsutil.RoleArnSession {RoleArn : namedRoleArnEntry .Arn }
606+ if namedRoleArnEntry .Name == CustomerRoleArnName || namedRoleArnEntry .Name == OrgRoleArnName {
607+ roleArnSession .RoleSessionName = roleChainResponse .CustomerRoleSessionName
608+ } else {
609+ roleArnSession .RoleSessionName = "test@example.com"
610+ }
611+
612+ // Default to no policy ARNs
613+ roleArnSession .PolicyARNs = []types.PolicyDescriptorType {}
614+ if namedRoleArnEntry .Name == CustomerRoleArnName {
615+ roleArnSession .IsCustomerRole = true
616+ // Add the session policy ARN for selected roles
617+ if roleChainResponse .SessionPolicyArn != "" {
618+ roleArnSession .PolicyARNs = []types.PolicyDescriptorType {
619+ {
620+ Arn : aws .String (roleChainResponse .SessionPolicyArn ),
621+ },
622+ }
623+ }
624+ } else {
625+ roleArnSession .IsCustomerRole = false
626+ }
627+ roleArnSession .Name = namedRoleArnEntry .Name
628+
629+ assumeRoleArnSessionSequence = append (assumeRoleArnSessionSequence , roleArnSession )
630+ }
631+
632+ Expect (len (assumeRoleArnSessionSequence )).To (Equal (1 ))
633+
634+ supportRole := assumeRoleArnSessionSequence [0 ]
635+ Expect (supportRole .IsCustomerRole ).To (BeFalse ())
636+ Expect (supportRole .Name ).To (Equal ("Support-Role-Arn" ))
637+ Expect (len (supportRole .PolicyARNs )).To (Equal (0 ))
638+ })
639+
640+ It ("should handle empty SessionPolicyArn for customer roles" , func () {
641+ roleChainResponse := assumeChainResponse {
642+ AssumptionSequence : []namedRoleArn {
643+ {
644+ Name : CustomerRoleArnName ,
645+ Arn : "arn:aws:iam::123456789012:role/customer-role" ,
646+ },
647+ },
648+ CustomerRoleSessionName : "customer-session" ,
649+ SessionPolicyArn : "" , // Empty session policy ARN
650+ }
651+
652+ // Simulate the logic from getIsolatedCredentials
653+ assumeRoleArnSessionSequence := make ([]awsutil.RoleArnSession , 0 , len (roleChainResponse .AssumptionSequence ))
654+ for _ , namedRoleArnEntry := range roleChainResponse .AssumptionSequence {
655+ roleArnSession := awsutil.RoleArnSession {RoleArn : namedRoleArnEntry .Arn }
656+ if namedRoleArnEntry .Name == CustomerRoleArnName || namedRoleArnEntry .Name == OrgRoleArnName {
657+ roleArnSession .RoleSessionName = roleChainResponse .CustomerRoleSessionName
658+ } else {
659+ roleArnSession .RoleSessionName = "test@example.com"
660+ }
661+
662+ // Default to no policy ARNs
663+ roleArnSession .PolicyARNs = []types.PolicyDescriptorType {}
664+ if namedRoleArnEntry .Name == CustomerRoleArnName {
665+ roleArnSession .IsCustomerRole = true
666+ // Add the session policy ARN for selected roles
667+ if roleChainResponse .SessionPolicyArn != "" {
668+ roleArnSession .PolicyARNs = []types.PolicyDescriptorType {
669+ {
670+ Arn : aws .String (roleChainResponse .SessionPolicyArn ),
671+ },
672+ }
673+ }
674+ } else {
675+ roleArnSession .IsCustomerRole = false
676+ }
677+ roleArnSession .Name = namedRoleArnEntry .Name
678+
679+ assumeRoleArnSessionSequence = append (assumeRoleArnSessionSequence , roleArnSession )
680+ }
681+
682+ Expect (len (assumeRoleArnSessionSequence )).To (Equal (1 ))
683+
684+ customerRole := assumeRoleArnSessionSequence [0 ]
685+ Expect (customerRole .IsCustomerRole ).To (BeTrue ())
686+ Expect (customerRole .Name ).To (Equal (CustomerRoleArnName ))
687+ Expect (len (customerRole .PolicyARNs )).To (Equal (0 ))
688+ })
689+ })
690+ })
0 commit comments