From 916694b2cf20e860925642d4c980557840f63dea Mon Sep 17 00:00:00 2001 From: Abhishek K <32607604+abhishek9686@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:37:43 +0400 Subject: [PATCH] NET-664: Local Connections improvements (#2651) * deprecate endpoint detection form config * add peer network info to pull --- controllers/hosts.go | 11 ++++++----- logic/peers.go | 2 -- models/mqtt.go | 23 +++++++++++------------ models/structs.go | 11 ++++++----- scripts/netmaker.default.env | 1 - scripts/nm-quick.sh | 2 +- scripts/nm-upgrade.sh | 2 +- servercfg/serverconf.go | 16 ---------------- 8 files changed, 25 insertions(+), 43 deletions(-) diff --git a/controllers/hosts.go b/controllers/hosts.go index 3274c359..5babd54a 100644 --- a/controllers/hosts.go +++ b/controllers/hosts.go @@ -123,11 +123,12 @@ func pull(w http.ResponseWriter, r *http.Request) { serverConf.TrafficKey = key response := models.HostPull{ - Host: *host, - Nodes: logic.GetHostNodes(host), - ServerConfig: serverConf, - Peers: hPU.Peers, - PeerIDs: hPU.PeerIDs, + Host: *host, + Nodes: logic.GetHostNodes(host), + ServerConfig: serverConf, + Peers: hPU.Peers, + PeerIDs: hPU.PeerIDs, + HostNetworkInfo: hPU.HostNetworkInfo, } logger.Log(1, hostID, "completed a pull") diff --git a/logic/peers.go b/logic/peers.go index aa347576..9f86fd2d 100644 --- a/logic/peers.go +++ b/logic/peers.go @@ -38,8 +38,6 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N HostNetworkInfo: models.HostInfoMap{}, } - // endpoint detection always comes from the server - hostPeerUpdate.EndpointDetection = servercfg.EndpointDetectionEnabled() slog.Debug("peer update for host", "hostId", host.ID.String()) peerIndexMap := make(map[string]int) for _, nodeID := range host.Nodes { diff --git a/models/mqtt.go b/models/mqtt.go index b50e8cd2..7c6072af 100644 --- a/models/mqtt.go +++ b/models/mqtt.go @@ -8,18 +8,17 @@ import ( // HostPeerUpdate - struct for host peer updates type HostPeerUpdate struct { - Host Host `json:"host" bson:"host" yaml:"host"` - NodeAddrs []net.IPNet `json:"nodes_addrs" yaml:"nodes_addrs"` - Server string `json:"server" bson:"server" yaml:"server"` - ServerVersion string `json:"serverversion" bson:"serverversion" yaml:"serverversion"` - ServerAddrs []ServerAddr `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"` - NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"` - Peers []wgtypes.PeerConfig - PeerIDs PeerMap `json:"peerids" bson:"peerids" yaml:"peerids"` - EndpointDetection bool `json:"endpointdetection" yaml:"endpointdetection"` - HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"` - EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"` - FwUpdate FwUpdate `json:"fw_update"` + Host Host `json:"host" bson:"host" yaml:"host"` + NodeAddrs []net.IPNet `json:"nodes_addrs" yaml:"nodes_addrs"` + Server string `json:"server" bson:"server" yaml:"server"` + ServerVersion string `json:"serverversion" bson:"serverversion" yaml:"serverversion"` + ServerAddrs []ServerAddr `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"` + NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"` + Peers []wgtypes.PeerConfig + PeerIDs PeerMap `json:"peerids" bson:"peerids" yaml:"peerids"` + HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"` + EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"` + FwUpdate FwUpdate `json:"fw_update"` } // IngressInfo - struct for ingress info diff --git a/models/structs.go b/models/structs.go index c67d5eee..906d16cf 100644 --- a/models/structs.go +++ b/models/structs.go @@ -223,11 +223,12 @@ type TrafficKeys struct { // HostPull - response of a host's pull type HostPull struct { - Host Host `json:"host" yaml:"host"` - Nodes []Node `json:"nodes" yaml:"nodes"` - Peers []wgtypes.PeerConfig `json:"peers" yaml:"peers"` - ServerConfig ServerConfig `json:"server_config" yaml:"server_config"` - PeerIDs PeerMap `json:"peer_ids,omitempty" yaml:"peer_ids,omitempty"` + Host Host `json:"host" yaml:"host"` + Nodes []Node `json:"nodes" yaml:"nodes"` + Peers []wgtypes.PeerConfig `json:"peers" yaml:"peers"` + ServerConfig ServerConfig `json:"server_config" yaml:"server_config"` + PeerIDs PeerMap `json:"peer_ids,omitempty" yaml:"peer_ids,omitempty"` + HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" yaml:"host_network_info,omitempty"` } // NodeGet - struct for a single node get response diff --git a/scripts/netmaker.default.env b/scripts/netmaker.default.env index fcacaeaa..247791d4 100644 --- a/scripts/netmaker.default.env +++ b/scripts/netmaker.default.env @@ -19,7 +19,6 @@ NETMAKER_TENANT_ID= LICENSE_KEY= SERVER_IMAGE_TAG= UI_IMAGE_TAG= -NETCLIENT_ENDPOINT_DETECTION=disabled # used for HA - identifies this server vs other servers NODE_ID=netmaker-server-1 METRICS_EXPORTER=off diff --git a/scripts/nm-quick.sh b/scripts/nm-quick.sh index dc9c2b32..7e24696e 100755 --- a/scripts/nm-quick.sh +++ b/scripts/nm-quick.sh @@ -309,7 +309,7 @@ save_config() { ( "INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT" "CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "STUN_PORT" "VERBOSITY" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND" - "DISABLE_REMOTE_IP_CHECK" "NETCLIENT_ENDPOINT_DETECTION" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" + "DISABLE_REMOTE_IP_CHECK" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" "FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT" "JWT_VALIDITY_DURATION" "RAC_AUTO_DISABLE") for name in "${toCopy[@]}"; do save_config_item $name "${!name}" diff --git a/scripts/nm-upgrade.sh b/scripts/nm-upgrade.sh index 3a62bc4f..8dcb7bcd 100755 --- a/scripts/nm-upgrade.sh +++ b/scripts/nm-upgrade.sh @@ -179,7 +179,7 @@ save_config() { ( "INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT" "CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "STUN_PORT" "VERBOSITY" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND" - "DISABLE_REMOTE_IP_CHECK" "NETCLIENT_ENDPOINT_DETECTION" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" + "DISABLE_REMOTE_IP_CHECK" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" "FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT" "JWT_VALIDITY_DURATION" "RAC_AUTO_DISABLE") for name in "${toCopy[@]}"; do save_config_item $name "${!name}" diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index a7347aeb..7bac8ede 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -53,11 +53,6 @@ func GetServerConfig() config.ServerConfig { } else { cfg.NetclientAutoUpdate = "disabled" } - if EndpointDetectionEnabled() { - cfg.NetclientEndpointDetection = "enabled" - } else { - cfg.NetclientEndpointDetection = "disabled" - } if IsRestBackend() { cfg.RestBackend = "on" } @@ -405,17 +400,6 @@ func AutoUpdateEnabled() bool { return true } -// EndpointDetectionEnabled returns a boolean indicating whether netclient endpoint detection is enabled or disabled -// default is enabled -func EndpointDetectionEnabled() bool { - if os.Getenv("NETCLIENT_ENDPOINT_DETECTION") == "disabled" { - return false - } else if config.Config.Server.NetclientEndpointDetection == "disabled" { - return false - } - return true -} - // IsDNSMode - should it run with DNS func IsDNSMode() bool { isdns := true