Skip to content

Commit dccb6b5

Browse files
authored
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
1 parent 80e775d commit dccb6b5

File tree

8 files changed

+61
-43
lines changed

8 files changed

+61
-43
lines changed

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type ServerConfig struct {
9292
JwtValidityDuration time.Duration `yaml:"jwt_validity_duration"`
9393
RacAutoDisable bool `yaml:"rac_auto_disable"`
9494
CacheEnabled string `yaml:"caching_enabled"`
95+
EndpointDetection bool `json:"endpoint_detection"`
9596
AllowedEmailDomains string `yaml:"allowed_email_domains"`
9697
}
9798

controllers/hosts.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,18 @@ func pull(w http.ResponseWriter, r *http.Request) {
134134

135135
serverConf.TrafficKey = key
136136
response := models.HostPull{
137-
Host: *host,
138-
Nodes: logic.GetHostNodes(host),
139-
ServerConfig: serverConf,
140-
Peers: hPU.Peers,
141-
PeerIDs: hPU.PeerIDs,
142-
HostNetworkInfo: hPU.HostNetworkInfo,
143-
EgressRoutes: hPU.EgressRoutes,
144-
FwUpdate: hPU.FwUpdate,
145-
ChangeDefaultGw: hPU.ChangeDefaultGw,
146-
DefaultGwIp: hPU.DefaultGwIp,
147-
IsInternetGw: hPU.IsInternetGw,
137+
Host: *host,
138+
Nodes: logic.GetHostNodes(host),
139+
ServerConfig: serverConf,
140+
Peers: hPU.Peers,
141+
PeerIDs: hPU.PeerIDs,
142+
HostNetworkInfo: hPU.HostNetworkInfo,
143+
EgressRoutes: hPU.EgressRoutes,
144+
FwUpdate: hPU.FwUpdate,
145+
ChangeDefaultGw: hPU.ChangeDefaultGw,
146+
DefaultGwIp: hPU.DefaultGwIp,
147+
IsInternetGw: hPU.IsInternetGw,
148+
EndpointDetection: servercfg.IsEndpointDetectionEnabled(),
148149
}
149150

150151
logger.Log(1, hostID, "completed a pull")

logic/peers.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
7272
FwUpdate: models.FwUpdate{
7373
EgressInfo: make(map[string]models.EgressInfo),
7474
},
75-
PeerIDs: make(models.PeerMap, 0),
76-
Peers: []wgtypes.PeerConfig{},
77-
NodePeers: []wgtypes.PeerConfig{},
78-
HostNetworkInfo: models.HostInfoMap{},
75+
PeerIDs: make(models.PeerMap, 0),
76+
Peers: []wgtypes.PeerConfig{},
77+
NodePeers: []wgtypes.PeerConfig{},
78+
HostNetworkInfo: models.HostInfoMap{},
79+
EndpointDetection: servercfg.IsEndpointDetectionEnabled(),
7980
}
8081

8182
slog.Debug("peer update for host", "hostId", host.ID.String())

models/mqtt.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ import (
88

99
// HostPeerUpdate - struct for host peer updates
1010
type HostPeerUpdate struct {
11-
Host Host `json:"host" bson:"host" yaml:"host"`
12-
ChangeDefaultGw bool `json:"change_default_gw"`
13-
DefaultGwIp net.IP `json:"default_gw_ip"`
14-
IsInternetGw bool `json:"is_inet_gw"`
15-
NodeAddrs []net.IPNet `json:"nodes_addrs" yaml:"nodes_addrs"`
16-
Server string `json:"server" bson:"server" yaml:"server"`
17-
ServerVersion string `json:"serverversion" bson:"serverversion" yaml:"serverversion"`
18-
ServerAddrs []ServerAddr `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"`
19-
NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
20-
Peers []wgtypes.PeerConfig
21-
PeerIDs PeerMap `json:"peerids" bson:"peerids" yaml:"peerids"`
22-
HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"`
23-
EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
24-
FwUpdate FwUpdate `json:"fw_update"`
25-
ReplacePeers bool `json:"replace_peers"`
11+
Host Host `json:"host" bson:"host" yaml:"host"`
12+
ChangeDefaultGw bool `json:"change_default_gw"`
13+
DefaultGwIp net.IP `json:"default_gw_ip"`
14+
IsInternetGw bool `json:"is_inet_gw"`
15+
NodeAddrs []net.IPNet `json:"nodes_addrs" yaml:"nodes_addrs"`
16+
Server string `json:"server" bson:"server" yaml:"server"`
17+
ServerVersion string `json:"serverversion" bson:"serverversion" yaml:"serverversion"`
18+
ServerAddrs []ServerAddr `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"`
19+
NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
20+
Peers []wgtypes.PeerConfig
21+
PeerIDs PeerMap `json:"peerids" bson:"peerids" yaml:"peerids"`
22+
HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"`
23+
EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
24+
FwUpdate FwUpdate `json:"fw_update"`
25+
ReplacePeers bool `json:"replace_peers"`
26+
EndpointDetection bool `json:"endpoint_detection"`
2627
}
2728

2829
// IngressInfo - struct for ingress info

models/structs.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,18 @@ type TrafficKeys struct {
232232

233233
// HostPull - response of a host's pull
234234
type HostPull struct {
235-
Host Host `json:"host" yaml:"host"`
236-
Nodes []Node `json:"nodes" yaml:"nodes"`
237-
Peers []wgtypes.PeerConfig `json:"peers" yaml:"peers"`
238-
ServerConfig ServerConfig `json:"server_config" yaml:"server_config"`
239-
PeerIDs PeerMap `json:"peer_ids,omitempty" yaml:"peer_ids,omitempty"`
240-
HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" yaml:"host_network_info,omitempty"`
241-
EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
242-
FwUpdate FwUpdate `json:"fw_update"`
243-
ChangeDefaultGw bool `json:"change_default_gw"`
244-
DefaultGwIp net.IP `json:"default_gw_ip"`
245-
IsInternetGw bool `json:"is_inet_gw"`
235+
Host Host `json:"host" yaml:"host"`
236+
Nodes []Node `json:"nodes" yaml:"nodes"`
237+
Peers []wgtypes.PeerConfig `json:"peers" yaml:"peers"`
238+
ServerConfig ServerConfig `json:"server_config" yaml:"server_config"`
239+
PeerIDs PeerMap `json:"peer_ids,omitempty" yaml:"peer_ids,omitempty"`
240+
HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" yaml:"host_network_info,omitempty"`
241+
EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
242+
FwUpdate FwUpdate `json:"fw_update"`
243+
ChangeDefaultGw bool `json:"change_default_gw"`
244+
DefaultGwIp net.IP `json:"default_gw_ip"`
245+
IsInternetGw bool `json:"is_inet_gw"`
246+
EndpointDetection bool `json:"endpoint_detection"`
246247
}
247248

248249
type DefaultGwInfo struct {

scripts/netmaker.default.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ JWT_VALIDITY_DURATION=43200
7272
# Auto disable a user's connecteds clients bassed on JWT token expiration
7373
RAC_AUTO_DISABLE=true
7474
# if turned on data will be cached on to improve performance significantly (IMPORTANT: If HA set to `false` )
75-
CACHING_ENABLED=true
75+
CACHING_ENABLED=true
76+
# if turned on netclient checks if peers are reachable over private/LAN address, and choose that as peer endpoint
77+
ENDPOINT_DETECTION=true

scripts/nm-quick.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ save_config() { (
249249
"INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT"
250250
"CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "VERBOSITY"
251251
"DEBUG_MODE" "REST_BACKEND" "DISABLE_REMOTE_IP_CHECK" "TELEMETRY" "ALLOWED_EMAIL_DOMAINS" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET"
252-
"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT" "JWT_VALIDITY_DURATION" "RAC_AUTO_DISABLE" "CACHING_ENABLED")
252+
"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT" "JWT_VALIDITY_DURATION" "RAC_AUTO_DISABLE" "CACHING_ENABLED" "ENDPOINT_DETECTION")
253253
for name in "${toCopy[@]}"; do
254254
save_config_item $name "${!name}"
255255
done

servercfg/serverconf.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,17 @@ func DeployedByOperator() bool {
674674
return config.Config.Server.DeployedByOperator
675675
}
676676

677+
// IsEndpointDetectionEnabled - returns true if endpoint detection enabled
678+
func IsEndpointDetectionEnabled() bool {
679+
var enabled = true //default
680+
if os.Getenv("ENDPOINT_DETECTION") != "" {
681+
enabled = os.Getenv("ENDPOINT_DETECTION") == "true"
682+
} else {
683+
enabled = config.Config.Server.EndpointDetection
684+
}
685+
return enabled
686+
}
687+
677688
// GetEnvironment returns the environment the server is running in (e.g. dev, staging, prod...)
678689
func GetEnvironment() string {
679690
if env := os.Getenv("ENVIRONMENT"); env != "" {

0 commit comments

Comments
 (0)