rpcserver: Add flag to BakeMacaroonRequest for allowing external permissions

This commit is contained in:
Turtle committed 2021-09-14 16:27:01 -05:00
1 parent d10a682fa9
commit 72a46b8673
4 files changed
+564 -529

No files matched your search

+542 -528
View File
File diff suppressed because it is too large. Load diff
+6
View File
@@ -3803,6 +3803,12 @@ message BakeMacaroonRequest {
// The root key ID used to create the macaroon, must be a positive integer. // The root key ID used to create the macaroon, must be a positive integer.
uint64 root_key_id = 2; uint64 root_key_id = 2;
/*
Informs the RPC on whether to allow external permissions that LND is not
aware of.
*/
bool allow_external_permissions = 3;
} }
message BakeMacaroonResponse { message BakeMacaroonResponse {
// The hex encoded macaroon, serialized in binary format. // The hex encoded macaroon, serialized in binary format.
+4
View File
@@ -2820,6 +2820,10 @@
"type": "string", "type": "string",
"format": "uint64", "format": "uint64",
"description": "The root key ID used to create the macaroon, must be a positive integer." "description": "The root key ID used to create the macaroon, must be a positive integer."
},
"allow_external_permissions": {
"type": "boolean",
"description": "Informs the RPC on whether to allow external permissions that LND is not\naware of."
} }
} }
}, },
+12 -1
View File
@@ -6799,6 +6799,8 @@ func (r *rpcServer) ChannelAcceptor(stream lnrpc.Lightning_ChannelAcceptorServer
// BakeMacaroon allows the creation of a new macaroon with custom read and write // BakeMacaroon allows the creation of a new macaroon with custom read and write
// permissions. No first-party caveats are added since this can be done offline. // permissions. No first-party caveats are added since this can be done offline.
// If the --allow-external-permissions flag is set, the RPC will allow
// external permissions that LND is not aware of.
func (r *rpcServer) BakeMacaroon(ctx context.Context, func (r *rpcServer) BakeMacaroon(ctx context.Context,
req *lnrpc.BakeMacaroonRequest) (*lnrpc.BakeMacaroonResponse, error) { req *lnrpc.BakeMacaroonRequest) (*lnrpc.BakeMacaroonResponse, error) {
@@ -6821,9 +6823,18 @@ func (r *rpcServer) BakeMacaroon(ctx context.Context,
} }
// Validate and map permission struct used by gRPC to the one used by // Validate and map permission struct used by gRPC to the one used by
// the bakery. // the bakery. If the --allow-external-permissions flag is set, we
// will not validate, but map.
requestedPermissions := make([]bakery.Op, len(req.Permissions)) requestedPermissions := make([]bakery.Op, len(req.Permissions))
for idx, op := range req.Permissions { for idx, op := range req.Permissions {
if req.AllowExternalPermissions {
requestedPermissions[idx] = bakery.Op{
Entity: op.Entity,
Action: op.Action,
}
continue
}
if !stringInSlice(op.Entity, validEntities) { if !stringInSlice(op.Entity, validEntities) {
return nil, fmt.Errorf("invalid permission entity. %s", return nil, fmt.Errorf("invalid permission entity. %s",
helpMsg) helpMsg)