From dbd95bb8ef02bd4a8429cfc4084a6ec53dad3100 Mon Sep 17 00:00:00 2001 From: Nils Stinnesbeck Date: Wed, 18 Nov 2026 11:56:29 +0100 Subject: [PATCH] run: --no-login-link keeps the sign-in link out of the terminal The link holds the admin token. Where the terminal is a log (containers) it would end up in log storage; the notice then only says where the token file is. The Kubernetes manifest uses it. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw --- README.md | 3 ++- cmd/allmende/login_test.go | 19 ++++++++++++++++++- cmd/allmende/run.go | 22 ++++++++++++++++++---- k8s/README.md | 11 ++++++----- k8s/base/statefulset.yaml | 1 + 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 98cc416..268e7b6 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,8 @@ the NixOS module has `services.allmende.public = true`. On Kubernetes, `k8s/` has ready manifests (kustomize), including how to run it behind a home router with a port forward: see [k8s/README.md](k8s/README.md). A node that does not know its own public address (router, container) is told one with -`--announce /dns4//tcp/4001`. +`--announce /dns4//tcp/4001`. Where the terminal is a log (containers), +`--no-login-link` keeps the sign-in link, which holds the admin token, out of it. ## Running a node for real diff --git a/cmd/allmende/login_test.go b/cmd/allmende/login_test.go index 263faf0..7662e53 100644 --- a/cmd/allmende/login_test.go +++ b/cmd/allmende/login_test.go @@ -1,6 +1,9 @@ package main -import "testing" +import ( + "strings" + "testing" +) func TestLoginURL(t *testing.T) { for addr, want := range map[string]string{ @@ -15,3 +18,17 @@ func TestLoginURL(t *testing.T) { } } } + +func TestLoginNoticeCanHideTheLink(t *testing.T) { + shown := loginNotice("127.0.0.1:8080", "sekret", false, true, "/data") + if !strings.Contains(shown, "#/login/sekret") || !strings.Contains(shown, "follows no region") { + t.Fatalf("the default shows the link and the region hint:\n%s", shown) + } + hidden := loginNotice("127.0.0.1:8080", "sekret", true, true, "/data") + if strings.Contains(hidden, "sekret") || strings.Contains(hidden, "login/") { + t.Fatalf("the token must not be printed:\n%s", hidden) + } + if !strings.Contains(hidden, "/data/admin.token") { + t.Fatalf("it should say where the token is:\n%s", hidden) + } +} diff --git a/cmd/allmende/run.go b/cmd/allmende/run.go index 59c2dee..defe723 100644 --- a/cmd/allmende/run.go +++ b/cmd/allmende/run.go @@ -49,6 +49,8 @@ func cmdRun(args []string) error { "address others should dial, when this node sits behind a router or in a container, e.g. /dns4/node.example.org/tcp/4001; repeatable") fs.Var(&listen, "listen", "libp2p listen multiaddr; repeatable (default: all interfaces, random ports)") httpAddr := fs.String("http", "127.0.0.1:8080", "address for the HTTP API") + noLoginLink := fs.Bool("no-login-link", false, + "do not print the owner sign-in link (it holds the admin token); use where the terminal is a log, e.g. in a container") noMDNS := fs.Bool("no-mdns", false, "do not look for peers on the local network") difficulty := fs.Int("difficulty", listing.DefaultDifficulty, "proof-of-work bits for listings; must match the rest of the network") @@ -199,10 +201,7 @@ func cmdRun(args []string) error { // Printed to the terminal, not logged: the token must not end up in a // log file. It sits in the URL fragment, which a browser never sends to // a server; the page moves it into sessionStorage and removes it. - fmt.Fprintf(os.Stderr, "\nOwner login (answer your inbox in the browser):\n %s\n\n", loginURL(ln.Addr().String(), token)) - if len(regions) == 0 && !*public { - fmt.Fprint(os.Stderr, "This node follows no region yet. Open the link above and choose where you want\nlistings from (and to publish) under \"My listings\" > \"Regions\".\n\n") - } + fmt.Fprint(os.Stderr, loginNotice(ln.Addr().String(), token, *noLoginLink, len(regions) == 0 && !*public, *data)) } else if len(regions) == 0 && !*public { log.Warn("this node follows no region and has no admin token, so nobody can choose one: pass --region") } @@ -250,6 +249,21 @@ func announce(ctx context.Context, log *slog.Logger, node *p2p.Node, st *store.S } } +// loginNotice is what the node prints about signing in. With hide set (for a +// node whose terminal is a log, e.g. in a container) the link is left out and +// the notice only says where the token is. +func loginNotice(listenAddr, token string, hide, noRegions bool, dataDir string) string { + if hide { + return fmt.Sprintf("\nOwner login link not shown (--no-login-link). The token is in %s\n\n", + filepath.Join(dataDir, tokenFile)) + } + s := fmt.Sprintf("\nOwner login (answer your inbox in the browser):\n %s\n\n", loginURL(listenAddr, token)) + if noRegions { + s += "This node follows no region yet. Open the link above and choose where you want\nlistings from (and to publish) under \"My listings\" > \"Regions\".\n\n" + } + return s +} + // loginURL is the link that signs the owner in to the web UI. func loginURL(listenAddr, token string) string { return uiURL(listenAddr, "/login/"+token) diff --git a/k8s/README.md b/k8s/README.md index f5873bc..a76be21 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -72,11 +72,12 @@ so: - **One replica only.** A second pod would be a second node with its own identity, not a copy. -- **The sign-in link is in the log.** `allmende run` prints the owner sign-in - link, token included, to the terminal, which in Kubernetes is the pod log. - A bootstrap node does not need it; if your logs are shared, read the token - from `/data/admin.token` yourself and rotate it by recovering the identity - (`allmende recover`) if it was exposed. +- **No sign-in link in the log.** `allmende run` normally prints the owner + sign-in link (it holds the admin token) to the terminal, which in Kubernetes + is the pod log. The manifest passes `--no-login-link`, so it is left out. + When you do want to sign in, read the token yourself and open + `http://localhost:8080/#/login/` through the port-forward below: + `kubectl -n allmende exec allmende-0 -- cat /data/admin.token` - **The web UI** is not published by default. For a look at it: `kubectl -n allmende port-forward svc/allmende-http 8080:8080`. To publish it, enable `ingress.yaml` in `base/kustomization.yaml` (read its note first: diff --git a/k8s/base/statefulset.yaml b/k8s/base/statefulset.yaml index 4331950..cd43bd8 100644 --- a/k8s/base/statefulset.yaml +++ b/k8s/base/statefulset.yaml @@ -45,6 +45,7 @@ spec: --public \ --no-default-bootstrap \ --no-mdns \ + --no-login-link \ --http 0.0.0.0:8080 \ --listen /ip4/0.0.0.0/tcp/4001 \ --listen /ip4/0.0.0.0/udp/4001/quic-v1 \