mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-11-12 01:10:38 +08:00
Add flag to turn on or off the PowerDNS split horizon feature, AKA views.
This commit is contained in:
parent
bfc2b26911
commit
200643282b
5 changed files with 17 additions and 15 deletions
|
|
@ -45,6 +45,8 @@ Following metadata are available:
|
||||||
<br> Can be one of `DEFAULT`, `INCREASE`, `EPOCH`, `SOA-EDIT` or `SOA-EDIT-INCREASE`, default format is YYYYMMDD01.
|
<br> Can be one of `DEFAULT`, `INCREASE`, `EPOCH`, `SOA-EDIT` or `SOA-EDIT-INCREASE`, default format is YYYYMMDD01.
|
||||||
<br>Please see [PowerDNS SOA-EDIT-DNSUPDATE documentation](https://doc.powerdns.com/authoritative/dnsupdate.html#soa-edit-dnsupdate-settings) for explanation of the kinds.
|
<br>Please see [PowerDNS SOA-EDIT-DNSUPDATE documentation](https://doc.powerdns.com/authoritative/dnsupdate.html#soa-edit-dnsupdate-settings) for explanation of the kinds.
|
||||||
<br>**Note that these tokens are case-sensitive!**
|
<br>**Note that these tokens are case-sensitive!**
|
||||||
|
- `use_views` enables mapping dnscontrol tags to PowerDNS views.
|
||||||
|
<br>Set to `true` to enable, defaults to `false`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
An example configuration:
|
An example configuration:
|
||||||
|
|
@ -64,7 +66,7 @@ D("example.com", REG_NONE, DnsProvider(DSP_POWERDNS),
|
||||||
See the [PowerDNS documentation](https://doc.powerdns.com/authoritative/http-api/index.html) how the API can be enabled.
|
See the [PowerDNS documentation](https://doc.powerdns.com/authoritative/http-api/index.html) how the API can be enabled.
|
||||||
|
|
||||||
## Tags and Variants
|
## Tags and Variants
|
||||||
If you use a dnscontrol *tag* (like `example.com!internal`) it will be mapped to a powerdns *variant* (like `example.com..internal`).
|
If you use a dnscontrol *tag* (like `example.com!internal`) it will be mapped to a powerdns *variant* (like `example.com..internal`) when `use_views` is enabled in the provider metadata.
|
||||||
|
|
||||||
See [PowerDNS documentation on Views](https://doc.powerdns.com/authoritative/views.html) for details on how to setup networks and views for these variants.
|
See [PowerDNS documentation on Views](https://doc.powerdns.com/authoritative/views.html) for details on how to setup networks and views for these variants.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func (dsp *powerdnsProvider) getDiff2DomainCorrections(dc *models.DomainConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
domainVariant := GetVariantName(dc.Name, dc.Metadata[models.DomainTag])
|
domainVariant := dsp.zoneName(dc.Name, dc.Metadata[models.DomainTag])
|
||||||
|
|
||||||
// only append a Correction if there are any, otherwise causes an error when sending an empty rrset
|
// only append a Correction if there are any, otherwise causes an error when sending an empty rrset
|
||||||
if len(rrDeleteSets) > 0 {
|
if len(rrDeleteSets) > 0 {
|
||||||
|
|
@ -100,14 +100,3 @@ func buildRecordList(change diff2.Change) (records []zones.Record) {
|
||||||
func canonical(fqdn string) string {
|
func canonical(fqdn string) string {
|
||||||
return fqdn + "."
|
return fqdn + "."
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the variant name for powerdns. this is the domain + "." + the tag
|
|
||||||
// so dnscontrol "example.com!internal" becomes powerdns "example.com..internal"
|
|
||||||
// See https://doc.powerdns.com/authoritative/views.html
|
|
||||||
func GetVariantName(domain string, tag string) string {
|
|
||||||
if tag != "" {
|
|
||||||
return canonical(domain) + "." + tag
|
|
||||||
} else {
|
|
||||||
return canonical(domain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func (dsp *powerdnsProvider) GetNameservers(string) ([]*models.Nameserver, error
|
||||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||||
func (dsp *powerdnsProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
|
func (dsp *powerdnsProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
|
||||||
curRecords := models.Records{}
|
curRecords := models.Records{}
|
||||||
domainVariant := GetVariantName(domain, meta[models.DomainTag])
|
domainVariant := dsp.zoneName(domain, meta[models.DomainTag])
|
||||||
zone, err := dsp.client.Zones().GetZone(context.Background(), dsp.ServerName, domainVariant)
|
zone, err := dsp.client.Zones().GetZone(context.Background(), dsp.ServerName, domainVariant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(pdnshttp.ErrNotFound); ok {
|
if _, ok := err.(pdnshttp.ErrNotFound); ok {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
// getDNSSECCorrections returns corrections that update a domain's DNSSEC state.
|
// getDNSSECCorrections returns corrections that update a domain's DNSSEC state.
|
||||||
func (dsp *powerdnsProvider) getDNSSECCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
func (dsp *powerdnsProvider) getDNSSECCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||||
domainVariant := GetVariantName(dc.Name, dc.Metadata[models.DomainTag])
|
domainVariant := dsp.zoneName(dc.Name, dc.Metadata[models.DomainTag])
|
||||||
zoneCryptokeys, getErr := dsp.client.Cryptokeys().ListCryptokeys(context.Background(), dsp.ServerName, domainVariant)
|
zoneCryptokeys, getErr := dsp.client.Cryptokeys().ListCryptokeys(context.Background(), dsp.ServerName, domainVariant)
|
||||||
if getErr != nil {
|
if getErr != nil {
|
||||||
if _, ok := getErr.(pdnshttp.ErrNotFound); ok {
|
if _, ok := getErr.(pdnshttp.ErrNotFound); ok {
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,21 @@ type powerdnsProvider struct {
|
||||||
DNSSecOnCreate bool `json:"dnssec_on_create"`
|
DNSSecOnCreate bool `json:"dnssec_on_create"`
|
||||||
ZoneKind zones.ZoneKind `json:"zone_kind"`
|
ZoneKind zones.ZoneKind `json:"zone_kind"`
|
||||||
SOAEditAPI zones.ZoneSOAEditAPI `json:"soa_edit_api,omitempty"`
|
SOAEditAPI zones.ZoneSOAEditAPI `json:"soa_edit_api,omitempty"`
|
||||||
|
UseViews bool `json:"use_views,omitempty"`
|
||||||
|
|
||||||
nameservers []*models.Nameserver
|
nameservers []*models.Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build the variant name for powerdns. this is the domain + "." + the tag
|
||||||
|
// so dnscontrol "example.com!internal" becomes powerdns "example.com..internal"
|
||||||
|
// See https://doc.powerdns.com/authoritative/views.html
|
||||||
|
func (dsp *powerdnsProvider) zoneName(domain string, tag string) string {
|
||||||
|
if dsp.UseViews && tag == "" {
|
||||||
|
return canonical(domain) + "." + tag
|
||||||
|
}
|
||||||
|
return canonical(domain)
|
||||||
|
}
|
||||||
|
|
||||||
// newDSP initializes a PowerDNS DNSServiceProvider.
|
// newDSP initializes a PowerDNS DNSServiceProvider.
|
||||||
func newDSP(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
func newDSP(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
||||||
dsp := &powerdnsProvider{}
|
dsp := &powerdnsProvider{}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue