mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-10-31 20:22:44 +08:00 
			
		
		
		
	NET-1075: Endpoint detection server config (#2876)
* add config for endpoint detection * add config to netmaker env file * fix config value check for endpoint detection
This commit is contained in:
		| @@ -92,6 +92,7 @@ type ServerConfig struct { | |||||||
| 	JwtValidityDuration        time.Duration `yaml:"jwt_validity_duration"` | 	JwtValidityDuration        time.Duration `yaml:"jwt_validity_duration"` | ||||||
| 	RacAutoDisable             bool          `yaml:"rac_auto_disable"` | 	RacAutoDisable             bool          `yaml:"rac_auto_disable"` | ||||||
| 	CacheEnabled               string        `yaml:"caching_enabled"` | 	CacheEnabled               string        `yaml:"caching_enabled"` | ||||||
|  | 	EndpointDetection          bool          `json:"endpoint_detection"` | ||||||
| 	AllowedEmailDomains        string        `yaml:"allowed_email_domains"` | 	AllowedEmailDomains        string        `yaml:"allowed_email_domains"` | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -134,17 +134,18 @@ func pull(w http.ResponseWriter, r *http.Request) { | |||||||
|  |  | ||||||
| 	serverConf.TrafficKey = key | 	serverConf.TrafficKey = key | ||||||
| 	response := models.HostPull{ | 	response := models.HostPull{ | ||||||
| 		Host:            *host, | 		Host:              *host, | ||||||
| 		Nodes:           logic.GetHostNodes(host), | 		Nodes:             logic.GetHostNodes(host), | ||||||
| 		ServerConfig:    serverConf, | 		ServerConfig:      serverConf, | ||||||
| 		Peers:           hPU.Peers, | 		Peers:             hPU.Peers, | ||||||
| 		PeerIDs:         hPU.PeerIDs, | 		PeerIDs:           hPU.PeerIDs, | ||||||
| 		HostNetworkInfo: hPU.HostNetworkInfo, | 		HostNetworkInfo:   hPU.HostNetworkInfo, | ||||||
| 		EgressRoutes:    hPU.EgressRoutes, | 		EgressRoutes:      hPU.EgressRoutes, | ||||||
| 		FwUpdate:        hPU.FwUpdate, | 		FwUpdate:          hPU.FwUpdate, | ||||||
| 		ChangeDefaultGw: hPU.ChangeDefaultGw, | 		ChangeDefaultGw:   hPU.ChangeDefaultGw, | ||||||
| 		DefaultGwIp:     hPU.DefaultGwIp, | 		DefaultGwIp:       hPU.DefaultGwIp, | ||||||
| 		IsInternetGw:    hPU.IsInternetGw, | 		IsInternetGw:      hPU.IsInternetGw, | ||||||
|  | 		EndpointDetection: servercfg.IsEndpointDetectionEnabled(), | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	logger.Log(1, hostID, "completed a pull") | 	logger.Log(1, hostID, "completed a pull") | ||||||
|   | |||||||
| @@ -72,10 +72,11 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N | |||||||
| 		FwUpdate: models.FwUpdate{ | 		FwUpdate: models.FwUpdate{ | ||||||
| 			EgressInfo: make(map[string]models.EgressInfo), | 			EgressInfo: make(map[string]models.EgressInfo), | ||||||
| 		}, | 		}, | ||||||
| 		PeerIDs:         make(models.PeerMap, 0), | 		PeerIDs:           make(models.PeerMap, 0), | ||||||
| 		Peers:           []wgtypes.PeerConfig{}, | 		Peers:             []wgtypes.PeerConfig{}, | ||||||
| 		NodePeers:       []wgtypes.PeerConfig{}, | 		NodePeers:         []wgtypes.PeerConfig{}, | ||||||
| 		HostNetworkInfo: models.HostInfoMap{}, | 		HostNetworkInfo:   models.HostInfoMap{}, | ||||||
|  | 		EndpointDetection: servercfg.IsEndpointDetectionEnabled(), | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	slog.Debug("peer update for host", "hostId", host.ID.String()) | 	slog.Debug("peer update for host", "hostId", host.ID.String()) | ||||||
|   | |||||||
| @@ -8,21 +8,22 @@ import ( | |||||||
|  |  | ||||||
| // HostPeerUpdate - struct for host peer updates | // HostPeerUpdate - struct for host peer updates | ||||||
| type HostPeerUpdate struct { | type HostPeerUpdate struct { | ||||||
| 	Host            Host                 `json:"host" bson:"host" yaml:"host"` | 	Host              Host                 `json:"host" bson:"host" yaml:"host"` | ||||||
| 	ChangeDefaultGw bool                 `json:"change_default_gw"` | 	ChangeDefaultGw   bool                 `json:"change_default_gw"` | ||||||
| 	DefaultGwIp     net.IP               `json:"default_gw_ip"` | 	DefaultGwIp       net.IP               `json:"default_gw_ip"` | ||||||
| 	IsInternetGw    bool                 `json:"is_inet_gw"` | 	IsInternetGw      bool                 `json:"is_inet_gw"` | ||||||
| 	NodeAddrs       []net.IPNet          `json:"nodes_addrs" yaml:"nodes_addrs"` | 	NodeAddrs         []net.IPNet          `json:"nodes_addrs" yaml:"nodes_addrs"` | ||||||
| 	Server          string               `json:"server" bson:"server" yaml:"server"` | 	Server            string               `json:"server" bson:"server" yaml:"server"` | ||||||
| 	ServerVersion   string               `json:"serverversion" bson:"serverversion" yaml:"serverversion"` | 	ServerVersion     string               `json:"serverversion" bson:"serverversion" yaml:"serverversion"` | ||||||
| 	ServerAddrs     []ServerAddr         `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"` | 	ServerAddrs       []ServerAddr         `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"` | ||||||
| 	NodePeers       []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"` | 	NodePeers         []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"` | ||||||
| 	Peers           []wgtypes.PeerConfig | 	Peers             []wgtypes.PeerConfig | ||||||
| 	PeerIDs         PeerMap               `json:"peerids" bson:"peerids" yaml:"peerids"` | 	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"` | 	HostNetworkInfo   HostInfoMap           `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"` | ||||||
| 	EgressRoutes    []EgressNetworkRoutes `json:"egress_network_routes"` | 	EgressRoutes      []EgressNetworkRoutes `json:"egress_network_routes"` | ||||||
| 	FwUpdate        FwUpdate              `json:"fw_update"` | 	FwUpdate          FwUpdate              `json:"fw_update"` | ||||||
| 	ReplacePeers    bool                  `json:"replace_peers"` | 	ReplacePeers      bool                  `json:"replace_peers"` | ||||||
|  | 	EndpointDetection bool                  `json:"endpoint_detection"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // IngressInfo - struct for ingress info | // IngressInfo - struct for ingress info | ||||||
|   | |||||||
| @@ -232,17 +232,18 @@ type TrafficKeys struct { | |||||||
|  |  | ||||||
| // HostPull - response of a host's pull | // HostPull - response of a host's pull | ||||||
| type HostPull struct { | type HostPull struct { | ||||||
| 	Host            Host                  `json:"host" yaml:"host"` | 	Host              Host                  `json:"host" yaml:"host"` | ||||||
| 	Nodes           []Node                `json:"nodes" yaml:"nodes"` | 	Nodes             []Node                `json:"nodes" yaml:"nodes"` | ||||||
| 	Peers           []wgtypes.PeerConfig  `json:"peers" yaml:"peers"` | 	Peers             []wgtypes.PeerConfig  `json:"peers" yaml:"peers"` | ||||||
| 	ServerConfig    ServerConfig          `json:"server_config" yaml:"server_config"` | 	ServerConfig      ServerConfig          `json:"server_config" yaml:"server_config"` | ||||||
| 	PeerIDs         PeerMap               `json:"peer_ids,omitempty" yaml:"peer_ids,omitempty"` | 	PeerIDs           PeerMap               `json:"peer_ids,omitempty" yaml:"peer_ids,omitempty"` | ||||||
| 	HostNetworkInfo HostInfoMap           `json:"host_network_info,omitempty"  yaml:"host_network_info,omitempty"` | 	HostNetworkInfo   HostInfoMap           `json:"host_network_info,omitempty"  yaml:"host_network_info,omitempty"` | ||||||
| 	EgressRoutes    []EgressNetworkRoutes `json:"egress_network_routes"` | 	EgressRoutes      []EgressNetworkRoutes `json:"egress_network_routes"` | ||||||
| 	FwUpdate        FwUpdate              `json:"fw_update"` | 	FwUpdate          FwUpdate              `json:"fw_update"` | ||||||
| 	ChangeDefaultGw bool                  `json:"change_default_gw"` | 	ChangeDefaultGw   bool                  `json:"change_default_gw"` | ||||||
| 	DefaultGwIp     net.IP                `json:"default_gw_ip"` | 	DefaultGwIp       net.IP                `json:"default_gw_ip"` | ||||||
| 	IsInternetGw    bool                  `json:"is_inet_gw"` | 	IsInternetGw      bool                  `json:"is_inet_gw"` | ||||||
|  | 	EndpointDetection bool                  `json:"endpoint_detection"` | ||||||
| } | } | ||||||
|  |  | ||||||
| type DefaultGwInfo struct { | type DefaultGwInfo struct { | ||||||
|   | |||||||
| @@ -72,4 +72,6 @@ JWT_VALIDITY_DURATION=43200 | |||||||
| # Auto disable a user's connecteds clients bassed on JWT token expiration | # Auto disable a user's connecteds clients bassed on JWT token expiration | ||||||
| RAC_AUTO_DISABLE=true | RAC_AUTO_DISABLE=true | ||||||
| # if turned on data will be cached on to improve performance significantly (IMPORTANT: If HA set to `false` ) | # if turned on data will be cached on to improve performance significantly (IMPORTANT: If HA set to `false` ) | ||||||
| CACHING_ENABLED=true | CACHING_ENABLED=true | ||||||
|  | # if turned on netclient checks if peers are reachable over private/LAN address, and choose that as peer endpoint | ||||||
|  | ENDPOINT_DETECTION=true | ||||||
|   | |||||||
| @@ -249,7 +249,7 @@ save_config() { ( | |||||||
| 		"INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT" | 		"INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT" | ||||||
| 		"CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "VERBOSITY" | 		"CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "VERBOSITY" | ||||||
| 		"DEBUG_MODE"  "REST_BACKEND" "DISABLE_REMOTE_IP_CHECK" "TELEMETRY" "ALLOWED_EMAIL_DOMAINS" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" | 		"DEBUG_MODE"  "REST_BACKEND" "DISABLE_REMOTE_IP_CHECK" "TELEMETRY" "ALLOWED_EMAIL_DOMAINS" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" | ||||||
| 		"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT" "JWT_VALIDITY_DURATION" "RAC_AUTO_DISABLE" "CACHING_ENABLED") | 		"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT" "JWT_VALIDITY_DURATION" "RAC_AUTO_DISABLE" "CACHING_ENABLED" "ENDPOINT_DETECTION") | ||||||
| 	for name in "${toCopy[@]}"; do | 	for name in "${toCopy[@]}"; do | ||||||
| 		save_config_item $name "${!name}" | 		save_config_item $name "${!name}" | ||||||
| 	done | 	done | ||||||
|   | |||||||
| @@ -674,6 +674,17 @@ func DeployedByOperator() bool { | |||||||
| 	return config.Config.Server.DeployedByOperator | 	return config.Config.Server.DeployedByOperator | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // IsEndpointDetectionEnabled - returns true if endpoint detection enabled | ||||||
|  | func IsEndpointDetectionEnabled() bool { | ||||||
|  | 	var enabled = true //default | ||||||
|  | 	if os.Getenv("ENDPOINT_DETECTION") != "" { | ||||||
|  | 		enabled = os.Getenv("ENDPOINT_DETECTION") == "true" | ||||||
|  | 	} else { | ||||||
|  | 		enabled = config.Config.Server.EndpointDetection | ||||||
|  | 	} | ||||||
|  | 	return enabled | ||||||
|  | } | ||||||
|  |  | ||||||
| // GetEnvironment returns the environment the server is running in (e.g. dev, staging, prod...) | // GetEnvironment returns the environment the server is running in (e.g. dev, staging, prod...) | ||||||
| func GetEnvironment() string { | func GetEnvironment() string { | ||||||
| 	if env := os.Getenv("ENVIRONMENT"); env != "" { | 	if env := os.Getenv("ENVIRONMENT"); env != "" { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Abhishek K
					Abhishek K