@@ -10,13 +10,16 @@ import (
10
10
"fmt"
11
11
"io/ioutil"
12
12
"net/http"
13
+ "os"
13
14
"strings"
14
15
"testing"
15
16
"time"
16
17
17
18
"github.com/btcsuite/btcutil"
18
19
"github.com/lightninglabs/faraday/frdrpc"
20
+ terminal "github.com/lightninglabs/lightning-terminal"
19
21
"github.com/lightninglabs/lightning-terminal/litrpc"
22
+ "github.com/lightninglabs/lightning-terminal/session"
20
23
"github.com/lightninglabs/loop/looprpc"
21
24
"github.com/lightninglabs/pool/poolrpc"
22
25
"github.com/lightningnetwork/lnd/lnrpc"
@@ -283,6 +286,46 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
283
286
})
284
287
}
285
288
})
289
+
290
+ t .t .Run ("gRPC super macaroon auth check" , func (tt * testing.T ) {
291
+ cfg := net .Alice .Cfg
292
+
293
+ superMacFile , err := bakeSuperMacaroon (cfg , true )
294
+ require .NoError (tt , err )
295
+
296
+ defer func () {
297
+ _ = os .Remove (superMacFile )
298
+ }()
299
+
300
+ for _ , endpoint := range endpoints {
301
+ endpoint := endpoint
302
+ tt .Run (endpoint .name + " lnd port" , func (ttt * testing.T ) {
303
+ if ! endpoint .supportsMacAuthOnLndPort {
304
+ return
305
+ }
306
+
307
+ runGRPCAuthTest (
308
+ ttt , cfg .RPCAddr (), cfg .TLSCertPath ,
309
+ superMacFile ,
310
+ endpoint .requestFn ,
311
+ endpoint .successPattern ,
312
+ )
313
+ })
314
+
315
+ tt .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
316
+ if ! endpoint .supportsMacAuthOnLitPort {
317
+ return
318
+ }
319
+
320
+ runGRPCAuthTest (
321
+ ttt , cfg .LitAddr (), cfg .TLSCertPath ,
322
+ superMacFile ,
323
+ endpoint .requestFn ,
324
+ endpoint .successPattern ,
325
+ )
326
+ })
327
+ }
328
+ })
286
329
}
287
330
288
331
// runCertificateCheck checks that the TLS certificates presented to clients are
@@ -601,3 +644,51 @@ func connectRPC(ctx context.Context, hostPort,
601
644
602
645
return grpc .DialContext (ctx , hostPort , opts ... )
603
646
}
647
+
648
+ func bakeSuperMacaroon (cfg * LitNodeConfig , readOnly bool ) (string , error ) {
649
+ lndAdminMac := lndMacaroonFn (cfg )
650
+
651
+ ctxb := context .Background ()
652
+ ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
653
+ defer cancel ()
654
+
655
+ rawConn , err := connectRPC (ctxt , cfg .RPCAddr (), cfg .TLSCertPath )
656
+ if err != nil {
657
+ return "" , err
658
+ }
659
+
660
+ lndAdminMacBytes , err := ioutil .ReadFile (lndAdminMac )
661
+ if err != nil {
662
+ return "" , err
663
+ }
664
+ lndAdminCtx := macaroonContext (ctxt , lndAdminMacBytes )
665
+ lndConn := lnrpc .NewLightningClient (rawConn )
666
+
667
+ superMacPermissions := terminal .GetAllPermissions (readOnly )
668
+ nullID := [4 ]byte {}
669
+ superMacHex , err := terminal .BakeSuperMacaroon (
670
+ lndAdminCtx , lndConn , session .NewSuperMacaroonRootKeyID (nullID ),
671
+ superMacPermissions , nil ,
672
+ )
673
+ if err != nil {
674
+ return "" , err
675
+ }
676
+
677
+ // The BakeSuperMacaroon function just hex encoded the macaroon, we know
678
+ // it's valid.
679
+ superMacBytes , _ := hex .DecodeString (superMacHex )
680
+
681
+ tempFile , err := ioutil .TempFile ("" , "lit-super-macaroon" )
682
+ if err != nil {
683
+ _ = os .Remove (tempFile .Name ())
684
+ return "" , err
685
+ }
686
+
687
+ err = ioutil .WriteFile (tempFile .Name (), superMacBytes , 0644 )
688
+ if err != nil {
689
+ _ = os .Remove (tempFile .Name ())
690
+ return "" , err
691
+ }
692
+
693
+ return tempFile .Name (), nil
694
+ }
0 commit comments