Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use WebIdentityRoleProvider #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions awsauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -267,6 +268,22 @@ func GetCredentials(c *Config) (*awsCredentials.Credentials, error) {
log.Print("[INFO] ECS container credentials detected, RemoteCredProvider added to auth chain")
}

if filePath := os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE"); len(filePath) > 0 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS_WEB_IDENTITY_TOKEN_FILE is come here.

https://aws.amazon.com/blogs/opensource/introducing-fine-grained-iam-roles-service-accounts/

Because the service account has an eks.amazonaws.com/role-arn annotation, the webhook injects the necessary environment variables (AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE) and sets up the aws-iam-token projected volume in the pod that the job supervises.

stsSession, err := session.NewSession(cfg)
if err != nil {
return nil, fmt.Errorf("error creating sts session: %s", err)
}
stsClient := sts.New(stsSession)

providers = append(providers, stscreds.NewWebIdentityRoleProvider(
stsClient,
os.Getenv("AWS_ROLE_ARN"),
strconv.FormatInt(time.Now().UnixNano(), 10),
filePath,
))
log.Print("[INFO] EKS IRSA credentials detected, WebIdentityRoleProvider added to auth chain")
}

if !c.SkipMetadataApiCheck {
// Real AWS should reply to a simple metadata request.
// We check it actually does to ensure something else didn't just
Expand Down