55 "strings"
66
77 "github.com/aws/aws-sdk-go/aws"
8+ "github.com/aws/aws-sdk-go/aws/credentials/stscreds"
89 awss "github.com/aws/aws-sdk-go/aws/session"
910 "github.com/aws/aws-sdk-go/service/route53"
1011 "github.com/pkg/errors"
@@ -17,10 +18,10 @@ import (
1718
1819// API represents the calls made to the API.
1920type API interface {
20- GetHostedZone (hostedZone string ) (* route53.GetHostedZoneOutput , error )
21- ValidateZoneRecords (zone * route53.HostedZone , zoneName string , zonePath * field.Path , ic * types.InstallConfig ) field.ErrorList
21+ GetHostedZone (hostedZone string , cfg * aws. Config ) (* route53.GetHostedZoneOutput , error )
22+ ValidateZoneRecords (zone * route53.HostedZone , zoneName string , zonePath * field.Path , ic * types.InstallConfig , cfg * aws. Config ) field.ErrorList
2223 GetBaseDomain (baseDomainName string ) (* route53.HostedZone , error )
23- GetSubDomainDNSRecords (hostedZone * route53.HostedZone , ic * types.InstallConfig ) ([]string , error )
24+ GetSubDomainDNSRecords (hostedZone * route53.HostedZone , ic * types.InstallConfig , cfg * aws. Config ) ([]string , error )
2425}
2526
2627// Client makes calls to the AWS Route53 API.
@@ -37,9 +38,9 @@ func NewClient(ssn *awss.Session) *Client {
3738}
3839
3940// GetHostedZone attempts to get the hosted zone from the AWS Route53 instance
40- func (c * Client ) GetHostedZone (hostedZone string ) (* route53.GetHostedZoneOutput , error ) {
41+ func (c * Client ) GetHostedZone (hostedZone string , cfg * aws. Config ) (* route53.GetHostedZoneOutput , error ) {
4142 // build a new Route53 instance from the same session that made it here
42- r53 := route53 .New (c .ssn )
43+ r53 := route53 .New (c .ssn , cfg )
4344
4445 // validate that the hosted zone exists
4546 hostedZoneOutput , err := r53 .GetHostedZone (& route53.GetHostedZoneInput {Id : aws .String (hostedZone )})
@@ -50,10 +51,10 @@ func (c *Client) GetHostedZone(hostedZone string) (*route53.GetHostedZoneOutput,
5051}
5152
5253// ValidateZoneRecords Attempts to validate each of the candidate HostedZones against the Config
53- func (c * Client ) ValidateZoneRecords (zone * route53.HostedZone , zoneName string , zonePath * field.Path , ic * types.InstallConfig ) field.ErrorList {
54+ func (c * Client ) ValidateZoneRecords (zone * route53.HostedZone , zoneName string , zonePath * field.Path , ic * types.InstallConfig , cfg * aws. Config ) field.ErrorList {
5455 allErrs := field.ErrorList {}
5556
56- problematicRecords , err := c .GetSubDomainDNSRecords (zone , ic )
57+ problematicRecords , err := c .GetSubDomainDNSRecords (zone , ic , cfg )
5758 if err != nil {
5859 allErrs = append (allErrs , field .InternalError (zonePath ,
5960 errors .Wrapf (err , "could not list record sets for domain %q" , zoneName )))
@@ -72,15 +73,15 @@ func (c *Client) ValidateZoneRecords(zone *route53.HostedZone, zoneName string,
7273
7374// GetSubDomainDNSRecords Validates the hostedZone against the cluster domain, and ensures that the
7475// cluster domain does not have a current record set for the hostedZone
75- func (c * Client ) GetSubDomainDNSRecords (hostedZone * route53.HostedZone , ic * types.InstallConfig ) ([]string , error ) {
76+ func (c * Client ) GetSubDomainDNSRecords (hostedZone * route53.HostedZone , ic * types.InstallConfig , cfg * aws. Config ) ([]string , error ) {
7677 dottedClusterDomain := ic .ClusterDomain () + "."
7778
7879 // validate that the domain of the hosted zone is the cluster domain or a parent of the cluster domain
7980 if ! isHostedZoneDomainParentOfClusterDomain (hostedZone , dottedClusterDomain ) {
8081 return nil , errors .Errorf ("hosted zone domain %q is not a parent of the cluster domain %q" , * hostedZone .Name , dottedClusterDomain )
8182 }
8283
83- r53 := route53 .New (c .ssn )
84+ r53 := route53 .New (c .ssn , cfg )
8485
8586 var problematicRecords []string
8687 // validate that the hosted zone does not already have any record sets for the cluster domain
@@ -134,3 +135,14 @@ func (c *Client) GetBaseDomain(baseDomainName string) (*route53.HostedZone, erro
134135 }
135136 return baseDomainZone , nil
136137}
138+
139+ // GetR53ClientCfg creates a config for the route53 client by determining
140+ // whether it is needed to obtain STS assume role credentials.
141+ func GetR53ClientCfg (sess * awss.Session , roleARN string ) * aws.Config {
142+ if roleARN == "" {
143+ return nil
144+ }
145+
146+ creds := stscreds .NewCredentials (sess , roleARN )
147+ return & aws.Config {Credentials : creds }
148+ }
0 commit comments