@@ -28,6 +28,7 @@ import (
28
28
"github.com/lightningnetwork/lnd/lnrpc"
29
29
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
30
30
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
31
+ "github.com/lightningnetwork/lnd/macaroons"
31
32
"github.com/stretchr/testify/require"
32
33
"golang.org/x/net/http2"
33
34
"google.golang.org/grpc"
@@ -224,6 +225,13 @@ var (
224
225
allowedThroughLNC : false ,
225
226
grpcWebURI : "/litrpc.Sessions/ListSessions" ,
226
227
}}
228
+
229
+ // customURIs is a map of endpoint URIs that we want to allow via a
230
+ // custom-macaroon session type.
231
+ customURIs = map [string ]bool {
232
+ "/lnrpc.Lightning/GetInfo" : true ,
233
+ "/frdrpc.FaradayServer/RevenueReport" : true ,
234
+ }
227
235
)
228
236
229
237
// testModeIntegrated makes sure that in integrated mode all daemons work
@@ -374,6 +382,7 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
374
382
rawLNCConn := setUpLNCConn (
375
383
ctxt , t .t , cfg .LitAddr (), cfg .TLSCertPath ,
376
384
cfg .LitMacPath ,
385
+ litrpc .SessionType_TYPE_MACAROON_READONLY , nil ,
377
386
)
378
387
defer rawLNCConn .Close ()
379
388
@@ -384,6 +393,48 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
384
393
ttt , rawLNCConn , endpoint .requestFn ,
385
394
endpoint .successPattern ,
386
395
endpoint .allowedThroughLNC ,
396
+ "unknown service" ,
397
+ )
398
+ })
399
+ }
400
+ })
401
+
402
+ t .t .Run ("lnc auth custom mac perms" , func (tt * testing.T ) {
403
+ cfg := net .Alice .Cfg
404
+
405
+ ctx := context .Background ()
406
+ ctxt , cancel := context .WithTimeout (ctx , defaultTimeout )
407
+ defer cancel ()
408
+
409
+ customPerms := make (
410
+ []* litrpc.MacaroonPermission , 0 , len (customURIs ),
411
+ )
412
+
413
+ customURIKeyword := macaroons .PermissionEntityCustomURI
414
+ for uri := range customURIs {
415
+ customPerms = append (
416
+ customPerms , & litrpc.MacaroonPermission {
417
+ Entity : customURIKeyword ,
418
+ Action : uri ,
419
+ },
420
+ )
421
+ }
422
+
423
+ rawLNCConn := setUpLNCConn (
424
+ ctxt , t .t , cfg .LitAddr (), cfg .TLSCertPath ,
425
+ cfg .LitMacPath ,
426
+ litrpc .SessionType_TYPE_MACAROON_CUSTOM , customPerms ,
427
+ )
428
+ defer rawLNCConn .Close ()
429
+
430
+ for _ , endpoint := range endpoints {
431
+ endpoint := endpoint
432
+ tt .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
433
+ allowed := customURIs [endpoint .grpcWebURI ]
434
+ runLNCAuthTest (
435
+ ttt , rawLNCConn , endpoint .requestFn ,
436
+ endpoint .successPattern ,
437
+ allowed , "permission denied" ,
387
438
)
388
439
})
389
440
}
@@ -393,7 +444,8 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
393
444
// setUpLNCConn creates a new LNC session and then creates a connection to that
394
445
// session via the mailbox that the session was created with.
395
446
func setUpLNCConn (ctx context.Context , t * testing.T , hostPort , tlsCertPath ,
396
- macPath string ) * grpc.ClientConn {
447
+ macPath string , sessType litrpc.SessionType ,
448
+ customMacPerms []* litrpc.MacaroonPermission ) * grpc.ClientConn {
397
449
398
450
rawConn , err := connectRPC (ctx , hostPort , tlsCertPath )
399
451
require .NoError (t , err )
@@ -406,11 +458,12 @@ func setUpLNCConn(ctx context.Context, t *testing.T, hostPort, tlsCertPath,
406
458
litClient := litrpc .NewSessionsClient (rawConn )
407
459
sessResp , err := litClient .AddSession (ctxm , & litrpc.AddSessionRequest {
408
460
Label : "integration-test" ,
409
- SessionType : litrpc . SessionType_TYPE_MACAROON_READONLY ,
461
+ SessionType : sessType ,
410
462
ExpiryTimestampSeconds : uint64 (
411
463
time .Now ().Add (5 * time .Minute ).Unix (),
412
464
),
413
- MailboxServerAddr : mailboxServerAddr ,
465
+ MailboxServerAddr : mailboxServerAddr ,
466
+ MacaroonCustomPermissions : customMacPerms ,
414
467
})
415
468
require .NoError (t , err )
416
469
@@ -669,7 +722,8 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
669
722
// runLNCAuthTest tests authentication of the given interface when connecting
670
723
// through Lightning Node Connect.
671
724
func runLNCAuthTest (t * testing.T , rawLNCConn grpc.ClientConnInterface ,
672
- makeRequest requestFn , successContent string , callAllowed bool ) {
725
+ makeRequest requestFn , successContent string , callAllowed bool ,
726
+ expectErrContains string ) {
673
727
674
728
ctxt , cancel := context .WithTimeout (
675
729
context .Background (), defaultTimeout ,
@@ -685,7 +739,7 @@ func runLNCAuthTest(t *testing.T, rawLNCConn grpc.ClientConnInterface,
685
739
// Is this a disallowed call?
686
740
if ! callAllowed {
687
741
require .Error (t , err )
688
- require .Contains (t , err .Error (), "unknown service" )
742
+ require .Contains (t , err .Error (), expectErrContains )
689
743
690
744
return
691
745
}
0 commit comments