From f556c6711cf266e188c7e400cd2efcc1f2d600b5 Mon Sep 17 00:00:00 2001 From: Tim Ross Date: Fri, 15 Nov 2024 20:04:22 -0500 Subject: [PATCH] Prevent using custom enpoints if one is not defined The AWS endpoint sanititazion was inadvertantly being applied all the time, causing configurations not using custom endpoints to be forced into using a custom endpoint instead of AWS. --- lib/events/dynamoevents/dynamoevents.go | 4 +++- lib/events/s3sessions/s3handler.go | 4 +++- lib/utils/aws/endpoint/endpoint.go | 2 +- lib/utils/aws/endpoint/endpoint_test.go | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/events/dynamoevents/dynamoevents.go b/lib/events/dynamoevents/dynamoevents.go index d17c8895709ac..1504d987b7fcc 100644 --- a/lib/events/dynamoevents/dynamoevents.go +++ b/lib/events/dynamoevents/dynamoevents.go @@ -208,7 +208,9 @@ func (cfg *Config) CheckAndSetDefaults() error { cfg.UIDGenerator = utils.NewRealUID() } - cfg.Endpoint = endpoint.CreateURI(cfg.Endpoint, cfg.Insecure) + if cfg.Endpoint != "" { + cfg.Endpoint = endpoint.CreateURI(cfg.Endpoint, cfg.Insecure) + } return nil } diff --git a/lib/events/s3sessions/s3handler.go b/lib/events/s3sessions/s3handler.go index 97605db6dfbad..7fc80f9063c5a 100644 --- a/lib/events/s3sessions/s3handler.go +++ b/lib/events/s3sessions/s3handler.go @@ -157,7 +157,9 @@ func (s *Config) CheckAndSetDefaults() error { return trace.BadParameter("missing parameter Bucket") } - s.Endpoint = endpoint.CreateURI(s.Endpoint, s.Insecure) + if s.Endpoint != "" { + s.Endpoint = endpoint.CreateURI(s.Endpoint, s.Insecure) + } return nil } diff --git a/lib/utils/aws/endpoint/endpoint.go b/lib/utils/aws/endpoint/endpoint.go index 22fddea4e5bd4..bfca04da9df1e 100644 --- a/lib/utils/aws/endpoint/endpoint.go +++ b/lib/utils/aws/endpoint/endpoint.go @@ -33,7 +33,7 @@ var schemeRegex = regexp.MustCompile("^([^:]+)://") // a custom service endpoint, this performs applies the same // behavior that the legacy sdk did. func CreateURI(endpoint string, insecure bool) string { - if !schemeRegex.MatchString(endpoint) { + if endpoint != "" && !schemeRegex.MatchString(endpoint) { scheme := "https" if insecure { scheme = "http" diff --git a/lib/utils/aws/endpoint/endpoint_test.go b/lib/utils/aws/endpoint/endpoint_test.go index 1b5b89236a682..9c799fad3aa15 100644 --- a/lib/utils/aws/endpoint/endpoint_test.go +++ b/lib/utils/aws/endpoint/endpoint_test.go @@ -31,6 +31,9 @@ func TestCreateURI(t *testing.T) { insecure bool expected string }{ + { + name: "empty endpoint", + }, { name: "valid endpoint", endpoint: "https://test.example.com",