Skip to content

Commit b12d226

Browse files
committed
lit: create litMacValidator
a type which implements the macaroons.MacaroonValidator interface which purely authenticates a call against LiT's macaroon service. Then, make this available to the rpc proxy. It is not used yet.
1 parent 5430e6d commit b12d226

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

rpc_proxy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ func (e *proxyErr) Unwrap() error {
6666
// newRpcProxy creates a new RPC proxy that can take any native gRPC, grpc-web
6767
// or REST request and delegate (and convert if necessary) it to the correct
6868
// component.
69-
func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
69+
func newRpcProxy(cfg *Config, validator,
70+
litMacValidator macaroons.MacaroonValidator,
7071
superMacValidator session.SuperMacaroonValidator,
7172
permsMgr *perms.Manager, subServerMgr *subservers.Manager,
7273
statusMgr *litstatus.Manager) *rpcProxy {
@@ -87,6 +88,7 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
8788
cfg: cfg,
8889
basicAuth: basicAuth,
8990
permsMgr: permsMgr,
91+
litMacValidator: litMacValidator,
9092
macValidator: validator,
9193
superMacValidator: superMacValidator,
9294
subServerMgr: subServerMgr,
@@ -169,6 +171,7 @@ type rpcProxy struct {
169171

170172
bakeSuperMac bakeSuperMac
171173

174+
litMacValidator macaroons.MacaroonValidator
172175
macValidator macaroons.MacaroonValidator
173176
superMacValidator session.SuperMacaroonValidator
174177

terminal.go

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ func (g *LightningTerminal) Run() error {
296296
// Construct the rpcProxy. It must be initialised before the main web
297297
// server is started.
298298
g.rpcProxy = newRpcProxy(
299-
g.cfg, g, g.validateSuperMacaroon, g.permsMgr, g.subServerMgr,
300-
g.statusMgr,
299+
g.cfg, g, &litMacValidator{g}, g.validateSuperMacaroon,
300+
g.permsMgr, g.subServerMgr, g.statusMgr,
301301
)
302302

303303
// Register any gRPC services that should be served using LiT's
@@ -1212,19 +1212,12 @@ func (g *LightningTerminal) ValidateMacaroon(ctx context.Context,
12121212
}
12131213

12141214
if g.permsMgr.IsSubServerURI(subservers.LIT, fullMethod) {
1215-
if !g.macaroonServiceStarted {
1216-
return fmt.Errorf("the macaroon service has not " +
1217-
"started yet")
1218-
}
1219-
1220-
if err := g.macaroonService.ValidateMacaroon(
1215+
validator := &litMacValidator{g}
1216+
err = validator.ValidateMacaroon(
12211217
ctx, requiredPermissions, fullMethod,
1222-
); err != nil {
1223-
return &proxyErr{
1224-
proxyContext: "lit",
1225-
wrapped: fmt.Errorf("invalid macaroon: %w",
1226-
err),
1227-
}
1218+
)
1219+
if err != nil {
1220+
return err
12281221
}
12291222
}
12301223

@@ -1236,6 +1229,40 @@ func (g *LightningTerminal) ValidateMacaroon(ctx context.Context,
12361229
return nil
12371230
}
12381231

1232+
// litMacValidator wraps the LightningTerminal struct and uses it to implement
1233+
// the macaroons.ValidateMacaroon interface. Unlike the LightningTerminal's
1234+
// ValidateMacaroon method which does whitelist checks and possibly uses a
1235+
// different sub-server's macaroon validator, this implementation uses only
1236+
// LiT's own macaroon service to verify the call.
1237+
type litMacValidator struct {
1238+
*LightningTerminal
1239+
}
1240+
1241+
// ValidateMacaroon checks that the given call is properly authenticated
1242+
// according to LiT's macaroon service.
1243+
//
1244+
// NOTE: This is part of the macaroons.ValidateMacaroon interface.
1245+
func (g *litMacValidator) ValidateMacaroon(ctx context.Context,
1246+
requiredPermissions []bakery.Op, fullMethod string) error {
1247+
1248+
if !g.macaroonServiceStarted {
1249+
return fmt.Errorf("the macaroon service has not " +
1250+
"started yet")
1251+
}
1252+
1253+
if err := g.macaroonService.ValidateMacaroon(
1254+
ctx, requiredPermissions, fullMethod,
1255+
); err != nil {
1256+
return &proxyErr{
1257+
proxyContext: "lit",
1258+
wrapped: fmt.Errorf("invalid macaroon: %w",
1259+
err),
1260+
}
1261+
}
1262+
1263+
return nil
1264+
}
1265+
12391266
// Permissions returns all permissions for which the external validator of the
12401267
// terminal is responsible.
12411268
//

0 commit comments

Comments
 (0)