mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
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:
+9
-4
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user