Merge pull request #8173 from yousong/bugfix/yousong-dns-strict-sub

dns: isMyDomain: match only strict subdomain of dns_domain
This commit is contained in:
yunion-ci-robot
2020-09-30 16:32:48 +08:00
committed by GitHub
2 changed files with 14 additions and 4 deletions
+9 -4
View File
@@ -87,7 +87,8 @@ type SRegionDNS struct {
Region string
K8sSkip bool
K8sManager *k8s.SKubeClusterManager
K8sManager *k8s.SKubeClusterManager
primaryZoneLabelCount int
}
func New() *SRegionDNS {
@@ -402,9 +403,13 @@ func (r *SRegionDNS) queryLocalDnsRecords(req *recordRequest) (recs []msg.Servic
}
func (r *SRegionDNS) isMyDomain(req *recordRequest) bool {
zones := []string{fmt.Sprintf("%s.", r.PrimaryZone)}
zone := plugin.Zones(zones).Matches(req.state.Name())
if zone != "" {
qname := req.state.Name()
qnameLabelCount := dns.CountLabel(qname)
if qnameLabelCount <= r.primaryZoneLabelCount {
return false
}
matched := dns.CompareDomainName(r.PrimaryZone, qname)
if matched == r.primaryZoneLabelCount {
return true
}
return false
+5
View File
@@ -21,6 +21,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/mholt/caddy"
"github.com/miekg/dns"
"yunion.io/x/pkg/util/regutils"
)
@@ -44,6 +45,10 @@ func setup(c *caddy.Controller) error {
if !regutils.MatchDomainName(rDNS.PrimaryZone) {
return fmt.Errorf("dns_domain %q invalid", rDNS.PrimaryZone)
}
if r := rDNS.PrimaryZone[len(rDNS.PrimaryZone)-1]; r != '.' {
rDNS.PrimaryZone += "."
}
rDNS.primaryZoneLabelCount = dns.CountLabel(rDNS.PrimaryZone)
err = rDNS.initDB(c)
if err != nil {