From 803202e94e5e608303a3466e0ce92ef1a9352864 Mon Sep 17 00:00:00 2001 From: Nils Stinnesbeck Date: Wed, 18 Nov 2026 23:37:55 +0100 Subject: [PATCH] k8s: REGION in config.env; the no-public-address warning names --announce REGION (place names or geohashes, comma separated) is passed to the node by the StatefulSet script, which now builds its arguments with set -- so a region is optional and PUBLIC_HOST must be set. The warning for a --public node without a public address now says which case it is (no --announce, or one that is not reachable) and the flag that fixes it. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw --- cmd/allmende/bootstrap.go | 17 +++++++++++++++++ cmd/allmende/bootstrap_test.go | 20 ++++++++++++++++++++ cmd/allmende/run.go | 4 ++-- k8s/README.md | 20 +++++++++++++++++--- k8s/base/config.env | 9 +++++++++ k8s/base/statefulset.yaml | 18 +++++++++++++++--- 6 files changed, 80 insertions(+), 8 deletions(-) diff --git a/cmd/allmende/bootstrap.go b/cmd/allmende/bootstrap.go index c503be1..34debca 100644 --- a/cmd/allmende/bootstrap.go +++ b/cmd/allmende/bootstrap.go @@ -5,6 +5,23 @@ import ( manet "github.com/multiformats/go-multiaddr/net" ) +// noPublicAddressWarning explains why a --public node has no records to +// publish, and the flag that fixes it. A node behind a router or in a +// container only sees its own private address, so it must be told the one +// others can dial; without --announce that is the usual reason, and a mistyped +// or private --announce address the other. +func noPublicAddressWarning(announced bool) string { + const fix = "say which address others should dial with --announce, e.g. " + + "--announce /dns4//tcp/ --announce /dns4//udp//quic-v1; " + + "the node then prints the DNS records to publish" + if !announced { + return "--public, but this node has no public address: it only knows its own private ones (it sits behind a router or in a container?). " + + "A bootstrap node needs one: " + fix + } + return "--public, but none of the --announce addresses is publicly reachable (a private or loopback IP, or a name such as localhost?). " + + "Others cannot dial it, so " + fix +} + // bootstrapRecords turns a node's addresses into the DNS TXT values that make // it a bootstrap node, one per publicly routable address. Loopback and private // addresses are left out: nobody else could use them. diff --git a/cmd/allmende/bootstrap_test.go b/cmd/allmende/bootstrap_test.go index 298871a..5602bb4 100644 --- a/cmd/allmende/bootstrap_test.go +++ b/cmd/allmende/bootstrap_test.go @@ -2,6 +2,7 @@ package main import ( "reflect" + "strings" "testing" ) @@ -28,6 +29,25 @@ func TestBootstrapRecordsKeepOnlyPublicAddresses(t *testing.T) { } } +func TestTheNoPublicAddressWarningNamesTheFlagThatFixesIt(t *testing.T) { + without := noPublicAddressWarning(false) + for _, want := range []string{"--announce /dns4/", "/udp//quic-v1", "behind a router or in a container", "DNS records"} { + if !strings.Contains(without, want) { + t.Errorf("without --announce the warning must mention %q:\n%s", want, without) + } + } + with := noPublicAddressWarning(true) + if !strings.Contains(with, "none of the --announce addresses is publicly reachable") || !strings.Contains(with, "localhost") { + t.Errorf("with an unusable --announce the warning must say so:\n%s", with) + } + if strings.Contains(with, "it only knows its own private ones") { + t.Errorf("it must not claim --announce is missing when it was given:\n%s", with) + } + if without == with { + t.Error("the two situations need different advice") + } +} + func TestAHostnameAddressIsPublishedAsItIs(t *testing.T) { const id = "12D3KooWQYhTNQdmr3ArTeUHRYzFg94BKyTkoWBDWez9kSCVe2Xo" got := bootstrapRecords([]string{ diff --git a/cmd/allmende/run.go b/cmd/allmende/run.go index a8cd71a..0e14f79 100644 --- a/cmd/allmende/run.go +++ b/cmd/allmende/run.go @@ -220,8 +220,8 @@ func cmdRun(args []string) error { } fmt.Fprintln(os.Stderr) } else { - log.Warn("--public, but this node has no public address; a bootstrap node needs one (a server, or a forwarded port): publish dnsaddr=/ip4//tcp//p2p/", - "peer_id", node.ID().String()) + log.Warn(noPublicAddressWarning(len(announceAddrs) > 0), + "peer_id", node.ID().String(), "announce", []string(announceAddrs)) } } diff --git a/k8s/README.md b/k8s/README.md index a4d4248..9c009d3 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -37,7 +37,8 @@ so: docker build -t git.stinnesbeck.com/nils/allmende: . && docker push git.stinnesbeck.com/nils/allmende: ``` 2. **Name.** Edit `base/config.env` (`PUBLIC_HOST`, and `PUBLIC_PORT` if the - router cannot forward 4001 to 4001). + router cannot forward 4001 to 4001; `REGION` if the node should keep + listings for a region). 3. **Apply.** ``` kubectl apply -k k8s/base # with a LoadBalancer (MetalLB, kube-vip, ...) @@ -85,8 +86,21 @@ so: that file). The same port serves the owner API, which the admin token protects. To keep it private, comment the file out in `base/kustomization.yaml` and use `kubectl -n allmende port-forward svc/allmende-http 8080:8080`. -- **Regions.** A bootstrap node follows none. To make it also keep listings, - open the UI through the port-forward, sign in and choose regions. +- **Regions.** A bootstrap node follows none by default. To make it also keep + listings, either set `REGION` in `base/config.env` (a place name or a + 3-character geohash, several separated by commas: `REGION=mechernich`) and + apply again, or open the UI through the port-forward, sign in and choose + regions there. A choice made in the browser is kept on the volume and wins + over `REGION` from then on; delete `/data/regions.json` to use `REGION` + again. Do not edit the `args` script in `statefulset.yaml` for this: a missing + trailing `\` there silently drops `--announce` (see below). +- **"--public, but this node has no public address" in the log** means the node + runs without `--announce`, so it only knows the pod's private address and + advertises that. Check that the live StatefulSet's `args` still contain both + `--announce` lines and that every line of the `set --` command but the last + ends in `\` (`kubectl -n allmende get statefulset allmende -o yaml`). The + warning says which case it is: no `--announce` at all, or one that is not + publicly reachable. An empty `PUBLIC_HOST` stops the pod with an error instead. - **More than one bootstrap node** on different networks makes the network independent of any single one. Run this on a second cluster or a VPS and add its records next to the first. diff --git a/k8s/base/config.env b/k8s/base/config.env index 28a3c52..8547e48 100644 --- a/k8s/base/config.env +++ b/k8s/base/config.env @@ -6,3 +6,12 @@ PUBLIC_HOST=bootstrap.allmende.stinnesbeck.com # The port your router forwards to the cluster, as seen from the internet # (TCP and UDP). Keep it 4001 unless the router cannot forward it. PUBLIC_PORT=4001 + +# The regions this node keeps listings for: a place name or a 3-character +# geohash, several separated by commas (REGION=mechernich or REGION=u1h,u0u). +# Empty (the default) follows none: it then only helps others connect. +# It is the starting value: once the owner chooses regions in the browser, those +# are kept on the volume and win over this (delete /data/regions.json to use +# this again). Changing this file restarts the pod, because the ConfigMap name +# changes with its content. +REGION= diff --git a/k8s/base/statefulset.yaml b/k8s/base/statefulset.yaml index 980d35a..1a3bd6a 100644 --- a/k8s/base/statefulset.yaml +++ b/k8s/base/statefulset.yaml @@ -34,13 +34,19 @@ spec: # bootstrap node has nothing to recover; its identity is its peer ID, # which lives on the volume). Then run as a bootstrap node: --public # serves the DHT and relays for nodes behind a NAT, --announce names - # the address the router forwards. + # the address the router forwards, and REGION (config.env) the regions + # to keep listings for, if any. + # + # When you edit this script: every line of the `set --` command but + # the last ends in a backslash. A missing one cuts the command short + # and silently drops the flags below it (--announce above all); the + # node then logs "--public, but this node has no public address". command: ["/bin/sh", "-c"] args: - | + : "${PUBLIC_HOST:?set PUBLIC_HOST in k8s/base/config.env}" [ -f /data/admin.token ] || allmende init --no-phrase - exec allmende run \ - --public \ + set -- --public \ --no-default-bootstrap \ --no-mdns \ --no-login-link \ @@ -49,6 +55,12 @@ spec: --listen /ip4/0.0.0.0/udp/4001/quic-v1 \ --announce "/dns4/${PUBLIC_HOST}/tcp/${PUBLIC_PORT}" \ --announce "/dns4/${PUBLIC_HOST}/udp/${PUBLIC_PORT}/quic-v1" + if [ -n "${REGION}" ]; then + set -f; IFS=, + for r in ${REGION}; do set -- "$@" --region "$r"; done + unset IFS; set +f + fi + exec allmende run "$@" envFrom: - configMapRef: name: allmende-config