Skip to content

Commit 0ec9508

Browse files
committed
multi: add DisableUI option
Add a new `disableui` config option. If this option is set then the user no longer needs to set the `uipassword` config option. This also means that the user will no longer be able to interact with the local UI.
1 parent a566bfc commit 0ec9508

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

config.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ type Config struct {
143143
HTTPListen string `long:"insecure-httplisten" description:"The host:port to listen on with TLS disabled. This is dangerous to enable as credentials will be submitted without encryption. Should only be used in combination with Tor hidden services or other external encryption."`
144144
EnableREST bool `long:"enablerest" description:"Also allow REST requests to be made to the main HTTP(s) port(s) configured above."`
145145
RestCORS []string `long:"restcors" description:"Add an ip:port/hostname to allow cross origin access from. To allow all origins, set as \"*\"."`
146-
UIPassword string `long:"uipassword" description:"The password that must be entered when using the loop UI. use a strong password to protect your node from unauthorized access through the web UI."`
146+
UIPassword string `long:"uipassword" description:"The password that must be entered when using the UI. Use a strong password to protect your node from unauthorized access through the web UI."`
147147
UIPasswordFile string `long:"uipassword_file" description:"Same as uipassword but instead of passing in the value directly, read the password from the specified file."`
148148
UIPasswordEnv string `long:"uipassword_env" description:"Same as uipassword but instead of passing in the value directly, read the password from the specified environment variable."`
149+
DisableUI bool `long:"disableui" description:"If set to true, no web UI will be served and so the uipassword will also not need to be set."`
149150

150151
LetsEncrypt bool `long:"letsencrypt" description:"Use Let's Encrypt to create a TLS certificate for the UI instead of using lnd's TLS certificate. Port 80 must be free to listen on and must be reachable from the internet for this to work."`
151152
LetsEncryptHost string `long:"letsencrypthost" description:"The host name to create a Let's Encrypt certificate for."`
@@ -424,13 +425,19 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
424425
return nil, err
425426
}
426427
}
427-
err = readUIPassword(cfg)
428-
if err != nil {
429-
return nil, fmt.Errorf("could not read UI password: %v", err)
430-
}
431-
if len(cfg.UIPassword) < uiPasswordMinLength {
432-
return nil, fmt.Errorf("please set a strong password for the "+
433-
"UI, at least %d characters long", uiPasswordMinLength)
428+
429+
// If the web UI is enabled, a UI password must be provided.
430+
if !cfg.DisableUI {
431+
err = readUIPassword(cfg)
432+
if err != nil {
433+
return nil, fmt.Errorf("could not read UI password: %v",
434+
err)
435+
}
436+
if len(cfg.UIPassword) < uiPasswordMinLength {
437+
return nil, fmt.Errorf("please set a strong "+
438+
"password for the UI, at least %d characters "+
439+
"long", uiPasswordMinLength)
440+
}
434441
}
435442

436443
if cfg.Network != DefaultNetwork {

rpc_proxy.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (p *rpcProxy) makeDirector(allowLitRPC bool) func(ctx context.Context,
333333
authHeaders := md.Get("authorization")
334334
macHeader := md.Get(HeaderMacaroon)
335335
switch {
336-
case len(authHeaders) == 1:
336+
case len(authHeaders) == 1 && !p.cfg.DisableUI:
337337
macBytes, err := p.basicAuthToMacaroon(
338338
authHeaders[0], requestURI, nil,
339339
)
@@ -482,6 +482,12 @@ func (p *rpcProxy) StreamServerInterceptor(srv interface{},
482482
func (p *rpcProxy) convertBasicAuth(ctx context.Context,
483483
requestURI string, ctxErr error) (context.Context, error) {
484484

485+
// If the UI is disabled, then there is no UI password and so the
486+
// request is required to have a macaroon in it.
487+
if p.cfg.DisableUI {
488+
return ctx, ctxErr
489+
}
490+
485491
md, ok := metadata.FromIncomingContext(ctx)
486492
if !ok {
487493
return ctx, ctxErr

terminal.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,14 @@ func (g *LightningTerminal) startMainWebServer() error {
12521252
return
12531253
}
12541254

1255+
// If the UI is disabled, then we return a 401 here to prevent
1256+
// serving any of the static files.
1257+
if g.cfg.DisableUI {
1258+
resp.WriteHeader(http.StatusUnauthorized)
1259+
1260+
return
1261+
}
1262+
12551263
// If we got here, it's a static file the browser wants, or
12561264
// something we don't know in which case the static file server
12571265
// will answer with a 404.
@@ -1630,6 +1638,13 @@ func (g *LightningTerminal) showStartupInfo() error {
16301638
listenAddr = fmt.Sprintf("%s, %s", listenAddr, g.cfg.HTTPListen)
16311639
}
16321640

1641+
webInterfaceString := fmt.Sprintf(
1642+
"%s (open %s in your browser)", listenAddr, info.webURI,
1643+
)
1644+
if g.cfg.DisableUI {
1645+
webInterfaceString = "disabled"
1646+
}
1647+
16331648
str := "" +
16341649
"----------------------------------------------------------\n" +
16351650
" Lightning Terminal (LiT) by Lightning Labs \n" +
@@ -1639,10 +1654,10 @@ func (g *LightningTerminal) showStartupInfo() error {
16391654
" LND Alias %s \n" +
16401655
" LND Version %s \n" +
16411656
" LiT Version %s \n" +
1642-
" Web interface %s (open %s in your browser) \n" +
1657+
" Web interface %s \n" +
16431658
"----------------------------------------------------------\n"
16441659
fmt.Printf(str, info.mode, info.status, info.alias, info.version,
1645-
Version(), listenAddr, info.webURI)
1660+
Version(), webInterfaceString)
16461661

16471662
return nil
16481663
}

0 commit comments

Comments
 (0)