@@ -28,6 +28,8 @@ import (
28
28
"github.com/lightningnetwork/lnd/signal"
29
29
"github.com/rakyll/statik/fs"
30
30
"google.golang.org/grpc"
31
+ "gopkg.in/macaroon-bakery.v2/bakery"
32
+
31
33
// Import generated go package that contains all static files for the
32
34
// UI in a compressed format.
33
35
_ "github.com/lightninglabs/lightning-terminal/statik"
@@ -136,7 +138,7 @@ func (g *LightningTerminal) Run() error {
136
138
g .cfg .frdrpcCfg = & frdrpc.Config {}
137
139
g .faradayServer = frdrpc .NewRPCServer (g .cfg .frdrpcCfg )
138
140
g .loopServer = loopd .New (g .cfg .Loop , nil )
139
- g .rpcProxy = newRpcProxy (g .cfg , nil , getAllPermissions ())
141
+ g .rpcProxy = newRpcProxy (g .cfg , g , getAllPermissions ())
140
142
141
143
// Hook interceptor for os signals.
142
144
err = signal .Intercept ()
@@ -358,6 +360,36 @@ func (g *LightningTerminal) RegisterRestSubserver(ctx context.Context,
358
360
)
359
361
}
360
362
363
+ // ValidateMacaroon extracts the macaroon from the context's gRPC metadata,
364
+ // checks its signature, makes sure all specified permissions for the called
365
+ // method are contained within and finally ensures all caveat conditions are
366
+ // met. A non-nil error is returned if any of the checks fail.
367
+ func (g * LightningTerminal ) ValidateMacaroon (ctx context.Context ,
368
+ requiredPermissions []bakery.Op , fullMethod string ) error {
369
+
370
+ // Validate all macaroons for services that are running in the local
371
+ // process. Calls that we proxy to a remote host don't need to be
372
+ // checked as they'll have their own interceptor.
373
+ switch {
374
+ case isLoopURI (fullMethod ):
375
+ return g .loopServer .ValidateMacaroon (
376
+ ctx , requiredPermissions , fullMethod ,
377
+ )
378
+
379
+ case isFaradayURI (fullMethod ):
380
+ return g .faradayServer .ValidateMacaroon (
381
+ ctx , requiredPermissions , fullMethod ,
382
+ )
383
+ }
384
+
385
+ // Because lnd will spin up its own gRPC server with macaroon
386
+ // interceptors if it is running in this process, it will check its
387
+ // macaroons there. If lnd is running remotely, that process will check
388
+ // the macaroons. So we don't need to worry about anything other than
389
+ // the subservers that are running in the local process.
390
+ return nil
391
+ }
392
+
361
393
// shutdown stops all subservers that were started and attached to lnd.
362
394
func (g * LightningTerminal ) shutdown () error {
363
395
var returnErr error
0 commit comments