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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 11:56:29 +01:00
co-authored by Claude Sonnet 5.5
parent 819df6d512
commit dbd95bb8ef
5 changed files with 45 additions and 11 deletions
+2 -1
View File
@@ -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 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 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 know its own public address (router, container) is told one with
`--announce /dns4/<name>/tcp/4001`. `--announce /dns4/<name>/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 ## Running a node for real
+18 -1
View File
@@ -1,6 +1,9 @@
package main package main
import "testing" import (
"strings"
"testing"
)
func TestLoginURL(t *testing.T) { func TestLoginURL(t *testing.T) {
for addr, want := range map[string]string{ 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)
}
}
+18 -4
View File
@@ -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") "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)") 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") 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") noMDNS := fs.Bool("no-mdns", false, "do not look for peers on the local network")
difficulty := fs.Int("difficulty", listing.DefaultDifficulty, difficulty := fs.Int("difficulty", listing.DefaultDifficulty,
"proof-of-work bits for listings; must match the rest of the network") "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 // 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 // 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. // 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)) fmt.Fprint(os.Stderr, loginNotice(ln.Addr().String(), token, *noLoginLink, len(regions) == 0 && !*public, *data))
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")
}
} else if len(regions) == 0 && !*public { } 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") 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. // loginURL is the link that signs the owner in to the web UI.
func loginURL(listenAddr, token string) string { func loginURL(listenAddr, token string) string {
return uiURL(listenAddr, "/login/"+token) return uiURL(listenAddr, "/login/"+token)
+6 -5
View File
@@ -72,11 +72,12 @@ so:
- **One replica only.** A second pod would be a second node with its own - **One replica only.** A second pod would be a second node with its own
identity, not a copy. identity, not a copy.
- **The sign-in link is in the log.** `allmende run` prints the owner sign-in - **No sign-in link in the log.** `allmende run` normally prints the owner
link, token included, to the terminal, which in Kubernetes is the pod log. sign-in link (it holds the admin token) to the terminal, which in Kubernetes
A bootstrap node does not need it; if your logs are shared, read the token is the pod log. The manifest passes `--no-login-link`, so it is left out.
from `/data/admin.token` yourself and rotate it by recovering the identity When you do want to sign in, read the token yourself and open
(`allmende recover`) if it was exposed. `http://localhost:8080/#/login/<token>` 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: - **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 `kubectl -n allmende port-forward svc/allmende-http 8080:8080`. To publish
it, enable `ingress.yaml` in `base/kustomization.yaml` (read its note first: it, enable `ingress.yaml` in `base/kustomization.yaml` (read its note first:
+1
View File
@@ -45,6 +45,7 @@ spec:
--public \ --public \
--no-default-bootstrap \ --no-default-bootstrap \
--no-mdns \ --no-mdns \
--no-login-link \
--http 0.0.0.0:8080 \ --http 0.0.0.0:8080 \
--listen /ip4/0.0.0.0/tcp/4001 \ --listen /ip4/0.0.0.0/tcp/4001 \
--listen /ip4/0.0.0.0/udp/4001/quic-v1 \ --listen /ip4/0.0.0.0/udp/4001/quic-v1 \