Skip to content

Commit d01636a

Browse files
committed
multi: only use admin mac or allow single mac
With the new lndclient version we can specify a single, custom macaroon. We use the admin macaroon as the custom macaroon in the remote connection case which removes the need to copy all subserver macaroons to the host where LiT is running. Users baking custom non-admin macaroons can also specify that directly with a new configuration option.
1 parent ebf99b1 commit d01636a

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

config.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99
"net/http"
1010
"os"
11+
"path"
1112
"path/filepath"
1213
"strings"
1314

@@ -171,7 +172,14 @@ type RemoteDaemonConfig struct {
171172

172173
// MacaroonDir is the directory that contains all the macaroon files
173174
// required for the remote connection.
174-
MacaroonDir string `long:"macaroondir" description:"The directory containing all lnd macaroons to use for the remote connection."`
175+
MacaroonDir string `long:"macaroondir" description:"DEPRECATED: Use macaroonpath. The directory containing all lnd macaroons to use for the remote connection."`
176+
177+
// MacaroonPath is the path to the single macaroon that should be used
178+
// instead of needing to specify the macaroon directory that contains
179+
// all of lnd's macaroons. The specified macaroon MUST have all
180+
// permissions that all the subservers use, otherwise permission errors
181+
// will occur.
182+
MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the admin.macaroon or a custom baked one. Cannot be specified at the same time as macaroondir. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."`
175183

176184
// TLSCertPath is the path to the tls cert of the remote daemon that
177185
// should be used to verify the TLS identity of the remote RPC server.
@@ -186,10 +194,24 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string, string,
186194
// In remote lnd mode, we just pass along what was configured in the
187195
// remote section of the lnd config.
188196
if c.LndMode == ModeRemote {
197+
// Because we now have the option to specify a single, custom
198+
// macaroon to the lndclient, we either use the single macaroon
199+
// indicated by the user or the admin macaroon from the mac dir
200+
// that was specified.
201+
macPath := path.Join(
202+
lncfg.CleanAndExpandPath(c.Remote.Lnd.MacaroonDir),
203+
defaultLndMacaroon,
204+
)
205+
if c.Remote.Lnd.MacaroonPath != "" {
206+
macPath = lncfg.CleanAndExpandPath(
207+
c.Remote.Lnd.MacaroonPath,
208+
)
209+
}
210+
189211
return c.Remote.Lnd.RPCServer,
190212
lndclient.Network(c.network),
191213
lncfg.CleanAndExpandPath(c.Remote.Lnd.TLSCertPath),
192-
lncfg.CleanAndExpandPath(c.Remote.Lnd.MacaroonDir), nil
214+
macPath, nil
193215
}
194216

195217
// When we start lnd internally, we take the listen address as
@@ -211,7 +233,7 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string, string,
211233
}
212234

213235
return lndDialAddr, lndclient.Network(c.network),
214-
c.Lnd.TLSCertPath, filepath.Dir(c.Lnd.AdminMacPath), nil
236+
c.Lnd.TLSCertPath, c.Lnd.AdminMacPath, nil
215237
}
216238

217239
// defaultConfig returns a configuration struct with all default values set.
@@ -442,6 +464,15 @@ func validateRemoteModeConfig(cfg *Config) error {
442464
}
443465
cfg.network = r.Lnd.Network
444466

467+
// Users can either specify the macaroon directory or the custom
468+
// macaroon to use, but not both.
469+
if r.Lnd.MacaroonDir != defaultRemoteLndMacDir &&
470+
r.Lnd.MacaroonPath != "" {
471+
472+
return fmt.Errorf("cannot set both macaroon dir and macaroon " +
473+
"path")
474+
}
475+
445476
// If the remote lnd's network isn't the default, we also check if we
446477
// need to adjust the default macaroon directory so the user can only
447478
// specify --network=testnet for example if everything else is using

doc/config-lnd-remote.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ directory on your remote machine to `/some/folder/with/lnd/data/` on your local
1919

2020
- tls.cert
2121
- admin.macaroon
22-
- chainnotifier.macaroon
23-
- invoices.macaroon
24-
- readonly.macaroon
25-
- router.macaroon
26-
- signer.macaroon
27-
- walletkit.macaroon
22+
23+
(Note that with LiT prior to `v0.3.5-alpha` all `*.macaroon` files need to be
24+
copied from the lnd machine.)
2825

2926
Create a `lit.conf` file. The default location LiT will look for the configuration file
3027
depends on your operating system:
@@ -38,7 +35,7 @@ creating `lit.conf` populate it with the following configuration settings:
3835

3936
```text
4037
remote.lnd.rpcserver=<externally-reachable-ip-address>:10009
41-
remote.lnd.macaroondir=/some/folder/with/lnd/data
38+
remote.lnd.macaroonpath=/some/folder/with/lnd/data/admin.macaroon
4239
remote.lnd.tlscertpath=/some/folder/with/lnd/data/tls.cert
4340
```
4441

@@ -95,7 +92,7 @@ and `faraday` (optional):
9592
--remote.lit-debuglevel=debug \
9693
--remote.lnd.network=testnet \
9794
--remote.lnd.rpcserver=some-other-host:10009 \
98-
--remote.lnd.macaroondir=/some/folder/with/lnd/data \
95+
--remote.lnd.macaroonpath=/some/folder/with/lnd/data/admin.macaroon \
9996
--remote.lnd.tlscertpath=/some/folder/with/lnd/data/tls.cert \
10097
--loop.loopoutmaxparts=5 \
10198
--pool.newnodesonly=true \
@@ -106,12 +103,6 @@ and `faraday` (optional):
106103
--faraday.bitcoin.password=testnetpw
107104
```
108105

109-
NOTE: Even though LiT itself only needs `lnd`'s `admin.macaroon`, the `loop`,
110-
`pool`, and `faraday` daemons will require other macaroons and will look for
111-
them in the folder specified with `--remote.lnd.macaroondir`. It is advised to
112-
copy all `*.macaroon` files and the `tls.cert` file from the remote host to the
113-
host that is running `litd`.
114-
115106
## Use a configuration file
116107

117108
You can also store the configuration in a persistent `~/.lit/lit.conf` file, so you do not
@@ -151,7 +142,7 @@ remote.lit-debuglevel=debug
151142
# Remote lnd options
152143
remote.lnd.network=testnet
153144
remote.lnd.rpcserver=some-other-host:10009
154-
remote.lnd.macaroondir=/some/folder/with/lnd/data
145+
remote.lnd.macaroonpath=/some/folder/with/lnd/data/admin.macaroon
155146
remote.lnd.tlscertpath=/some/folder/with/lnd/data/tls.cert
156147
157148
# Loop
@@ -192,7 +183,7 @@ lit-dir=~/.lit
192183
193184
remote.lnd.network=testnet
194185
remote.lnd.rpcserver=some-other-host:10009
195-
remote.lnd.macaroondir=/some/folder/with/lnd/data
186+
remote.lnd.macaroonpath=/some/folder/with/lnd/data/admin.macaroon
196187
remote.lnd.tlscertpath=/some/folder/with/lnd/data/tls.cert
197188
```
198189

rpc_proxy.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io/ioutil"
99
"net/http"
10-
"path"
1110
"strings"
1211
"time"
1312

@@ -316,7 +315,6 @@ func (p *rpcProxy) basicAuthToMacaroon(ctx context.Context,
316315
switch {
317316
case isLndURI(requestURI):
318317
_, _, _, macPath, err = p.cfg.lndConnectParams()
319-
macPath = path.Join(macPath, defaultLndMacaroon)
320318

321319
case isLoopURI(requestURI):
322320
macPath = p.cfg.Loop.MacaroonPath

terminal.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99
"net/http"
1010
"os"
11+
"path"
1112
"path/filepath"
1213
"regexp"
1314
"strings"
@@ -249,7 +250,7 @@ func (g *LightningTerminal) Run() error {
249250
func (g *LightningTerminal) startSubservers() error {
250251
var basicClient lnrpc.LightningClient
251252

252-
host, network, tlsPath, macDir, err := g.cfg.lndConnectParams()
253+
host, network, tlsPath, macPath, err := g.cfg.lndConnectParams()
253254
if err != nil {
254255
return err
255256
}
@@ -265,8 +266,8 @@ func (g *LightningTerminal) startSubservers() error {
265266
// subservers have the same requirements.
266267
var err error
267268
basicClient, err = lndclient.NewBasicClient(
268-
host, tlsPath, macDir, string(network),
269-
lndclient.MacFilename(defaultLndMacaroon),
269+
host, tlsPath, path.Dir(macPath), string(network),
270+
lndclient.MacFilename(path.Base(macPath)),
270271
)
271272
return err
272273
}, defaultStartupTimeout)
@@ -301,8 +302,8 @@ func (g *LightningTerminal) startSubservers() error {
301302
&lndclient.LndServicesConfig{
302303
LndAddress: host,
303304
Network: network,
304-
MacaroonDir: macDir,
305305
TLSPath: tlsPath,
306+
CustomMacaroonPath: macPath,
306307
BlockUntilChainSynced: true,
307308
BlockUntilUnlocked: true,
308309
CallerCtx: ctxc,
@@ -643,10 +644,10 @@ func (g *LightningTerminal) showStartupInfo() error {
643644
if g.cfg.LndMode == ModeRemote {
644645
// We try to query GetInfo on the remote node to find out the
645646
// alias. But the wallet might be locked.
646-
host, network, tlsPath, macDir, _ := g.cfg.lndConnectParams()
647+
host, network, tlsPath, macPath, _ := g.cfg.lndConnectParams()
647648
basicClient, err := lndclient.NewBasicClient(
648-
host, tlsPath, macDir, string(network),
649-
lndclient.MacFilename(defaultLndMacaroon),
649+
host, tlsPath, path.Dir(macPath), string(network),
650+
lndclient.MacFilename(path.Base(macPath)),
650651
)
651652
if err != nil {
652653
return fmt.Errorf("error querying remote node: %v", err)

0 commit comments

Comments
 (0)