Skip to content

Commit c8add30

Browse files
author
Mike Morris
committed
Validate SAML parameters before doing AssumeRoleWithSAML
Check that we have something resembling a value in the SAMLAssertion and PrincipalARN before making the AssumeRole call. We'll leave the data validation to AWS, but make sure we provide a more helpful error message in case these values aren't set.
1 parent 124e360 commit c8add30

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/credentials/saml_role_credentials.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package credentials
33
import (
44
"aws-runas/lib/cache"
55
"encoding/base64"
6+
"fmt"
67
"github.com/aws/aws-sdk-go/aws/client"
78
"github.com/aws/aws-sdk-go/aws/credentials"
89
"github.com/aws/aws-sdk-go/service/sts"
@@ -84,6 +85,14 @@ func (p *SamlRoleProvider) retrieve() (*cache.CacheableCredentials, error) {
8485
p.Duration = AssumeRoleDefaultDuration
8586
}
8687

88+
if len(p.SAMLAssertion) < 20 {
89+
return nil, fmt.Errorf("invalid SAML Assertion detected, check your local SAML and identity provider configuration")
90+
}
91+
92+
if len(p.principalArn) < 20 {
93+
return nil, fmt.Errorf("invalid Principal ARN, check that your configured role ARN matches the identity provider configuration")
94+
}
95+
8796
i := new(sts.AssumeRoleWithSAMLInput).SetDurationSeconds(p.validateDuration(p.Duration)).SetRoleArn(p.RoleARN).
8897
SetPrincipalArn(p.principalArn).SetSAMLAssertion(p.SAMLAssertion)
8998

0 commit comments

Comments
 (0)