Skip to content

pdns: fix TXT record cleanup for wildcard domains #2500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"time"

"github.com/go-acme/lego/v4/challenge"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
}

rec := internal.Record{
Content: "\"" + info.Value + "\"",
Content: strconv.Quote(info.Value),
Disabled: false,

// pre-v1 API
Expand Down Expand Up @@ -202,17 +203,27 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("pdns: no existing record found for %s", info.EffectiveFQDN)
}

rrSets := internal.RRSets{
RRSets: []internal.RRSet{
{
Name: set.Name,
Type: set.Type,
ChangeType: "DELETE",
},
},
var records []internal.Record
for _, r := range set.Records {
if r.Content != strconv.Quote(info.Value) {
records = append(records, r)
}
}

err = d.client.UpdateRecords(ctx, zone, rrSets)
rrSet := internal.RRSet{
Name: set.Name,
Type: set.Type,
}

if len(records) > 0 {
rrSet.ChangeType = "REPLACE"
rrSet.TTL = d.config.TTL
rrSet.Records = records
} else {
rrSet.ChangeType = "DELETE"
}

err = d.client.UpdateRecords(ctx, zone, internal.RRSets{RRSets: []internal.RRSet{rrSet}})
if err != nil {
return fmt.Errorf("pdns: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions providers/dns/pdns/pdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ func TestLivePresentAndCleanup(t *testing.T) {

err = provider.Present(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123e==")
require.NoError(t, err)

err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
err = provider.CleanUp(envTest.GetDomain(), "", "123e==")
require.NoError(t, err)
}

func mustParse(rawURL string) *url.URL {
Expand Down