diff --git a/pkg/credentials/iam_aws.go b/pkg/credentials/iam_aws.go index 485a717eb..f7a4af4a2 100644 --- a/pkg/credentials/iam_aws.go +++ b/pkg/credentials/iam_aws.go @@ -19,6 +19,7 @@ package credentials import ( "bufio" + "context" "errors" "fmt" "io/ioutil" @@ -254,7 +255,10 @@ func getEcsTaskCredentials(client *http.Client, endpoint string, token string) ( } func fetchIMDSToken(client *http.Client, endpoint string) (string, error) { - req, err := http.NewRequest(http.MethodPut, endpoint+tokenPath, nil) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint+tokenPath, nil) if err != nil { return "", err }