From df7553aa625dff6e2bcf77b57e43a5ff98ff1d6e Mon Sep 17 00:00:00 2001 From: Costas Drogos Date: Thu, 10 Feb 2022 20:22:59 +0100 Subject: [PATCH] ns1: fix multivalue CAA handling (#1404) * ns1: fix multivalue CAA handling Introducing better multivalue support for the CAA entry broke CAA support for ns1, failing the relevant test. Improve the code touching CAA in either side, so that it can handle multivalue, quoted, CAA entries. * ns1: use native CAA record parser for CAA instead of using PopulateFromString. * ns1: remove panics Remove panics and bubble-up errors. * ns1: in case of errors, return nil data Co-authored-by: Tom Limoncelli --- providers/ns1/ns1Provider.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/providers/ns1/ns1Provider.go b/providers/ns1/ns1Provider.go index 0fe37bedf..e369b30d5 100644 --- a/providers/ns1/ns1Provider.go +++ b/providers/ns1/ns1Provider.go @@ -170,7 +170,12 @@ func buildRecord(recs models.Records, domain string, id string) *dns.Record { } else if r.Type == "TXT" { rec.AddAnswer(&dns.Answer{Rdata: r.TxtStrings}) } else if r.Type == "CAA" { - rec.AddAnswer(&dns.Answer{Rdata: strings.Split(fmt.Sprintf("%v %s %s", r.CaaFlag, r.CaaTag, r.GetTargetField()), " ")}) + rec.AddAnswer(&dns.Answer{ + Rdata: []string{ + fmt.Sprintf("%v", r.CaaFlag), + r.CaaTag, + fmt.Sprintf("%s", r.GetTargetField()), + }}) } else if r.Type == "SRV" { rec.AddAnswer(&dns.Answer{Rdata: strings.Split(fmt.Sprintf("%d %d %d %v", r.SrvPriority, r.SrvWeight, r.SrvPort, r.GetTargetField()), " ")}) } else { @@ -192,16 +197,22 @@ func convert(zr *dns.ZoneRecord, domain string) ([]*models.RecordConfig, error) case "ALIAS": rec.Type = rtype if err := rec.SetTarget(ans); err != nil { - panic(fmt.Errorf("unparsable %s record received from ns1: %w", rtype, err)) + return nil, fmt.Errorf("unparsable %s record received from ns1: %w", rtype, err) } case "URLFWD": rec.Type = rtype if err := rec.SetTarget(ans); err != nil { - panic(fmt.Errorf("unparsable %s record received from ns1: %w", rtype, err)) + return nil, fmt.Errorf("unparsable %s record received from ns1: %w", rtype, err) + } + case "CAA": + //dnscontrol expects quotes around multivalue CAA entries, API doesn't add them + x_ans := strings.SplitN(ans, " ", 3) + if err := rec.SetTargetCAAStrings(x_ans[0], x_ans[1], x_ans[2]); err != nil { + return nil, fmt.Errorf("unparsable %s record received from ns1: %w", rtype, err) } default: if err := rec.PopulateFromString(rtype, ans, domain); err != nil { - panic(fmt.Errorf("unparsable record received from ns1: %w", err)) + return nil, fmt.Errorf("unparsable record received from ns1: %w", err) } } found = append(found, rec)