Skip to content

Commit

Permalink
skip service validation to get the default regions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kmala committed Jul 11, 2024
1 parent 4a70f33 commit 6c15092
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ type tokenVerifier struct {
validSTShostnames map[string]bool
}

func getDefaultHostNameForRegion(partition *endpoints.Partition, region string) (string, error) {
rep, err := partition.EndpointFor(stsServiceID, region, endpoints.STSRegionalEndpointOption, endpoints.ResolveUnknownServiceOption)
if err != nil {
return "", fmt.Errorf("Error resolving endpoint for %s in partition %s. err: %v", region, partition.ID(), err)
}
parsedURL, err := url.Parse(rep.URL)
if err != nil {
return "", fmt.Errorf("Error parsing STS URL %s. err: %v", rep.URL, err)
}
return parsedURL.Hostname(), nil
}

func stsHostsForPartition(partitionID, region string) map[string]bool {
validSTShostnames := map[string]bool{}

Expand All @@ -396,6 +408,14 @@ func stsHostsForPartition(partitionID, region string) map[string]bool {
stsSvc, ok := partition.Services()[stsServiceID]
if !ok {
logrus.Errorf("STS service not found in partition %s", partitionID)
// Add the host of the current instances region if the service doesn't already exists in the partition
// so we don't fail if the service is not present in the go sdk but matches the instances region.
stsHostName, err := getDefaultHostNameForRegion(partition, region)
if err != nil {
logrus.WithError(err).Error("Error getting default hostname")
} else {
validSTShostnames[stsHostName] = true
}
return validSTShostnames
}
stsSvcEndPoints := stsSvc.Endpoints()
Expand All @@ -416,17 +436,12 @@ func stsHostsForPartition(partitionID, region string) map[string]bool {
// Add the host of the current instances region if not already exists so we don't fail if the region is not
// present in the go sdk but matches the instances region.
if _, ok := stsSvcEndPoints[region]; !ok {
rep, err := partition.EndpointFor(stsServiceID, region, endpoints.STSRegionalEndpointOption)
stsHostName, err := getDefaultHostNameForRegion(partition, region)
if err != nil {
logrus.WithError(err).Errorf("Error resolving endpoint for %s in partition %s", region, partitionID)
logrus.WithError(err).Error("Error getting default hostname")
return validSTShostnames
}
parsedURL, err := url.Parse(rep.URL)
if err != nil {
logrus.WithError(err).Errorf("Error parsing STS URL %s", rep.URL)
return validSTShostnames
}
validSTShostnames[parsedURL.Hostname()] = true
validSTShostnames[stsHostName] = true
}

return validSTShostnames
Expand Down

0 comments on commit 6c15092

Please sign in to comment.