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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+18
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user