Merge pull request #4427 from yyforyongyu/customize-root-key-id
macaroons: customize root key ID
This commit is contained in:
24 files changed
+2144
-777
No files matched your search
@@ -129,6 +129,11 @@ description):
|
||||
* BakeMacaroon
|
||||
* Bakes a new macaroon with the provided list of permissions and
|
||||
restrictions
|
||||
* ListMacaroonIDs
|
||||
* List all the macaroon root key IDs that are in use.
|
||||
* DeleteMacaroonID
|
||||
* Remove a specific macaroon root key ID from the database and invalidates
|
||||
all macaroons derived from the key with that ID.
|
||||
|
||||
## Service: WalletUnlocker
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
"google.golang.org/grpc"
|
||||
"gopkg.in/macaroon-bakery.v2/bakery"
|
||||
)
|
||||
@@ -119,8 +120,9 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
// At this point, we know that the chain notifier macaroon
|
||||
// doesn't yet, exist, so we need to create it with the help of
|
||||
// the main macaroon service.
|
||||
chainNotifierMac, err := cfg.MacService.Oven.NewMacaroon(
|
||||
context.Background(), bakery.LatestVersion, nil,
|
||||
chainNotifierMac, err := cfg.MacService.NewMacaroon(
|
||||
context.Background(),
|
||||
macaroons.DefaultRootKeyID,
|
||||
macaroonOps...,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -99,8 +100,8 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
// At this point, we know that the invoices macaroon doesn't
|
||||
// yet, exist, so we need to create it with the help of the
|
||||
// main macaroon service.
|
||||
invoicesMac, err := cfg.MacService.Oven.NewMacaroon(
|
||||
context.Background(), bakery.LatestVersion, nil,
|
||||
invoicesMac, err := cfg.MacService.NewMacaroon(
|
||||
context.Background(), macaroons.DefaultRootKeyID,
|
||||
macaroonOps...,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -133,6 +133,10 @@ http:
|
||||
- selector: lnrpc.Lightning.BakeMacaroon
|
||||
post: "/v1/macaroon"
|
||||
body: "*"
|
||||
- selector: lnrpc.Lightning.ListMacaroonIDs
|
||||
get: "/v1/macaroon/ids"
|
||||
- selector: lnrpc.Lightning.DeleteMacaroonID
|
||||
delete: "/v1/macaroon/{root_key_id}"
|
||||
|
||||
# walletunlocker.proto
|
||||
- selector: lnrpc.WalletUnlocker.GenSeed
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
|
||||
@@ -164,8 +165,8 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
// At this point, we know that the router macaroon doesn't yet,
|
||||
// exist, so we need to create it with the help of the main
|
||||
// macaroon service.
|
||||
routerMac, err := cfg.MacService.Oven.NewMacaroon(
|
||||
context.Background(), bakery.LatestVersion, nil,
|
||||
routerMac, err := cfg.MacService.NewMacaroon(
|
||||
context.Background(), macaroons.DefaultRootKeyID,
|
||||
macaroonOps...,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
+988
-735
File diff suppressed because it is too large.
Load diff
@@ -1913,6 +1913,78 @@ func local_request_Lightning_BakeMacaroon_0(ctx context.Context, marshaler runti
|
||||
|
||||
}
|
||||
|
||||
func request_Lightning_ListMacaroonIDs_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListMacaroonIDsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.ListMacaroonIDs(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Lightning_ListMacaroonIDs_0(ctx context.Context, marshaler runtime.Marshaler, server LightningServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListMacaroonIDsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.ListMacaroonIDs(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Lightning_DeleteMacaroonID_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeleteMacaroonIDRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["root_key_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "root_key_id")
|
||||
}
|
||||
|
||||
protoReq.RootKeyId, err = runtime.Uint64(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "root_key_id", err)
|
||||
}
|
||||
|
||||
msg, err := client.DeleteMacaroonID(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Lightning_DeleteMacaroonID_0(ctx context.Context, marshaler runtime.Marshaler, server LightningServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeleteMacaroonIDRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["root_key_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "root_key_id")
|
||||
}
|
||||
|
||||
protoReq.RootKeyId, err = runtime.Uint64(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "root_key_id", err)
|
||||
}
|
||||
|
||||
msg, err := server.DeleteMacaroonID(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterLightningHandlerServer registers the http handlers for service Lightning to "mux".
|
||||
// UnaryRPC :call LightningServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
@@ -2874,6 +2946,46 @@ func RegisterLightningHandlerServer(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Lightning_ListMacaroonIDs_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Lightning_ListMacaroonIDs_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_ListMacaroonIDs_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_Lightning_DeleteMacaroonID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Lightning_DeleteMacaroonID_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_DeleteMacaroonID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3975,6 +4087,46 @@ func RegisterLightningHandlerClient(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Lightning_ListMacaroonIDs_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Lightning_ListMacaroonIDs_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_ListMacaroonIDs_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_Lightning_DeleteMacaroonID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Lightning_DeleteMacaroonID_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_DeleteMacaroonID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4084,6 +4236,10 @@ var (
|
||||
pattern_Lightning_SubscribeChannelBackups_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "channels", "backup", "subscribe"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Lightning_BakeMacaroon_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "macaroon"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Lightning_ListMacaroonIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "macaroon", "ids"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Lightning_DeleteMacaroonID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "macaroon", "root_key_id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -4192,4 +4348,8 @@ var (
|
||||
forward_Lightning_SubscribeChannelBackups_0 = runtime.ForwardResponseStream
|
||||
|
||||
forward_Lightning_BakeMacaroon_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Lightning_ListMacaroonIDs_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Lightning_DeleteMacaroonID_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
@@ -491,6 +491,19 @@ service Lightning {
|
||||
offline.
|
||||
*/
|
||||
rpc BakeMacaroon (BakeMacaroonRequest) returns (BakeMacaroonResponse);
|
||||
|
||||
/* lncli: `listmacaroonids`
|
||||
ListMacaroonIDs returns all root key IDs that are in use.
|
||||
*/
|
||||
rpc ListMacaroonIDs (ListMacaroonIDsRequest)
|
||||
returns (ListMacaroonIDsResponse);
|
||||
|
||||
/* lncli: `deletemacaroonid`
|
||||
DeleteMacaroonID deletes the specified macaroon ID and invalidates all
|
||||
macaroons derived from that ID.
|
||||
*/
|
||||
rpc DeleteMacaroonID (DeleteMacaroonIDRequest)
|
||||
returns (DeleteMacaroonIDResponse);
|
||||
}
|
||||
|
||||
message Utxo {
|
||||
@@ -3327,12 +3340,31 @@ message MacaroonPermission {
|
||||
message BakeMacaroonRequest {
|
||||
// The list of permissions the new macaroon should grant.
|
||||
repeated MacaroonPermission permissions = 1;
|
||||
|
||||
// The root key ID used to create the macaroon, must be a positive integer.
|
||||
uint64 root_key_id = 2;
|
||||
}
|
||||
message BakeMacaroonResponse {
|
||||
// The hex encoded macaroon, serialized in binary format.
|
||||
string macaroon = 1;
|
||||
}
|
||||
|
||||
message ListMacaroonIDsRequest {
|
||||
}
|
||||
message ListMacaroonIDsResponse {
|
||||
// The list of root key IDs that are in use.
|
||||
repeated uint64 root_key_ids = 1;
|
||||
}
|
||||
|
||||
message DeleteMacaroonIDRequest {
|
||||
// The root key ID to be removed.
|
||||
uint64 root_key_id = 1;
|
||||
}
|
||||
message DeleteMacaroonIDResponse {
|
||||
// A boolean indicates that the deletion is successful.
|
||||
bool deleted = 1;
|
||||
}
|
||||
|
||||
message Failure {
|
||||
enum FailureCode {
|
||||
/*
|
||||
|
||||
@@ -1426,6 +1426,62 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/macaroon/ids": {
|
||||
"get": {
|
||||
"summary": "lncli: `listmacaroonids`\nListMacaroonIDs returns all root key IDs that are in use.",
|
||||
"operationId": "ListMacaroonIDs",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/lnrpcListMacaroonIDsResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/runtimeError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Lightning"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/macaroon/{root_key_id}": {
|
||||
"delete": {
|
||||
"summary": "lncli: `deletemacaroonid`\nDeleteMacaroonID deletes the specified macaroon ID and invalidates all\nmacaroons derived from that ID.",
|
||||
"operationId": "DeleteMacaroonID",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/lnrpcDeleteMacaroonIDResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/runtimeError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "root_key_id",
|
||||
"description": "The root key ID to be removed.",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"Lightning"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/newaddress": {
|
||||
"get": {
|
||||
"summary": "lncli: `newaddress`\nNewAddress creates a new address under control of the local wallet.",
|
||||
@@ -2399,6 +2455,11 @@
|
||||
"$ref": "#/definitions/lnrpcMacaroonPermission"
|
||||
},
|
||||
"description": "The list of permissions the new macaroon should grant."
|
||||
},
|
||||
"root_key_id": {
|
||||
"type": "string",
|
||||
"format": "uint64",
|
||||
"description": "The root key ID used to create the macaroon, must be a positive integer."
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -3161,6 +3222,16 @@
|
||||
"lnrpcDeleteAllPaymentsResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
"lnrpcDeleteMacaroonIDResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"deleted": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"description": "A boolean indicates that the deletion is successful."
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcDisconnectPeerResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
@@ -4095,6 +4166,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcListMacaroonIDsResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"root_key_ids": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
},
|
||||
"description": "The list of root key IDs that are in use."
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcListPaymentsResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
"google.golang.org/grpc"
|
||||
"gopkg.in/macaroon-bakery.v2/bakery"
|
||||
)
|
||||
@@ -111,8 +112,8 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
// At this point, we know that the signer macaroon doesn't yet,
|
||||
// exist, so we need to create it with the help of the main
|
||||
// macaroon service.
|
||||
signerMac, err := cfg.MacService.Oven.NewMacaroon(
|
||||
context.Background(), bakery.LatestVersion, nil,
|
||||
signerMac, err := cfg.MacService.NewMacaroon(
|
||||
context.Background(), macaroons.DefaultRootKeyID,
|
||||
macaroonOps...,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
"google.golang.org/grpc"
|
||||
"gopkg.in/macaroon-bakery.v2/bakery"
|
||||
@@ -156,8 +157,9 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
|
||||
// At this point, we know that the wallet kit macaroon doesn't
|
||||
// yet, exist, so we need to create it with the help of the
|
||||
// main macaroon service.
|
||||
walletKitMac, err := cfg.MacService.Oven.NewMacaroon(
|
||||
context.Background(), bakery.LatestVersion, nil,
|
||||
walletKitMac, err := cfg.MacService.NewMacaroon(
|
||||
context.Background(),
|
||||
macaroons.DefaultRootKeyID,
|
||||
macaroonOps...,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user