fix: close record repair and verification gaps

This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 9251c85fd8
commit adff599e08
27 files changed
+787 -153

No files matched your search

+46 -3
View File
@@ -162,6 +162,10 @@ func (changes zoneChanges) empty() bool {
return len(changes.Creates)+len(changes.Updates)+len(changes.Deletes) == 0 && changes.SOAUpdate == nil && !changes.ManageSerial
}
func (changes zoneChanges) deletesOnly() bool {
return len(changes.Deletes) > 0 && len(changes.Creates)+len(changes.Updates) == 0 && changes.SOAUpdate == nil && !changes.ManageSerial
}
func (changes zoneChanges) finalRows(rows []recordRow) []recordRow {
updates := make(map[int64]recordRow)
deletes := make(map[int64]bool)
@@ -192,8 +196,22 @@ func validateZoneChanges(zone string, current []recordRow, changes zoneChanges)
before := summarizeZone(current)
after := summarizeZone(result)
problems, warnings = zoneRuleProblems(zone, result, after, true)
repair := len(after.soa) != 0 && soaDefects(after.soa) < soaDefects(before.soa)
if repair {
soaRepair := len(after.soa) != 0 && soaDefects(after.soa) < soaDefects(before.soa)
soaOnlyRepair := soaRepair && slices.Equal(nonSOARows(current), nonSOARows(result))
// An existing CNAME can block an SOA repair at the apex. Permit an
// independent repair without permitting normal writes on the broken zone.
cnameRepair := soaDefects(after.soa) != 0 && changes.deletesOnly()
if len(problems) != 0 && (soaOnlyRepair || cnameRepair) {
beforeProblems, _ := zoneRuleProblems(zone, current, before, true)
if soaOnlyRepair || (len(problems) < len(beforeProblems) && deletesOnlyConflictingCNAMEs(changes.Deletes, beforeProblems)) {
existing := make(map[zoneProblem]bool, len(beforeProblems))
for _, p := range beforeProblems {
existing[p] = true
}
problems = slices.DeleteFunc(problems, func(p zoneProblem) bool { return existing[p] })
}
}
if soaRepair {
problems = slices.DeleteFunc(problems, func(p zoneProblem) bool { return p.Code == "soa_multiple" || p.Code == "soa_not_apex" })
}
if len(before.soa) != 0 {
@@ -202,7 +220,7 @@ func validateZoneChanges(zone string, current []recordRow, changes zoneChanges)
afterSOAs[row.ID] = true
}
for _, row := range before.soa {
if !afterSOAs[row.ID] && !repair {
if !afterSOAs[row.ID] && !soaRepair {
problems = append(problems, recordProblem(row, "error", "soa_delete", "SOA may only be deleted with the zone"))
}
}
@@ -219,6 +237,31 @@ func validateZoneChanges(zone string, current []recordRow, changes zoneChanges)
return problems, warnings
}
func nonSOARows(rows []recordRow) []recordRow {
var records []recordRow
for _, row := range rows {
if row.RecordType != "SOA" {
records = append(records, row)
}
}
return records
}
func deletesOnlyConflictingCNAMEs(ids []int64, problems []zoneProblem) bool {
conflicting := make(map[int64]bool)
for _, problem := range problems {
if problem.Type == "CNAME" && (problem.Code == "cname_apex" || problem.Code == "cname_conflict") {
conflicting[problem.RecordID] = true
}
}
for _, id := range ids {
if !conflicting[id] {
return false
}
}
return true
}
func soaDefects(soa []recordRow) int {
defects := len(soa) - 1
for _, row := range soa {