Skip to content

Commit b3ad811

Browse files
committed
multi: add Lnd's registered subserver perms
In this commit, we let the PermissionsManager manage LND's subserver permissions. Once Litd is connected to LND, it can get LND's build tags and pass them to the PermissionsManager which will then adjust its list of permissions accordingly.
1 parent c2eb98d commit b3ad811

File tree

5 files changed

+247
-15
lines changed

5 files changed

+247
-15
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"github.com/lightninglabs/pool/poolrpc"
2727
"github.com/lightningnetwork/lnd/keychain"
2828
"github.com/lightningnetwork/lnd/lnrpc"
29+
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
30+
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2931
"github.com/stretchr/testify/require"
3032
"golang.org/x/net/http2"
3133
"google.golang.org/grpc"
@@ -81,17 +83,33 @@ var (
8183
// gRPC request. One byte version and then 4 bytes content length.
8284
emptyGrpcWebRequest = []byte{0, 0, 0, 0, 0}
8385

84-
lndRequestFn = func(ctx context.Context,
86+
lnrpcRequestFn = func(ctx context.Context,
8587
c grpc.ClientConnInterface) (proto.Message, error) {
8688

87-
lndConn := lnrpc.NewLightningClient(c)
88-
return lndConn.GetInfo(
89+
lnrpcConn := lnrpc.NewLightningClient(c)
90+
return lnrpcConn.GetInfo(
8991
ctx, &lnrpc.GetInfoRequest{},
9092
)
9193
}
9294
lndMacaroonFn = func(cfg *LitNodeConfig) string {
9395
return cfg.AdminMacPath
9496
}
97+
routerrpcRequestFn = func(ctx context.Context,
98+
c grpc.ClientConnInterface) (proto.Message, error) {
99+
100+
routerrpcConn := routerrpc.NewRouterClient(c)
101+
return routerrpcConn.GetMissionControlConfig(
102+
ctx, &routerrpc.GetMissionControlConfigRequest{},
103+
)
104+
}
105+
walletrpcRequestFn = func(ctx context.Context,
106+
c grpc.ClientConnInterface) (proto.Message, error) {
107+
108+
walletrpcConn := walletrpc.NewWalletKitClient(c)
109+
return walletrpcConn.ListUnspent(
110+
ctx, &walletrpc.ListUnspentRequest{},
111+
)
112+
}
95113
faradayRequestFn = func(ctx context.Context,
96114
c grpc.ClientConnInterface) (proto.Message, error) {
97115

@@ -145,14 +163,32 @@ var (
145163
allowedThroughLNC bool
146164
grpcWebURI string
147165
restWebURI string
166+
restPOST bool
148167
}{{
149168
name: "lnrpc",
150169
macaroonFn: lndMacaroonFn,
151-
requestFn: lndRequestFn,
170+
requestFn: lnrpcRequestFn,
152171
successPattern: "\"identity_pubkey\":\"0",
153172
allowedThroughLNC: true,
154173
grpcWebURI: "/lnrpc.Lightning/GetInfo",
155174
restWebURI: "/v1/getinfo",
175+
}, {
176+
name: "routerrpc",
177+
macaroonFn: lndMacaroonFn,
178+
requestFn: routerrpcRequestFn,
179+
successPattern: "\"config\":{",
180+
allowedThroughLNC: true,
181+
grpcWebURI: "/routerrpc.Router/GetMissionControlConfig",
182+
restWebURI: "/v2/router/mccfg",
183+
}, {
184+
name: "walletrpc",
185+
macaroonFn: lndMacaroonFn,
186+
requestFn: walletrpcRequestFn,
187+
successPattern: "\"utxos\":[",
188+
allowedThroughLNC: true,
189+
grpcWebURI: "/walletrpc.WalletKit/ListUnspent",
190+
restWebURI: "/v2/wallet/utxos",
191+
restPOST: true,
156192
}, {
157193
name: "frdrpc",
158194
macaroonFn: faradayMacaroonFn,
@@ -322,6 +358,7 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
322358
endpoint.macaroonFn(cfg),
323359
endpoint.restWebURI,
324360
endpoint.successPattern,
361+
endpoint.restPOST,
325362
)
326363
})
327364
}
@@ -529,7 +566,7 @@ func runGRPCWebAuthTest(t *testing.T, hostPort, uiPassword, grpcWebURI string) {
529566

530567
// runRESTAuthTest tests authentication of the given REST interface.
531568
func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
532-
successPattern string) {
569+
successPattern string, usePOST bool) {
533570

534571
basicAuth := base64.StdEncoding.EncodeToString(
535572
[]byte(fmt.Sprintf("%s:%s", uiPassword, uiPassword)),
@@ -539,13 +576,19 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
539576
}
540577
url := fmt.Sprintf("https://%s%s", hostPort, restURI)
541578

579+
method := "GET"
580+
if usePOST {
581+
method = "POST"
582+
}
583+
542584
// First test a REST call without authorization, which should fail.
543-
body, responseHeader, err := callURL(url, "GET", nil, nil, false)
585+
body, responseHeader, err := callURL(url, method, nil, nil, false)
544586
require.NoError(t, err)
545587

546-
require.Equal(
588+
require.Equalf(
547589
t, "application/grpc",
548590
responseHeader.Get("grpc-metadata-content-type"),
591+
"response headers: %v, body: %v", responseHeader, body,
549592
)
550593
require.Equal(
551594
t, "application/json",
@@ -558,7 +601,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
558601

559602
// Now add the UI password which should make the request succeed.
560603
body, responseHeader, err = callURL(
561-
url, "GET", nil, basicAuthHeader, false,
604+
url, method, nil, basicAuthHeader, false,
562605
)
563606
require.NoError(t, err)
564607
require.Contains(t, body, successPattern)
@@ -573,7 +616,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
573616
},
574617
}
575618
body, responseHeader, err = callURL(
576-
url, "GET", nil, macaroonHeader, false,
619+
url, method, nil, macaroonHeader, false,
577620
)
578621
require.NoError(t, err)
579622
require.Contains(t, body, successPattern)

itest/litd_mode_remote_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func testModeRemote(net *NetworkHarness, t *harnessTest) {
125125
endpoint.macaroonFn(cfg),
126126
endpoint.restWebURI,
127127
endpoint.successPattern,
128+
endpoint.restPOST,
128129
)
129130
})
130131
}

make/release_flags.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ windows-386 \
1111
windows-amd64 \
1212
windows-arm
1313

14-
LND_RELEASE_TAGS = litd autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc
14+
LND_RELEASE_TAGS = litd autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc neutrinorpc peersrpc
1515

1616
# By default we will build all systems. But with the 'sys' tag, a specific
1717
# system can be specified. This is useful to release for a subset of

0 commit comments

Comments
 (0)