Skip to content

Commit eb216af

Browse files
committed
multi: validate macaroons for lit calls
Use the new macaroon service to verify LitURI calls.
1 parent af90cd9 commit eb216af

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ var (
135135
ctx, &litrpc.ListSessionsRequest{},
136136
)
137137
}
138+
litMacaroonFn = func(cfg *LitNodeConfig) string {
139+
return cfg.LitMacPath
140+
}
138141

139142
endpoints = []struct {
140143
name string
@@ -198,16 +201,16 @@ var (
198201
restWebURI: "/v1/pool/info",
199202
}, {
200203
name: "litrpc",
201-
macaroonFn: nil,
204+
macaroonFn: litMacaroonFn,
202205
requestFn: litRequestFn,
203206
// In some test cases we actually expect some sessions, so we
204207
// don't explicitly check for an empty array but just the
205208
// existence of the array in the response.
206209
successPattern: "\"sessions\":[",
207-
supportsMacAuthOnLndPort: false,
208-
supportsMacAuthOnLitPort: false,
209-
supportsUIPasswordOnLndPort: true,
210-
supportsUIPasswordOnLitPort: true,
210+
supportsMacAuthOnLndPort: true,
211+
supportsMacAuthOnLitPort: true,
212+
supportsUIPasswordOnLndPort: false,
213+
supportsUIPasswordOnLitPort: false,
211214
allowedThroughLNC: false,
212215
grpcWebURI: "/litrpc.Sessions/ListSessions",
213216
}}

itest/litd_node.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type LitNodeConfig struct {
6767
LoopMacPath string
6868
PoolMacPath string
6969
LitTLSCertPath string
70+
LitMacPath string
7071

7172
UIPassword string
7273
LitDir string
@@ -279,6 +280,9 @@ func newNode(cfg *LitNodeConfig, harness *NetworkHarness) (*HarnessNode, error)
279280
cfg.PoolMacPath = filepath.Join(
280281
cfg.PoolDir, cfg.NetParams.Name, "pool.macaroon",
281282
)
283+
cfg.LitMacPath = filepath.Join(
284+
cfg.LitDir, cfg.NetParams.Name, "lit.macaroon",
285+
)
282286
cfg.LitTLSCertPath = filepath.Join(cfg.LitDir, "tls.cert")
283287
cfg.GenerateListeningPorts()
284288

rpc_proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
537537
}
538538

539539
case isLitURI(requestURI):
540-
return EmptyMacaroonBytes, nil
540+
macPath = p.cfg.MacaroonPath
541541

542542
default:
543543
return nil, fmt.Errorf("unknown gRPC web request: %v",

subserver_permissions.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ var (
1212
// litPermissions is a map of all LiT RPC methods and their required
1313
// macaroon permissions to access the session service.
1414
litPermissions = map[string][]bakery.Op{
15-
"/litrpc.Sessions/AddSession": {{}},
16-
"/litrpc.Sessions/ListSessions": {{}},
17-
"/litrpc.Sessions/RevokeSession": {{}},
15+
"/litrpc.Sessions/AddSession": {{
16+
Entity: "sessions",
17+
Action: "write",
18+
}},
19+
"/litrpc.Sessions/ListSessions": {{
20+
Entity: "sessions",
21+
Action: "read",
22+
}},
23+
"/litrpc.Sessions/RevokeSession": {{
24+
Entity: "sessions",
25+
Action: "write",
26+
}},
1827
}
1928

2029
// whiteListedMethods is a map of all lnd RPC methods that don't require

terminal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,12 @@ func (g *LightningTerminal) ValidateMacaroon(ctx context.Context,
749749
}
750750

751751
case isLitURI(fullMethod):
752-
wrap := fmt.Errorf("invalid basic auth")
753-
_, err := g.rpcProxy.convertBasicAuth(ctx, fullMethod, wrap)
754-
if err != nil {
752+
if err := g.sessionRpcServer.macaroonService.ValidateMacaroon(
753+
ctx, requiredPermissions, fullMethod,
754+
); err != nil {
755755
return &proxyErr{
756756
proxyContext: "lit",
757-
wrapped: fmt.Errorf("invalid auth: %v",
757+
wrapped: fmt.Errorf("invalid macaroon: %v",
758758
err),
759759
}
760760
}

0 commit comments

Comments
 (0)