Skip to content

Commit 40c5027

Browse files
committed
feat: add processCredentialTimeout option to token command
This update introduces a new flag `--process-credential-timeout` to the token command, allowing users to specify a timeout for the AWS credential_process execution. The timeout value can be set to a positive duration, overriding the SDK's default of 1 minute. The change includes updates to the `GetTokenOptions` struct and the associated binding in the command initialization.
1 parent e4c2964 commit 40c5027

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cmd/aws-iam-authenticator/token.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var tokenCmd = &cobra.Command{
4242
forwardSessionName := viper.GetBool("forwardSessionName")
4343
sessionName := viper.GetString("sessionName")
4444
cache := viper.GetBool("cache")
45+
procCredTimeout := viper.GetDuration("processCredentialTimeout")
4546

4647
if clusterID == "" {
4748
fmt.Fprintf(os.Stderr, "Error: cluster ID not specified\n")
@@ -69,11 +70,12 @@ var tokenCmd = &cobra.Command{
6970
}
7071

7172
tok, err = gen.GetWithOptions(context.Background(), &token.GetTokenOptions{
72-
ClusterID: clusterID,
73-
AssumeRoleARN: roleARN,
74-
AssumeRoleExternalID: externalID,
75-
SessionName: sessionName,
76-
Region: region,
73+
ClusterID: clusterID,
74+
AssumeRoleARN: roleARN,
75+
AssumeRoleExternalID: externalID,
76+
SessionName: sessionName,
77+
Region: region,
78+
ProcessCredentialTimeout: procCredTimeout,
7779
})
7880
if err != nil {
7981
fmt.Fprintf(os.Stderr, "could not get token: %v\n", err)
@@ -99,6 +101,7 @@ func init() {
99101
false,
100102
"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")
101103
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.")
104+
tokenCmd.Flags().Duration("process-credential-timeout", 0, "Timeout for AWS credential_process execution (e.g. 5m, 120s). 0 uses SDK default (1m).")
102105
if err := viper.BindPFlag("region", tokenCmd.Flags().Lookup("region")); err != nil {
103106
fmt.Printf("Failed to bind flag '%s' - %+v\n", "region", err)
104107
os.Exit(1)
@@ -127,6 +130,10 @@ func init() {
127130
fmt.Printf("Failed to bind flag '%s' - %+v\n", "cache", err)
128131
os.Exit(1)
129132
}
133+
if err := viper.BindPFlag("processCredentialTimeout", tokenCmd.Flags().Lookup("process-credential-timeout")); err != nil {
134+
fmt.Printf("Failed to bind flag '%s' - %+v\n", "processCredentialTimeout", err)
135+
os.Exit(1)
136+
}
130137
if err := viper.BindEnv("role", "DEFAULT_ROLE"); err != nil {
131138
fmt.Printf("Failed to bind env '%s' - %+v\n", "role", err)
132139
os.Exit(1)

pkg/token/token.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/aws/aws-sdk-go-v2/aws/middleware"
3737
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
3838
"github.com/aws/aws-sdk-go-v2/config"
39+
"github.com/aws/aws-sdk-go-v2/credentials/processcreds"
3940
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
4041
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
4142
"github.com/aws/aws-sdk-go-v2/service/sts"
@@ -120,6 +121,9 @@ type GetTokenOptions struct {
120121
AssumeRoleARN string
121122
AssumeRoleExternalID string
122123
SessionName string
124+
// ProcessCredentialTimeout, if set to a positive duration, overrides the SDK's
125+
// default 1 minute timeout for running credential_process.
126+
ProcessCredentialTimeout time.Duration
123127
}
124128

125129
// FormatError is returned when there is a problem with token that is
@@ -235,6 +239,11 @@ func (g generator) GetWithOptions(ctx context.Context, options *GetTokenOptions)
235239
config.WithAssumeRoleCredentialOptions(func(options *stscreds.AssumeRoleOptions) {
236240
options.TokenProvider = StdinStderrTokenProvider
237241
}),
242+
config.WithProcessCredentialOptions(func(o *processcreds.Options) {
243+
if options.ProcessCredentialTimeout > 0 {
244+
o.Timeout = options.ProcessCredentialTimeout
245+
}
246+
}),
238247
config.WithEC2IMDSClientEnableState(imds.ClientEnabled),
239248
)
240249
if err != nil {

0 commit comments

Comments
 (0)