Skip to content

Commit 482fd8d

Browse files
committed
lnrpc+rpcserver: add QoL flag for permission check
To make it even more obvious that by default the permissions to check aren't taken from the full method provided, we add a new flag that does that on request.
1 parent 0f06385 commit 482fd8d

File tree

5 files changed

+636
-539
lines changed

5 files changed

+636
-539
lines changed

itest/lnd_macaroons_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/lightningnetwork/lnd/lnrpc"
1313
"github.com/lightningnetwork/lnd/lntest"
1414
"github.com/lightningnetwork/lnd/lntest/node"
15+
"github.com/lightningnetwork/lnd/lntest/wait"
1516
"github.com/lightningnetwork/lnd/macaroons"
1617
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
@@ -316,6 +317,37 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
316317
require.Error(t, err)
317318
require.Contains(t, err.Error(), "permission denied")
318319
},
320+
}, {
321+
// Check that with the CheckMacaroonPermissions RPC, we can
322+
// check that a macaroon follows the permissions of a given
323+
// method.
324+
name: "default permissions from full method",
325+
run: func(ctxt context.Context, t *testing.T) {
326+
// We test that the macaroon of the test client has
327+
// all the permissions for calling the BakeMacaroon RPC.
328+
mac, err := testNode.ReadMacaroon(
329+
testNode.Cfg.AdminMacPath, wait.DefaultTimeout,
330+
)
331+
require.NoError(t, err)
332+
333+
macBytes, err := mac.MarshalBinary()
334+
require.NoError(t, err)
335+
336+
checkReq := &lnrpc.CheckMacPermRequest{
337+
Macaroon: macBytes,
338+
FullMethod: "/lnrpc.Lightning/BakeMacaroon",
339+
}
340+
checkReq.CheckDefaultPermsFromFullMethod = true
341+
342+
// Test that CheckMacaroonPermissions accurately
343+
// characterizes macaroon as valid, since the admin
344+
// macaroon should have all the permissions.
345+
checkResp, err := testClient.CheckMacaroonPermissions(
346+
ctxt, checkReq,
347+
)
348+
require.NoError(t, err)
349+
require.Equal(t, checkResp.Valid, true)
350+
},
319351
}}
320352

321353
for _, tc := range testCases {

0 commit comments

Comments
 (0)