Skip to content

Commit

Permalink
pdns: fix wildcard with SANs (#837)
Browse files Browse the repository at this point in the history
The current implementation of the DNS challenge does not allow
to set multiple TXT records at once.

As PowerDNS has the concept of record sets, and so all records
for the same type and name must set during one call, we would override
existing records.

To avoid this, we merge the new TXT record with existing ones
  • Loading branch information
tbe authored and ldez committed Mar 21, 2019
1 parent 0ce6ba3 commit b668bde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion providers/dns/pdns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (d *DNSProvider) findTxtRecord(fqdn string) (*rrSet, error) {
}
}

return nil, fmt.Errorf("no existing record found for %s", fqdn)
return nil, nil
}

func (d *DNSProvider) getAPIVersion() (int, error) {
Expand Down
18 changes: 17 additions & 1 deletion providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
TTL: d.config.TTL,
}

// Look for existing records.
existingRrSet, err := d.findTxtRecord(fqdn)
if err != nil {
return fmt.Errorf("pdns: %v", err)
}

// merge the existing and new records
var records []Record
if existingRrSet != nil {
records = existingRrSet.Records
}
records = append(records, rec)

rrsets := rrSets{
RRSets: []rrSet{
{
Expand All @@ -129,7 +142,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Type: "TXT",
Kind: "Master",
TTL: d.config.TTL,
Records: []Record{rec},
Records: records,
},
},
}
Expand Down Expand Up @@ -159,6 +172,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
if err != nil {
return fmt.Errorf("pdns: %v", err)
}
if set == nil {
return fmt.Errorf("pdns: no existing record found for %s", fqdn)
}

rrsets := rrSets{
RRSets: []rrSet{
Expand Down

0 comments on commit b668bde

Please sign in to comment.