From cbe42b790010fb4a0a6b07b03c1484a346c0a63a Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 3 Nov 2026 23:28:40 -0800 Subject: [PATCH] fix: separate the gossip listen address from the advertised one (#8) KNOX_PEER_ADDR doubled as the bind address, so a container tried to bind the host's overlay IP and the gossip server never started. KNOX_LISTEN_ADDR now controls the bind (defaulting to KNOX_PEER_ADDR for compatibility) and the advertised address stays what peers dial. --- README.md | 1 + internal/watch/gossip.go | 17 ++++++++++++++++- internal/watch/watch.go | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a7342b..03265c6 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ DNS name: a self-signed certificate and a shared bearer token are enough. | `KNOX_TLS_CERT` / `KNOX_TLS_KEY` | Serve TLS. Generate with `knox tls init`. | | `KNOX_TLS_CA` | Client side: trust a peer's self-signed cert. | | `KNOX_INSECURE_TLS=1` | Client side: skip verification (trusted overlay only). | +| `KNOX_LISTEN_ADDR` | Address the gossip server binds (use `0.0.0.0:8931` in a container). | | `KNOX_PEER_ADDR` | Address this node advertises to peers. | | `KNOX_PEERS` | Comma-separated seed peers, e.g. `https://172.30.170.155:8931`. | | `KNOX_LOCAL_SOURCES=none` | Replicate only: skip ingest of local files/sessions. | diff --git a/internal/watch/gossip.go b/internal/watch/gossip.go index f35fe4f..f97ebc1 100644 --- a/internal/watch/gossip.go +++ b/internal/watch/gossip.go @@ -416,14 +416,29 @@ func isLoopbackAddr(addr string) bool { return host == "localhost" } -// ListenAddr returns the advertised HTTP address (KNOX_PEER_ADDR or default). +// ListenAddr is the address the gossip server binds. It is separate from the +// advertised address because a container cannot bind the host's public or +// overlay IP: inside the netns it listens on all interfaces while advertising +// something peers can dial (KNOX_PEER_ADDR). func ListenAddr() (addr string) { + if addr = os.Getenv("KNOX_LISTEN_ADDR"); addr != "" { + return addr + } if addr = os.Getenv("KNOX_PEER_ADDR"); addr != "" { return addr } return "localhost:" + defaultPort } +// AdvertiseAddr is the base URL this node publishes to peers (/v1/ping), which +// is what they store and dial. Falls back to the listen address. +func AdvertiseAddr() string { + if addr := os.Getenv("KNOX_PEER_ADDR"); addr != "" { + return addr + } + return ListenAddr() +} + const defaultMetricsPort = "8932" // MetricsAddr returns the Prometheus scrape address (KNOX_METRICS_ADDR or diff --git a/internal/watch/watch.go b/internal/watch/watch.go index bbe3652..ffde2c1 100644 --- a/internal/watch/watch.go +++ b/internal/watch/watch.go @@ -157,7 +157,7 @@ func (w *Watcher) Start() error { // Start the gossip server first so peers can reach us while the initial // seed is still ingesting. Vault/dirs are logged after the seed below. gossipAddr := ListenAddr() - node := &Node{Kdb: w.knoxDB, Name: "knox", Addr: gossipAddr, Metrics: w.metrics} + node := &Node{Kdb: w.knoxDB, Name: "knox", Addr: AdvertiseAddr(), Metrics: w.metrics} srv := &http.Server{ Addr: gossipAddr, Handler: httpauth.Middleware(node.Handler()),