1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00
This commit is contained in:
Tom Limoncelli
2023-03-06 09:55:55 -05:00
parent 1135879d40
commit ebe0726189
7 changed files with 139 additions and 35 deletions

View File

@@ -463,6 +463,7 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
}
for _, d := range config.Domains {
// Check that CNAMES don't have to co-exist with any other records
errs = append(errs, checkCNAMEs(d)...)
// Check that if any advanced record types are used in a domain, every provider for that domain supports them

View File

@@ -104,10 +104,6 @@ func (a *edgeDNSProvider) EnsureZoneExists(domain string) error {
return createZone(domain, a.contractID, a.groupID)
}
func (a *edgeDNSProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) {
}
// GetDomainCorrections return a list of corrections. Each correction is a text string describing the change
// and a function that, if called, will make the change.
// “dnscontrol preview” simply prints the text strings.
@@ -124,10 +120,15 @@ func (a *edgeDNSProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
}
models.PostProcessRecords(existingRecords)
txtutil.SplitSingleLongTxt(dc.Records)
return a.GetZoneRecordsCorrections(dc, existingRecords)
}
func (a *edgeDNSProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) {
var corrections []*models.Correction
var keysToUpdate map[models.RecordKey][]string
var err error
if !diff2.EnableDiff2 {
keysToUpdate, err = (diff.New(dc)).ChangedGroups(existingRecords)
} else {
@@ -245,6 +246,7 @@ func (a *edgeDNSProvider) GetZoneRecords(domain string) (models.Records, error)
if err != nil {
return nil, err
}
txtutil.SplitSingleLongTxt(records)
return records, nil
}

View File

@@ -69,7 +69,6 @@ func New(settings map[string]string, _ json.RawMessage) (providers.DNSServicePro
// GetDomainCorrections returns the corrections for a domain.
func (api *autoDNSProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
var changes []*models.RecordConfig
dc, err := dc.Copy()
if err != nil {
@@ -92,6 +91,13 @@ func (api *autoDNSProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mo
models.PostProcessRecords(existingRecords)
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
return api.GetZoneRecordsCorrections(dc, existingRecords)
}
func (api *autoDNSProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) {
domain := dc.Name
var changes []*models.RecordConfig
var corrections []*models.Correction
if !diff2.EnableDiff2 {

View File

@@ -308,6 +308,7 @@ func (c *axfrddnsProvider) GetZoneRecords(domain string) (models.Records, error)
foundRecords = append(foundRecords, foundDNSSecRecords)
}
txtutil.SplitSingleLongTxt(foundRecords) // Autosplit long TXT records
return foundRecords, nil
}
@@ -348,10 +349,15 @@ func (c *axfrddnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
// Normalize
models.PostProcessRecords(foundRecords)
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
return c.GetZoneRecordsCorrections(dc, foundRecords)
}
func (c *axfrddnsProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, error) {
var corrections []*models.Correction
var create, del, mod diff.Changeset
var err error
if !diff2.EnableDiff2 {
differ := diff.New(dc)
_, create, del, mod, err = differ.IncrementalDiff(foundRecords)

View File

@@ -9,6 +9,7 @@ import (
"time"
aauth "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns"
adns "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns"
"github.com/Azure/go-autorest/autorest/to"
"github.com/StackExchange/dnscontrol/v3/models"
@@ -25,6 +26,8 @@ type azurednsProvider struct {
zones map[string]*adns.Zone
resourceGroup *string
subscriptionID *string
rawRecords map[string][]*armdns.RecordSet
zoneName map[string]string
}
func newAzureDNSDsp(conf map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
@@ -47,7 +50,14 @@ func newAzureDNS(m map[string]string, metadata json.RawMessage) (*azurednsProvid
return nil, recordErr
}
api := &azurednsProvider{zonesClient: zonesClient, recordsClient: recordsClient, resourceGroup: to.StringPtr(rg), subscriptionID: to.StringPtr(subID)}
api := &azurednsProvider{
zonesClient: zonesClient,
recordsClient: recordsClient,
resourceGroup: to.StringPtr(rg),
subscriptionID: to.StringPtr(subID),
rawRecords: map[string][]*armdns.RecordSet{},
zoneName: map[string]string{},
}
err := api.getZones()
if err != nil {
return nil, err
@@ -156,6 +166,9 @@ func (a *azurednsProvider) GetZoneRecords(domain string) (models.Records, error)
if err != nil {
return nil, err
}
models.PostProcessRecords(existingRecords)
return existingRecords, nil
}
@@ -165,21 +178,18 @@ func (a *azurednsProvider) getExistingRecords(domain string) (models.Records, []
return nil, nil, "", errNoExist{domain}
}
zoneName := *zone.Name
records, err := a.fetchRecordSets(zoneName)
rawRecords, err := a.fetchRecordSets(zoneName)
if err != nil {
return nil, nil, "", err
}
var existingRecords models.Records
for _, set := range records {
for _, set := range rawRecords {
existingRecords = append(existingRecords, nativeToRecords(set, zoneName)...)
}
// FIXME(tlim): PostProcessRecords is usually called in GetDomainCorrections.
models.PostProcessRecords(existingRecords)
// FIXME(tlim): The "records" return value is usually stored in RecordConfig.Original.
return existingRecords, records, zoneName, nil
return existingRecords, rawRecords, zoneName, nil
}
func (a *azurednsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
@@ -189,16 +199,24 @@ func (a *azurednsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
return nil, err
}
existingRecords, records, zoneName, err := a.getExistingRecords(dc.Name)
existingRecords, rawRecords, zoneName, err := a.getExistingRecords(dc.Name)
if err != nil {
return nil, err
}
a.rawRecords[dc.Name] = rawRecords
a.zoneName[dc.Name] = zoneName
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
txtutil.SplitSingleLongTxt(existingRecords) // Autosplit long TXT records
return a.GetZoneRecordsCorrections(dc, existingRecords)
}
func (a *azurednsProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) {
var corrections []*models.Correction
if !diff2.EnableDiff2 {
records := a.rawRecords[dc.Name]
zoneName := a.zoneName[dc.Name]
differ := diff.New(dc)
namesToUpdate, err := differ.ChangedGroups(existingRecords)
if err != nil {

View File

@@ -204,18 +204,6 @@ func ParseZoneContents(content string, zoneName string, zonefileName string) (mo
func (c *bindProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
dc.Punycode()
comments := make([]string, 0, 5)
comments = append(comments,
fmt.Sprintf("generated with dnscontrol %s", time.Now().Format(time.RFC3339)),
)
if dc.AutoDNSSEC == "on" {
// This does nothing but reminds the user to add the correct
// auto-dnssecc zone statement to named.conf.
// While it is a no-op, it is useful for situations where a zone
// has multiple providers.
comments = append(comments, "Automatic DNSSEC signing requested")
}
c.zonefile = filepath.Join(c.directory,
makeFileName(c.filenameformat, dc.UniqueName, dc.Name, dc.Tag))
@@ -224,6 +212,18 @@ func (c *bindProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.
return nil, err
}
// Normalize
models.PostProcessRecords(foundRecords)
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
return c.GetZoneRecordsCorrections(dc, foundRecords)
}
func (c *bindProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, error) {
changes := false
var msg string
// Find the SOA records; use them to make or update the desired SOA.
var foundSoa *models.RecordConfig
for _, r := range foundRecords {
@@ -247,13 +247,6 @@ func (c *bindProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.
*desiredSoa = *soaRec
}
// Normalize
models.PostProcessRecords(foundRecords)
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
changes := false
var msg string
if !diff2.EnableDiff2 {
differ := diff.New(dc)
@@ -293,6 +286,7 @@ func (c *bindProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.
} else {
var msgs []string
var err error
msgs, changes, err = diff2.ByZone(foundRecords, dc, nil)
if err != nil {
return nil, err
@@ -306,6 +300,18 @@ func (c *bindProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.
//fmt.Printf("DEBUG: BIND changes=%v\n", changes)
if changes {
comments := make([]string, 0, 5)
comments = append(comments,
fmt.Sprintf("generated with dnscontrol %s", time.Now().Format(time.RFC3339)),
)
if dc.AutoDNSSEC == "on" {
// This does nothing but reminds the user to add the correct
// auto-dnssecc zone statement to named.conf.
// While it is a no-op, it is useful for situations where a zone
// has multiple providers.
comments = append(comments, "Automatic DNSSEC signing requested")
}
// We only change the serial number if there is a change.
desiredSoa.SoaSerial = nextSerial

View File

@@ -224,6 +224,71 @@ func (c *cloudflareProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
// Therefore, whether the string is 1 octet or thousands, just store it as
// one string in the first element of .TxtStrings.
return c.GetZoneRecordsCorrections(dc, records)
}
func (c *cloudflareProvider) GetZoneRecordsCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
if err := c.preprocessConfig(dc); err != nil {
return nil, err
}
for i := len(records) - 1; i >= 0; i-- {
rec := records[i]
// Delete ignore labels
if labelMatches(dnsutil.TrimDomainName(rec.Original.(cloudflare.DNSRecord).Name, dc.Name), c.ignoredLabels) {
printer.Debugf("ignored_label: %s\n", rec.Original.(cloudflare.DNSRecord).Name)
records = append(records[:i], records[i+1:]...)
}
}
if c.manageRedirects {
prs, err := c.getPageRules(domainID, dc.Name)
//printer.Printf("GET PAGE RULES:\n")
//for i, p := range prs {
// printer.Printf("%03d: %q\n", i, p.GetTargetField())
//}
if err != nil {
return nil, err
}
records = append(records, prs...)
}
if c.manageWorkers {
wrs, err := c.getWorkerRoutes(domainID, dc.Name)
if err != nil {
return nil, err
}
records = append(records, wrs...)
}
for _, rec := range dc.Records {
if rec.Type == "ALIAS" {
rec.Type = "CNAME"
}
// As per CF-API documentation proxied records are always forced to have a TTL of 1.
// When not forcing this property change here, dnscontrol tries each time to update
// the TTL of a record which simply cannot be changed anyway.
if rec.Metadata[metaProxy] != "off" {
rec.TTL = 1
}
if labelMatches(rec.GetLabel(), c.ignoredLabels) {
log.Fatalf("FATAL: dnsconfig contains label that matches ignored_labels: %#v is in %v)\n", rec.GetLabel(), c.ignoredLabels)
}
}
checkNSModifications(dc)
// Normalize
models.PostProcessRecords(records)
//txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
// Don't split.
// Cloudflare's API only supports one TXT string of any non-zero length. No
// multiple strings.
// When serving the DNS record, it splits strings >255 octets into
// individual segments of 255 each. However that is hidden from the API.
// Therefore, whether the string is 1 octet or thousands, just store it as
// one string in the first element of .TxtStrings.
var corrections []*models.Correction
if !diff2.EnableDiff2 {