Skip to content

Commit e117ae6

Browse files
committed
oidc: ignore default AWS config
This commit makes the aws-cli-oidc tool ignore all the default AWS configurations like env vars, credential files, and config files. This fixes a circular dependency where the OIDC tool tries to analyze the profile configrations which in turn rely on an already executed (aws-cli-oidc) credential process.
1 parent 9495e9b commit e117ae6

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

internal/aws_oidc.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package internal
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"log"
78
"os"
89
"strings"
910
"time"
1011

11-
"github.com/aws/aws-sdk-go/aws"
12-
"github.com/aws/aws-sdk-go/aws/session"
13-
"github.com/aws/aws-sdk-go/service/sts"
12+
"github.com/aws/aws-sdk-go-v2/aws"
13+
"github.com/aws/aws-sdk-go-v2/aws/defaults"
14+
"github.com/aws/aws-sdk-go-v2/service/sts"
1415
)
1516

1617
const expiryDelta = 10 * time.Second
@@ -68,13 +69,6 @@ func GetCredentialsWithOIDC(client *OIDCClient, idToken string, roleARN string,
6869
}
6970

7071
func assumeRoleWithWebIdentity(client *OIDCClient, idToken string, roleARN string, durationSeconds int64) (*AWSCredentials, error) {
71-
sess, err := session.NewSession()
72-
if err != nil {
73-
return nil, fmt.Errorf("failed to create session: %v", err)
74-
}
75-
76-
svc := sts.New(sess)
77-
7872
username := os.Getenv("USER")
7973
split := strings.SplitN(roleARN, "/", 2)
8074
rolename := client.name
@@ -84,12 +78,15 @@ func assumeRoleWithWebIdentity(client *OIDCClient, idToken string, roleARN strin
8478

8579
log.Println("Requesting AWS credentials using ID Token")
8680

87-
resp, err := svc.AssumeRoleWithWebIdentity(&sts.AssumeRoleWithWebIdentityInput{
81+
cfg := defaults.Config()
82+
cfg.Region = "eu-central-1"
83+
req := sts.New(cfg).AssumeRoleWithWebIdentityRequest(&sts.AssumeRoleWithWebIdentityInput{
8884
RoleArn: aws.String(roleARN),
8985
RoleSessionName: aws.String(username + "@" + rolename),
9086
WebIdentityToken: aws.String(idToken),
9187
DurationSeconds: aws.Int64(durationSeconds),
9288
})
89+
resp, err := req.Send(context.Background())
9390
if err != nil {
9491
return nil, fmt.Errorf("error retrieving STS credentials using ID Token: %v", err)
9592
}

0 commit comments

Comments
 (0)