From de8a56bde8df13150368edc5af09d1351604d562 Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Fri, 5 Aug 2016 22:41:24 -0500 Subject: [PATCH] Fix GoogleCloud DNS challenge to allow subdomains Fixes #257 Previously the google cloud provider assumed the domain being provided was also the authoritative zone. This fix uses an acme function to recursively lookup the authoritative zone for a provided domain. --- providers/dns/googlecloud/googlecloud.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/providers/dns/googlecloud/googlecloud.go b/providers/dns/googlecloud/googlecloud.go index a9a9903e..b8d9951c 100644 --- a/providers/dns/googlecloud/googlecloud.go +++ b/providers/dns/googlecloud/googlecloud.go @@ -5,7 +5,6 @@ package googlecloud import ( "fmt" "os" - "strings" "time" "github.com/xenolf/lego/acme" @@ -121,23 +120,24 @@ func (c *DNSProvider) Timeout() (timeout, interval time.Duration) { // getHostedZone returns the managed-zone func (c *DNSProvider) getHostedZone(domain string) (string, error) { - dnsName := domain + "." + authZone, err := acme.FindZoneByFqdn(acme.ToFqdn(domain), acme.RecursiveNameservers) + if err != nil { + return "", err + } + zones, err := c.client.ManagedZones. List(c.project). - DnsName(dnsName). + DnsName(authZone). Do() if err != nil { return "", fmt.Errorf("GoogleCloud API call failed: %v", err) } - for _, z := range zones.ManagedZones { - if strings.HasSuffix(dnsName, z.DnsName) { - return z.Name, nil - } + if len(zones.ManagedZones) == 0 { + return "", fmt.Errorf("No matching GoogleCloud domain found for domain %s", authZone) } - return "", fmt.Errorf("No matching GoogleCloud domain found for domain %s", domain) - + return zones.ManagedZones[0].Name, nil } func (c *DNSProvider) findTxtRecords(zone, fqdn string) ([]*dns.ResourceRecordSet, error) {