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.
This commit is contained in:
Oliver Gugger committed 2025-07-21 13:07:43 +02:00
1 parent 66340500e9
commit 6b1c85265f
5 files changed
+680 -543

No files matched your search

+30
View File
@@ -8794,6 +8794,20 @@ func (r *rpcServer) ListPermissions(_ context.Context,
func (r *rpcServer) CheckMacaroonPermissions(ctx context.Context,
req *lnrpc.CheckMacPermRequest) (*lnrpc.CheckMacPermResponse, error) {
// Sanity-check the input parameters to eliminate impossible
// combinations.
switch {
case len(req.Permissions) > 0 && req.CheckDefaultPermsFromFullMethod:
return nil, fmt.Errorf("cannot check default permissions " +
"from full method and from provided permission list " +
"at the same time")
case len(req.FullMethod) == 0 && req.CheckDefaultPermsFromFullMethod:
return nil, fmt.Errorf("cannot check default permissions " +
"from full method without providing the full method " +
"name")
}
// Turn grpc macaroon permission into bakery.Op for the server to
// process.
permissions := make([]bakery.Op, len(req.Permissions))
@@ -8804,6 +8818,22 @@ func (r *rpcServer) CheckMacaroonPermissions(ctx context.Context,
}
}
// If the user wants to check the default permissions for the
// full method, then we'll use the interceptor chain to obtain the
// default permissions for the full method. This overwrites the
// user-provided permissions parsed above, but those are required to be
// empty anyway if the flag is turned on.
if req.CheckDefaultPermsFromFullMethod {
allPerms := r.interceptorChain.Permissions()
methodPerms, ok := allPerms[req.FullMethod]
if !ok {
return nil, fmt.Errorf("no permissions found for "+
"full method %s", req.FullMethod)
}
permissions = methodPerms
}
err := r.macService.CheckMacAuth(
ctx, req.Macaroon, permissions, req.FullMethod,
)