Feature: Tunnel the device protocol through a reverse proxy over WebSocket

This commit is contained in:
yuanyuanxiang committed 2026-10-30 17:21:42 +01:00
1 parent de621aa555
commit d4f312c9d8
20 files changed
+1994 -63

No files matched your search

+18
View File
@@ -1153,6 +1153,22 @@ func main() {
log.Info("ConnAuth HMAC verification enabled for device sub-connections (YAMA_CONN_AUTH_KEY)")
}
// Optional WebSocket transport on the device port, for devices that can only
// reach the server through a reverse proxy on a shared port (nginx on 443).
// YAMA_WS_PATH restricts upgrades to one request path (empty = any path).
// YAMA_TRUSTED_PROXIES lists the IPs/CIDRs allowed to report a device's real
// address via X-Forwarded-For / X-Real-IP (default: loopback only).
wsPath := strings.TrimSpace(os.Getenv("YAMA_WS_PATH"))
trustedProxies := splitCSV(os.Getenv("YAMA_TRUSTED_PROXIES"))
if wsPath != "" {
log.Info("WebSocket transport on device port enabled: path=%s", wsPath)
} else {
log.Info("WebSocket transport on device port enabled: any path")
}
if len(trustedProxies) > 0 {
log.Info("Trusting forwarded client IPs from: %s", strings.Join(trustedProxies, ", "))
}
// Create servers for each port
var servers []*server.Server
for _, port := range ports {
@@ -1163,6 +1179,8 @@ func main() {
config.PerIPConnRateLimit = envInt("YAMA_PERIP_CONN_RATE", config.PerIPConnRateLimit)
config.TLSCertFile = tlsCert
config.TLSKeyFile = tlsKey
config.WSPath = wsPath
config.TrustedProxies = trustedProxies
srv := server.New(config)
srv.SetLogger(log.WithPrefix(fmt.Sprintf("Server:%d", port)))