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:
Abhishek K 2024-04-03 23:51:09 +05:30 committed by GitHub
parent 80e775d5b4
commit dccb6b5da7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 61 additions and 43 deletions

View file

@ -92,6 +92,7 @@ type ServerConfig struct {
JwtValidityDuration time.Duration `yaml:"jwt_validity_duration"`
RacAutoDisable bool `yaml:"rac_auto_disable"`
CacheEnabled string `yaml:"caching_enabled"`
EndpointDetection bool `json:"endpoint_detection"`
AllowedEmailDomains string `yaml:"allowed_email_domains"`
}

View file

@ -145,6 +145,7 @@ func pull(w http.ResponseWriter, r *http.Request) {
ChangeDefaultGw: hPU.ChangeDefaultGw,
DefaultGwIp: hPU.DefaultGwIp,
IsInternetGw: hPU.IsInternetGw,
EndpointDetection: servercfg.IsEndpointDetectionEnabled(),
}
logger.Log(1, hostID, "completed a pull")

View file

@ -76,6 +76,7 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
Peers: []wgtypes.PeerConfig{},
NodePeers: []wgtypes.PeerConfig{},
HostNetworkInfo: models.HostInfoMap{},
EndpointDetection: servercfg.IsEndpointDetectionEnabled(),
}
slog.Debug("peer update for host", "hostId", host.ID.String())

View file

@ -23,6 +23,7 @@ type HostPeerUpdate struct {
EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
FwUpdate FwUpdate `json:"fw_update"`
ReplacePeers bool `json:"replace_peers"`
EndpointDetection bool `json:"endpoint_detection"`
}
// IngressInfo - struct for ingress info

View file

@ -243,6 +243,7 @@ type HostPull struct {
ChangeDefaultGw bool `json:"change_default_gw"`
DefaultGwIp net.IP `json:"default_gw_ip"`
IsInternetGw bool `json:"is_inet_gw"`
EndpointDetection bool `json:"endpoint_detection"`
}
type DefaultGwInfo struct {

View file

@ -73,3 +73,5 @@ JWT_VALIDITY_DURATION=43200
RAC_AUTO_DISABLE=true
# if turned on data will be cached on to improve performance significantly (IMPORTANT: If HA set to `false` )
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

View file

@ -249,7 +249,7 @@ save_config() { (
"INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT"
"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"
"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
save_config_item $name "${!name}"
done

View file

@ -674,6 +674,17 @@ func DeployedByOperator() bool {
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...)
func GetEnvironment() string {
if env := os.Getenv("ENVIRONMENT"); env != "" {