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

[v15] Re-enable AWS IMDSv1 fallback #39366

Merged
merged 1 commit into from Mar 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/teleport-usage/main.go
Expand Up @@ -81,7 +81,6 @@ func main() {
Retryer: limiter,
Region: aws.String(params.awsRegion),
CredentialsChainVerboseErrors: aws.Bool(true),
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
},
})
Expand Down
4 changes: 0 additions & 4 deletions integration/ec2_test.go
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/gravitational/trace"
Expand Down Expand Up @@ -144,9 +143,6 @@ func getIID(ctx context.Context, t *testing.T) imds.InstanceIdentityDocument {
func getCallerIdentity(t *testing.T) *sts.GetCallerIdentityOutput {
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
},
})
require.NoError(t, err)
stsService := sts.New(sess)
Expand Down
5 changes: 2 additions & 3 deletions lib/auth/join_iam.go
Expand Up @@ -437,9 +437,8 @@ func createSignedSTSIdentityRequest(ctx context.Context, challenge string, opts

func newSTSClient(ctx context.Context, cfg *stsIdentityRequestConfig) (*sts.STS, error) {
awsConfig := awssdk.Config{
EC2MetadataEnableFallback: awssdk.Bool(false),
UseFIPSEndpoint: cfg.fipsEndpointOption,
STSRegionalEndpoint: cfg.regionalEndpointOption,
UseFIPSEndpoint: cfg.fipsEndpointOption,
STSRegionalEndpoint: cfg.regionalEndpointOption,
}
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Expand Down
4 changes: 1 addition & 3 deletions lib/backend/dynamo/dynamodbbk.go
Expand Up @@ -251,9 +251,7 @@ func New(ctx context.Context, params backend.Params) (*Backend, error) {
useFIPSEndpoint = endpoints.FIPSEndpointStateEnabled
}

awsConfig := aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
}
awsConfig := aws.Config{}
if cfg.Region != "" {
awsConfig.Region = aws.String(cfg.Region)
}
Expand Down
12 changes: 5 additions & 7 deletions lib/cloud/clients.go
Expand Up @@ -1023,9 +1023,8 @@ func (c *TestCloudClients) getAWSSessionForRegion(region string) (*awssession.Se
AccessKeyID: "fakeClientKeyID",
SecretAccessKey: "fakeClientSecret",
}}),
Region: aws.String(region),
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
Region: aws.String(region),
UseFIPSEndpoint: useFIPSEndpoint,
})
}

Expand Down Expand Up @@ -1296,10 +1295,9 @@ func buildAWSSessionOptions(region string, cred *credentials.Credentials) awsses
return awssession.Options{
SharedConfigState: awssession.SharedConfigEnable,
Config: aws.Config{
Region: aws.String(region),
Credentials: cred,
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
Region: aws.String(region),
Credentials: cred,
UseFIPSEndpoint: useFIPSEndpoint,
},
}
}
8 changes: 3 additions & 5 deletions lib/configurators/aws/aws.go
Expand Up @@ -336,8 +336,7 @@ func (c *ConfiguratorConfig) CheckAndSetDefaults() error {
c.AWSSession, err = awssession.NewSessionWithOptions(awssession.Options{
SharedConfigState: awssession.SharedConfigEnable,
Config: aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
UseFIPSEndpoint: useFIPSEndpoint,
},
})
if err != nil {
Expand Down Expand Up @@ -369,9 +368,8 @@ func (c *ConfiguratorConfig) CheckAndSetDefaults() error {
}
session, err := awssession.NewSessionWithOptions(awssession.Options{
Config: aws.Config{
Region: &region,
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
Region: &region,
UseFIPSEndpoint: useFIPSEndpoint,
},
SharedConfigState: awssession.SharedConfigEnable,
})
Expand Down
4 changes: 1 addition & 3 deletions lib/events/dynamoevents/dynamoevents.go
Expand Up @@ -264,9 +264,7 @@ func New(ctx context.Context, cfg Config) (*Log, error) {
Config: cfg,
}

awsConfig := aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
}
awsConfig := aws.Config{}

// Override the default environment's region if value set in YAML file:
if cfg.Region != "" {
Expand Down
3 changes: 1 addition & 2 deletions lib/events/s3sessions/s3handler.go
Expand Up @@ -157,8 +157,7 @@ func (s *Config) CheckAndSetDefaults() error {
}
if s.Session == nil {
awsConfig := aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: events.FIPSProtoStateToAWSState(s.UseFIPSEndpoint),
UseFIPSEndpoint: events.FIPSProtoStateToAWSState(s.UseFIPSEndpoint),
}
if s.Region != "" {
awsConfig.Region = aws.String(s.Region)
Expand Down
10 changes: 4 additions & 6 deletions lib/integrations/awsoidc/clientsv1.go
Expand Up @@ -71,8 +71,7 @@ func NewSessionV1(ctx context.Context, client IntegrationTokenGenerator, region
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigDisable,
Config: aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
UseFIPSEndpoint: useFIPSEndpoint,
},
})
if err != nil {
Expand All @@ -99,10 +98,9 @@ func NewSessionV1(ctx context.Context, client IntegrationTokenGenerator, region
session, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigDisable,
Config: aws.Config{
Region: aws.String(region),
Credentials: awsCredentials,
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
Region: aws.String(region),
Credentials: awsCredentials,
UseFIPSEndpoint: useFIPSEndpoint,
},
})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions lib/srv/app/cloud.go
Expand Up @@ -104,8 +104,7 @@ func (c *CloudConfig) CheckAndSetDefaults() error {
session, err := awssession.NewSessionWithOptions(awssession.Options{
SharedConfigState: awssession.SharedConfigEnable,
Config: aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
UseFIPSEndpoint: useFIPSEndpoint,
},
})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions lib/utils/aws/signing.go
Expand Up @@ -75,8 +75,7 @@ func (s *SigningServiceConfig) CheckAndSetDefaults() error {
ses, err := awssession.NewSessionWithOptions(awssession.Options{
SharedConfigState: awssession.SharedConfigEnable,
Config: aws.Config{
EC2MetadataEnableFallback: aws.Bool(false),
UseFIPSEndpoint: useFIPSEndpoint,
UseFIPSEndpoint: useFIPSEndpoint,
},
})
if err != nil {
Expand Down