Skip to content

Commit 25dd06a

Browse files
pefeiglPeter Feigltlimoncelli
authored
POWERDNS: Map dnscontrol Tags to powerdns Variants (#3803)
Co-authored-by: Peter Feigl <peter.feigl@nexoid.at> Co-authored-by: Tom Limoncelli <6293917+tlimoncelli@users.noreply.github.com>
1 parent c1b90d0 commit 25dd06a

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

documentation/provider/powerdns.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ D("example.com", REG_NONE, DnsProvider(DSP_POWERDNS),
6363
## Activation
6464
See the [PowerDNS documentation](https://doc.powerdns.com/authoritative/http-api/index.html) how the API can be enabled.
6565

66+
## Tags and Variants
67+
If you use a dnscontrol *tag* (like `example.com!internal`) it will be mapped to a powerdns *variant* (like `example.com..internal`).
68+
69+
See [PowerDNS documentation on Views](https://doc.powerdns.com/authoritative/views.html) for details on how to setup networks and views for these variants.
70+
6671
## Caveats
6772

6873
### SOA Records

providers/powerdns/diff.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,22 @@ func (dsp *powerdnsProvider) getDiff2DomainCorrections(dc *models.DomainConfig,
5858
}
5959
}
6060

61+
domainVariant := GetVariantName(dc.Name, dc.Metadata[models.DomainTag])
62+
6163
// only append a Correction if there are any, otherwise causes an error when sending an empty rrset
6264
if len(rrDeleteSets) > 0 {
6365
corrections = append(corrections, &models.Correction{
6466
Msg: strings.Join(deleteMsgs, "\n"),
6567
F: func() error {
66-
return dsp.client.Zones().RemoveRecordSetsFromZone(context.Background(), dsp.ServerName, canonical(dc.Name), rrDeleteSets)
68+
return dsp.client.Zones().RemoveRecordSetsFromZone(context.Background(), dsp.ServerName, domainVariant, rrDeleteSets)
6769
},
6870
})
6971
}
7072
if len(rrChangeSets) > 0 {
7173
corrections = append(corrections, &models.Correction{
7274
Msg: strings.Join(changeMsgs, "\n"),
7375
F: func() error {
74-
return dsp.client.Zones().AddRecordSetsToZone(context.Background(), dsp.ServerName, canonical(dc.Name), rrChangeSets)
76+
return dsp.client.Zones().AddRecordSetsToZone(context.Background(), dsp.ServerName, domainVariant, rrChangeSets)
7577
},
7678
})
7779
}
@@ -98,3 +100,14 @@ func buildRecordList(change diff2.Change) (records []zones.Record) {
98100
func canonical(fqdn string) string {
99101
return fqdn + "."
100102
}
103+
104+
// Build the variant name for powerdns. this is the domain + "." + the tag
105+
// so dnscontrol "example.com!internal" becomes powerdns "example.com..internal"
106+
// See https://doc.powerdns.com/authoritative/views.html
107+
func GetVariantName(domain string, tag string) string {
108+
if tag != "" {
109+
return canonical(domain) + "." + tag
110+
} else {
111+
return canonical(domain)
112+
}
113+
}

providers/powerdns/dns.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func (dsp *powerdnsProvider) GetNameservers(string) ([]*models.Nameserver, error
2121
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
2222
func (dsp *powerdnsProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
2323
curRecords := models.Records{}
24-
zone, err := dsp.client.Zones().GetZone(context.Background(), dsp.ServerName, canonical(domain))
24+
domainVariant := GetVariantName(domain, meta[models.DomainTag])
25+
zone, err := dsp.client.Zones().GetZone(context.Background(), dsp.ServerName, domainVariant)
2526
if err != nil {
2627
if _, ok := err.(pdnshttp.ErrNotFound); ok {
2728
// Zone is not found, but everything else is okay so return no records

providers/powerdns/dnssec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010

1111
// getDNSSECCorrections returns corrections that update a domain's DNSSEC state.
1212
func (dsp *powerdnsProvider) getDNSSECCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
13-
zoneCryptokeys, getErr := dsp.client.Cryptokeys().ListCryptokeys(context.Background(), dsp.ServerName, dc.Name)
13+
domainVariant := GetVariantName(dc.Name, dc.Metadata[models.DomainTag])
14+
zoneCryptokeys, getErr := dsp.client.Cryptokeys().ListCryptokeys(context.Background(), dsp.ServerName, domainVariant)
1415
if getErr != nil {
1516
if _, ok := getErr.(pdnshttp.ErrNotFound); ok {
1617
// Zone doesn't exist, this is okay as no corrections are needed

0 commit comments

Comments
 (0)