Skip to content

Commit 2a089d1

Browse files
committed
loopd: all only specifying one lnd macaroon
Fixes #299 by allowing only one macaroon to be specified in the --lnd.macaroonpath config option/command line flag.
1 parent 6b8a12f commit 2a089d1

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

loopd/config.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/x509"
66
"fmt"
77
"os"
8+
"path"
89
"path/filepath"
910
"time"
1011

@@ -46,6 +47,10 @@ var (
4647

4748
defaultSelfSignedOrganization = "loop autogenerated cert"
4849

50+
// defaultLndMacaroon is the default macaroon file we use if the old,
51+
// deprecated --lnd.macaroondir config option is used.
52+
defaultLndMacaroon = "admin.macaroon"
53+
4954
// DefaultTLSCertPath is the default full path of the autogenerated TLS
5055
// certificate.
5156
DefaultTLSCertPath = filepath.Join(
@@ -70,9 +75,20 @@ var (
7075
)
7176

7277
type lndConfig struct {
73-
Host string `long:"host" description:"lnd instance rpc address"`
74-
MacaroonDir string `long:"macaroondir" description:"Path to the directory containing all the required lnd macaroons"`
75-
TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"`
78+
Host string `long:"host" description:"lnd instance rpc address"`
79+
80+
// MacaroonDir is the directory that contains all the macaroon files
81+
// required for the remote connection.
82+
MacaroonDir string `long:"macaroondir" description:"DEPRECATED: Use macaroonpath."`
83+
84+
// MacaroonPath is the path to the single macaroon that should be used
85+
// instead of needing to specify the macaroon directory that contains
86+
// all of lnd's macaroons. The specified macaroon MUST have all
87+
// permissions that all the subservers use, otherwise permission errors
88+
// will occur.
89+
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."`
90+
91+
TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"`
7692
}
7793

7894
type loopServerConfig struct {
@@ -235,6 +251,30 @@ func Validate(cfg *Config) error {
235251
return err
236252
}
237253

254+
// Make sure only one of the macaroon options is used.
255+
switch {
256+
case cfg.Lnd.MacaroonPath != "" && cfg.Lnd.MacaroonDir != "":
257+
return fmt.Errorf("use --lnd.macaroonpath only")
258+
259+
case cfg.Lnd.MacaroonDir != "":
260+
// With the new version of lndclient we can only specify a
261+
// single macaroon instead of all of them. If the old
262+
// macaroondir is used, we use the admin macaroon located in
263+
// that directory.
264+
cfg.Lnd.MacaroonPath = path.Join(
265+
lncfg.CleanAndExpandPath(cfg.Lnd.MacaroonDir),
266+
defaultLndMacaroon,
267+
)
268+
269+
case cfg.Lnd.MacaroonPath != "":
270+
cfg.Lnd.MacaroonPath = lncfg.CleanAndExpandPath(
271+
cfg.Lnd.MacaroonPath,
272+
)
273+
274+
default:
275+
return fmt.Errorf("must specify --lnd.macaroonpath")
276+
}
277+
238278
return nil
239279
}
240280

loopd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func newListenerCfg(config *Config, rpcCfg RPCConfig) *listenerCfg {
9090
svcCfg := &lndclient.LndServicesConfig{
9191
LndAddress: cfg.Host,
9292
Network: network,
93-
MacaroonDir: cfg.MacaroonDir,
93+
CustomMacaroonPath: cfg.MacaroonPath,
9494
TLSPath: cfg.TLSPath,
9595
CheckVersion: LoopMinRequiredLndVersion,
9696
BlockUntilChainSynced: true,

release_notes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ This file tracks release notes for the loop client.
1717

1818
#### New Features
1919
* If lnd is locked when the loop client starts up, it will wait for lnd to be
20-
unlocked. Previous versions would exit with an error.
20+
unlocked. Previous versions would exit with an error.
21+
* Loop will no longer need all `lnd` subserver macaroons to be present in the
22+
`--lnd.macaroondir`. Instead the new `--lnd.macaroonpath` option can be
23+
pointed to a single macaroon, for example the `admin.macaroon` or a custom
24+
baked one with the exact permissions needed for Loop. If the now deprecated
25+
flag/option `--lnd.macaroondir` is used, it will fall back to use only the
26+
`admin.macaroon` from that directory.
2127

2228
#### Breaking Changes
2329
* The `AutoOut`, `AutoOutBudgetSat` and `AutoOutBudgetStartSec` fields in the

0 commit comments

Comments
 (0)