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

switch to use regional sts endpoint & imdsV2 #283

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions cmd/aws-iam-authenticator/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var tokenCmd = &cobra.Command{
Short: "Authenticate using AWS IAM and get token for Kubernetes",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
region := viper.GetString("region")
roleARN := viper.GetString("role")
externalID := viper.GetString("externalID")
clusterID := viper.GetString("clusterID")
Expand Down Expand Up @@ -65,6 +66,7 @@ var tokenCmd = &cobra.Command{
AssumeRoleARN: roleARN,
AssumeRoleExternalID: externalID,
SessionName: sessionName,
Region: region,
})
if err != nil {
fmt.Fprintf(os.Stderr, "could not get token: %v\n", err)
Expand All @@ -81,6 +83,7 @@ var tokenCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(tokenCmd)
tokenCmd.Flags().String("region", "", "AWS region to use for assume role calls")
tokenCmd.Flags().StringP("role", "r", "", "Assume an IAM Role ARN before signing this token")
tokenCmd.Flags().StringP("external-id", "e", "", "External ID to pass when assuming the IAM Role")
tokenCmd.Flags().StringP("session-name", "s", "", "Session name to pass when assuming the IAM Role")
Expand All @@ -89,6 +92,7 @@ func init() {
false,
"Enable mapping a federated sessions caller-specified-role-name attribute onto newly assumed sessions. NOTE: Only applicable when a new role is requested via --role")
tokenCmd.Flags().Bool("cache", false, "Cache the credential on disk until it expires. Uses the aws profile specified by AWS_PROFILE or the default profile.")
viper.BindPFlag("region", tokenCmd.Flags().Lookup("region"))
viper.BindPFlag("role", tokenCmd.Flags().Lookup("role"))
viper.BindPFlag("externalID", tokenCmd.Flags().Lookup("external-id"))
viper.BindPFlag("tokenOnly", tokenCmd.Flags().Lookup("token-only"))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module sigs.k8s.io/aws-iam-authenticator
go 1.12

require (
github.com/aws/aws-sdk-go v1.23.11
github.com/aws/aws-sdk-go v1.26.7
github.com/gofrs/flock v0.7.0
github.com/prometheus/client_golang v1.1.0
github.com/sirupsen/logrus v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aws/aws-sdk-go v1.23.11 h1:fTq1xdeDdCwUfBA64QHk1b5HJfWauac36LvtWlk0pEw=
github.com/aws/aws-sdk-go v1.23.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.26.7 h1:ObjEnmzvSdYy8KVd3me7v/UMyCn81inLy2SyoIPoBkg=
github.com/aws/aws-sdk-go v1.26.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
8 changes: 6 additions & 2 deletions pkg/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"strings"
"time"

"github.com/aws/aws-sdk-go/aws/credentials"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -92,6 +92,7 @@ type Token struct {

// GetTokenOptions is passed to GetWithOptions to provide an extensible get token interface
type GetTokenOptions struct {
Region string
ClusterID string
AssumeRoleARN string
AssumeRoleExternalID string
Expand Down Expand Up @@ -230,6 +231,9 @@ func (g generator) GetWithOptions(options *GetTokenOptions) (Token, error) {
if err != nil {
return Token{}, fmt.Errorf("could not create session: %v", err)
}
if options.Region != "" {
sess = sess.Copy(aws.NewConfig().WithRegion(options.Region).WithSTSRegionalEndpoint(endpoints.RegionalSTSEndpoint))
}

if g.cache {
// figure out what profile we're using
Expand Down
7 changes: 7 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/aws/arn/arn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 102 additions & 28 deletions vendor/github.com/aws/aws-sdk-go/aws/client/default_retryer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/aws/client/no_op_retryer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading