mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-03 19:54:22 +08:00
depreacte ingress dns usage on client configs
This commit is contained in:
parent
b043ed8cb7
commit
885b36810b
5 changed files with 94 additions and 49 deletions
|
@ -133,6 +133,12 @@ func getExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
gwNode, err := logic.GetNodeByID(client.IngressGatewayID)
|
||||
if err != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
logic.SetDNSOnWgConfig(&gwNode, &client)
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(client)
|
||||
|
@ -288,39 +294,11 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
logic.SetDNSOnWgConfig(&gwnode, &client)
|
||||
defaultDNS := ""
|
||||
if client.DNS != "" {
|
||||
defaultDNS = "DNS = " + client.DNS
|
||||
} else if gwnode.IngressDNS != "" {
|
||||
defaultDNS = "DNS = " + gwnode.IngressDNS
|
||||
}
|
||||
if client.DNS == "" {
|
||||
if len(network.NameServers) > 0 {
|
||||
if defaultDNS == "" {
|
||||
defaultDNS = "DNS = " + strings.Join(network.NameServers, ",")
|
||||
} else {
|
||||
defaultDNS += "," + strings.Join(network.NameServers, ",")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// if servercfg.GetManageDNS() {
|
||||
// if gwnode.Address6.IP != nil {
|
||||
// if defaultDNS == "" {
|
||||
// defaultDNS = "DNS = " + gwnode.Address6.IP.String()
|
||||
// } else {
|
||||
// defaultDNS = defaultDNS + ", " + gwnode.Address6.IP.String()
|
||||
// }
|
||||
// }
|
||||
// if gwnode.Address.IP != nil {
|
||||
// if defaultDNS == "" {
|
||||
// defaultDNS = "DNS = " + gwnode.Address.IP.String()
|
||||
// } else {
|
||||
// defaultDNS = defaultDNS + ", " + gwnode.Address.IP.String()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
defaultMTU := 1420
|
||||
if host.MTU != 0 {
|
||||
|
@ -745,18 +723,10 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
extclient.Tags = make(map[models.TagID]struct{})
|
||||
// extclient.Tags[models.TagID(fmt.Sprintf("%s.%s", extclient.Network,
|
||||
// models.RemoteAccessTagName))] = struct{}{}
|
||||
// set extclient dns to ingressdns if extclient dns is not explicitly set
|
||||
if (extclient.DNS == "") && (node.IngressDNS != "") {
|
||||
network, _ := logic.GetNetwork(node.Network)
|
||||
dns := node.IngressDNS
|
||||
if len(network.NameServers) > 0 {
|
||||
if dns == "" {
|
||||
dns = strings.Join(network.NameServers, ",")
|
||||
} else {
|
||||
dns += "," + strings.Join(network.NameServers, ",")
|
||||
}
|
||||
|
||||
}
|
||||
// set extclient dns to ingressdns if extclient dns is not explicitly
|
||||
gwDNS := logic.GetGwDNS(&node)
|
||||
if (extclient.DNS == "") && (gwDNS != "") {
|
||||
dns := gwDNS
|
||||
extclient.DNS = dns
|
||||
}
|
||||
host, err := logic.GetHost(node.HostID.String())
|
||||
|
|
39
logic/dns.go
39
logic/dns.go
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/schema"
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
"github.com/txn2/txeh"
|
||||
)
|
||||
|
||||
|
@ -172,6 +173,44 @@ func GetNodeDNS(network string) ([]models.DNSEntry, error) {
|
|||
return dns, nil
|
||||
}
|
||||
|
||||
func GetGwDNS(node *models.Node) string {
|
||||
if !servercfg.GetManageDNS() {
|
||||
return ""
|
||||
}
|
||||
h, err := GetHost(node.HostID.String())
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if h.DNS != "yes" {
|
||||
return ""
|
||||
}
|
||||
dns := []string{}
|
||||
if node.Address.IP != nil {
|
||||
dns = append(dns, node.Address.IP.String())
|
||||
}
|
||||
if node.Address6.IP != nil {
|
||||
dns = append(dns, node.Address6.IP.String())
|
||||
}
|
||||
return strings.Join(dns, ",")
|
||||
|
||||
}
|
||||
|
||||
func SetDNSOnWgConfig(gwNode *models.Node, extclient *models.ExtClient) {
|
||||
if extclient.RemoteAccessClientID == "" {
|
||||
if extclient.DNS == "" {
|
||||
extclient.DNS = GetGwDNS(gwNode)
|
||||
}
|
||||
return
|
||||
}
|
||||
ns := GetNameserversForNode(gwNode)
|
||||
for _, nsI := range ns {
|
||||
if nsI.MatchDomain == "." {
|
||||
extclient.DNS = GetGwDNS(gwNode)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetCustomDNS - gets the custom DNS of a network
|
||||
func GetCustomDNS(network string) ([]models.DNSEntry, error) {
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ func migrateNameservers() {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, netI := range nets {
|
||||
if len(netI.NameServers) > 0 {
|
||||
ns := schema.Nameserver{
|
||||
|
@ -59,6 +60,7 @@ func migrateNameservers() {
|
|||
Tags: datatypes.JSONMap{
|
||||
"*": struct{}{},
|
||||
},
|
||||
Nodes: make(datatypes.JSONMap),
|
||||
Status: true,
|
||||
CreatedBy: user.UserName,
|
||||
}
|
||||
|
@ -70,6 +72,44 @@ func migrateNameservers() {
|
|||
logic.SaveNetwork(&netI)
|
||||
}
|
||||
}
|
||||
nodes, _ := logic.GetAllNodes()
|
||||
for _, node := range nodes {
|
||||
if !node.IsGw {
|
||||
continue
|
||||
}
|
||||
if node.IngressDNS != "" {
|
||||
if (node.Address.IP != nil && node.Address.IP.String() == node.IngressDNS) ||
|
||||
(node.Address6.IP != nil && node.Address6.IP.String() == node.IngressDNS) {
|
||||
continue
|
||||
}
|
||||
if node.IngressDNS == "8.8.8.8" || node.IngressDNS == "1.1.1.1" || node.IngressDNS == "9.9.9.9" {
|
||||
continue
|
||||
}
|
||||
h, err := logic.GetHost(node.HostID.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ns := schema.Nameserver{
|
||||
ID: uuid.NewString(),
|
||||
Name: fmt.Sprintf("%s gw nameservers", h.Name),
|
||||
NetworkID: node.Network,
|
||||
Servers: []string{node.IngressDNS},
|
||||
MatchAll: true,
|
||||
MatchDomains: []string{"."},
|
||||
Nodes: datatypes.JSONMap{
|
||||
node.ID.String(): struct{}{},
|
||||
},
|
||||
Tags: make(datatypes.JSONMap),
|
||||
Status: true,
|
||||
CreatedBy: user.UserName,
|
||||
}
|
||||
ns.Create(db.WithContext(context.TODO()))
|
||||
node.IngressDNS = ""
|
||||
logic.UpsertNode(&node)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// removes if any stale configurations from previous run.
|
||||
|
|
|
@ -1171,11 +1171,7 @@ func getRemoteAccessGatewayConf(w http.ResponseWriter, r *http.Request) {
|
|||
userConf.OwnerID = user.UserName
|
||||
userConf.RemoteAccessClientID = req.RemoteAccessClientID
|
||||
userConf.IngressGatewayID = node.ID.String()
|
||||
|
||||
// set extclient dns to ingressdns if extclient dns is not explicitly set
|
||||
if (userConf.DNS == "") && (node.IngressDNS != "") {
|
||||
userConf.DNS = node.IngressDNS
|
||||
}
|
||||
logic.SetDNSOnWgConfig(&node, &userConf)
|
||||
|
||||
userConf.Network = node.Network
|
||||
host, err := logic.GetHost(node.HostID.String())
|
||||
|
@ -1301,9 +1297,8 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
gws := userGws[node.Network]
|
||||
if extClient.DNS == "" {
|
||||
extClient.DNS = node.IngressDNS
|
||||
}
|
||||
|
||||
logic.SetDNSOnWgConfig(&node, &extClient)
|
||||
|
||||
extClient.IngressGatewayEndpoint = utils.GetExtClientEndpoint(
|
||||
host.EndpointIP,
|
||||
|
|
|
@ -17,6 +17,7 @@ type Nameserver struct {
|
|||
MatchAll bool `gorm:"match_all" json:"match_all"`
|
||||
MatchDomains datatypes.JSONSlice[string] `gorm:"match_domains" json:"match_domains"`
|
||||
Tags datatypes.JSONMap `gorm:"tags" json:"tags"`
|
||||
Nodes datatypes.JSONMap `gorm:"nodes" json:"nodes"`
|
||||
Status bool `gorm:"status" json:"status"`
|
||||
CreatedBy string `gorm:"created_by" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"created_at" json:"created_at"`
|
||||
|
|
Loading…
Add table
Reference in a new issue