@@ -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