Skip to content
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

fix(pihole): gracefully avoid invalid request with wildcard #4904

Merged
merged 5 commits into from
Nov 29, 2024
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
4 changes: 4 additions & 0 deletions provider/pihole/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"golang.org/x/net/html"

"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/provider"
)

// piholeAPI declares the "API" actions performed against the Pihole server.
Expand Down Expand Up @@ -224,6 +225,9 @@ func (p *piholeClient) apply(ctx context.Context, action string, ep *endpoint.En
log.Infof("%s %s IN %s -> %s", action, ep.DNSName, ep.RecordType, ep.Targets[0])

form := p.newDNSActionForm(action, ep)
if strings.Contains(ep.DNSName, "*") {
return provider.NewSoftError(errors.New("UNSUPPORTED: Pihole DNS names cannot return wildcard"))
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(form.Encode()))
if err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions provider/pihole/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ func TestCreateRecord(t *testing.T) {
if err := cl.createRecord(context.Background(), ep); err != nil {
t.Fatal(err)
}

// Test create a wildcard record and ensure it fails
ep = &endpoint.Endpoint{
DNSName: "*.example.com",
Targets: []string{"192.168.1.1"},
RecordType: endpoint.RecordTypeA,
}
if err := cl.createRecord(context.Background(), ep); err == nil {
t.Fatal(err)
}
}

func TestDeleteRecord(t *testing.T) {
Expand Down