multi: use ReadOnly param of BakeSuperMacaroon

This commit is contained in:
Elle Mouton 2024-10-14 11:00:51 +02:00
parent a59bf2735d
commit b4f8224c54
No known key found for this signature in database
GPG key ID: D7D916376026F177
3 changed files with 12 additions and 5 deletions

View file

@ -32,6 +32,11 @@ var litCommands = []cli.Command{
"specified as a hex string using a " +
"maximum of 8 characters.",
},
cli.BoolFlag{
Name: "read_only",
Usage: "Whether the macaroon should " +
"only contain read permissions.",
},
cli.StringFlag{
Name: "save_to",
Usage: "Save returned admin macaroon to " +
@ -125,6 +130,7 @@ func bakeSuperMacaroon(ctx *cli.Context) error {
resp, err := client.BakeSuperMacaroon(
ctxb, &litrpc.BakeSuperMacaroonRequest{
RootKeyIdSuffix: suffix,
ReadOnly: ctx.Bool("read_only"),
},
)
if err != nil {

View file

@ -187,7 +187,8 @@ type rpcProxy struct {
}
// bakeSuperMac can be used to bake a new super macaroon.
type bakeSuperMac func(ctx context.Context, rootKeyID uint32) (string, error)
type bakeSuperMac func(ctx context.Context, rootKeyID uint32,
readOnly bool) (string, error)
// lndBasicClientFn can be used to obtain access to an lnrpc.LightningClient if
// it is available.
@ -255,7 +256,7 @@ func (p *rpcProxy) BakeSuperMacaroon(ctx context.Context,
return nil, ErrWaitingToStart
}
superMac, err := p.bakeSuperMac(ctx, req.RootKeyIdSuffix)
superMac, err := p.bakeSuperMac(ctx, req.RootKeyIdSuffix, req.ReadOnly)
if err != nil {
return nil, err
}

View file

@ -584,8 +584,8 @@ func (g *LightningTerminal) start() error {
// bakeSuperMac is a closure that can be used to bake a new super
// macaroon that contains all active permissions.
bakeSuperMac := func(ctx context.Context, rootKeyIDSuffix uint32) (
string, error) {
bakeSuperMac := func(ctx context.Context, rootKeyIDSuffix uint32,
readOnly bool) (string, error) {
var suffixBytes [4]byte
binary.BigEndian.PutUint32(suffixBytes[:], rootKeyIDSuffix)
@ -594,7 +594,7 @@ func (g *LightningTerminal) start() error {
return BakeSuperMacaroon(
ctx, g.basicClient, rootKeyID,
g.permsMgr.ActivePermissions(false), nil,
g.permsMgr.ActivePermissions(readOnly), nil,
)
}