-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrpc_auth.go
More file actions
273 lines (243 loc) · 7.41 KB
/
Copy pathrpc_auth.go
File metadata and controls
273 lines (243 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package waved
import (
"fmt"
"github.com/lightninglabs/wavelength/rpc/swapclientrpc"
"github.com/lightninglabs/wavelength/rpc/wavewalletrpc"
"github.com/lightninglabs/wavelength/waverpc"
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
)
// wavedMacaroonLocation is the "Location" field stamped into every macaroon
// the daemon bakes. It identifies the issuing daemon, not a permission scope.
const wavedMacaroonLocation = "waved"
// Macaroon entities slice the daemon's RPC surface into logical domains. Each
// method requires one or more (entity, action) pairs, so operators can mint
// least-privilege macaroons scoped to a single domain — read-only fee data, a
// swap-only token — instead of the all-or-nothing token a single entity would
// force. Modeled on lnd's per-entity permission map.
const (
// entityInfo covers daemon and wallet status plus the seed/unlock
// lifecycle.
entityInfo = "info"
// entityVTXO covers VTXO inventory, in-round sends, refreshes, and
// forfeit signing.
entityVTXO = "vtxo"
// entityAddress covers receive scripts, addresses, and receive-auth
// key material.
entityAddress = "address"
// entityOnChain covers boarding, on-chain sends, sweeps, and
// unilateral exit.
entityOnChain = "onchain"
// entityOOR covers out-of-round send sessions.
entityOOR = "oor"
// entityRound covers round participation and round queries.
entityRound = "round"
// entitySwap covers the swap subsystem.
entitySwap = "swap"
// entityRecovery covers vHTLC on-chain recovery jobs.
entityRecovery = "recovery"
// entityFees covers operator fee estimation and history.
entityFees = "fees"
// entityActivity covers the unified ledger, transaction history, and
// activity inspection.
entityActivity = "activity"
)
// wavedEntities is the full set of logical macaroon entities. The read-only
// macaroon grants read on each of them, and every method's required ops must
// name one of these entities.
var wavedEntities = []string{
entityInfo,
entityVTXO,
entityAddress,
entityOnChain,
entityOOR,
entityRound,
entitySwap,
entityRecovery,
entityFees,
entityActivity,
}
var wavedRPCPermissions = newWavedRPCPermissions()
// newWavedRPCPermissions returns the local daemon's explicit macaroon policy.
// Methods are grouped by logical entity and action so the taxonomy — which
// domain each call belongs to — is legible at a glance.
func newWavedRPCPermissions() map[string][]bakery.Op {
permissions := make(map[string][]bakery.Op)
// grant records that every listed method of service requires the given
// action on entity. Each method gets its own fresh op slice so callers
// never alias a shared backing array.
grant := func(service, entity, action string, methods ...string) {
for _, method := range methods {
fullMethod := "/" + service + "/" + method
permissions[fullMethod] = []bakery.Op{{
Entity: entity,
Action: action,
}}
}
}
daemon := waverpc.DaemonService_ServiceDesc.ServiceName
grant(daemon, entityInfo, "read",
"GetInfo", "GetBalance",
)
grant(
daemon, entityInfo, "write", "GenSeed", "InitWallet",
"UnlockWallet",
)
grant(
daemon, entityVTXO, "read", "ListVTXOs",
"GetIndexedVTXOByPkScript", "GetVTXOExpiryInfo",
"ListPendingForfeitParticipantSignatureRequests",
)
grant(
daemon, entityVTXO, "write", "SendVTXO", "SignVTXOForfeit",
"RefreshVTXOs", "RefreshCustomVTXOs",
"SubmitForfeitParticipantSignatures", "LeaveVTXOs",
)
grant(
daemon, entityAddress, "write", "NewAddress",
"NewReceiveScript", "ReceiveAuthKey", "SignReceiveAuthMessage",
"SignReceiveAuthMessageCompact", "ReceiveAuthECDH",
)
grant(
daemon, entitySwap, "write", "SignOutSwapHtlcAck",
"SignCreditAccountAuthorization",
)
grant(
daemon, entityOOR, "read", "GetIndexedOORSessionByTxid",
"ListOORSessions", "GetOORSession",
)
grant(
daemon, entityOOR, "write", "SendOOR", "PrepareOOR",
"SignOORCustomInput",
)
grant(
daemon, entityOnChain, "read", "ListBoardingSweeps",
"GetUnrollStatus",
)
grant(
daemon, entityOnChain, "write", "SendOnChain", "Board",
"SweepBoardingUTXOs", "Unroll",
)
grant(
daemon, entityRound, "read", "ListRounds", "GetRound",
"WatchRounds",
)
grant(daemon, entityRound, "write",
"JoinNextRound",
)
grant(daemon, entityFees, "read",
"EstimateFee", "GetFeeHistory",
)
grant(daemon, entityActivity, "read",
"ListTransactions",
)
grant(
daemon, entityRecovery, "read", "GetVHTLCRecoveryStatus",
"ListVHTLCRecoveries",
)
grant(
daemon, entityRecovery, "write", "ArmVHTLCRecovery",
"EscalateVHTLCRecovery", "CancelVHTLCRecovery",
)
swap := swapclientrpc.SwapClientService_ServiceDesc.ServiceName
grant(
swap, entitySwap, "read", "QuotePay", "ListSwaps", "GetSwap",
"SubscribeSwaps", "ListCredits",
)
grant(
swap, entitySwap, "write", "StartPay", "StartReceive",
"ResumeSwap", "CreateCredit", "RedeemCredit",
)
wavewalletdk := wavewalletrpc.WalletService_ServiceDesc.ServiceName
grant(
wavewalletdk, entityInfo, "read", "Balance", "Status",
"SubscribeWallet",
)
grant(wavewalletdk, entityInfo, "write",
"Create", "Unlock",
)
grant(wavewalletdk, entityActivity, "read",
"List",
)
grant(wavewalletdk, entityAddress, "write",
"Recv",
)
grant(
wavewalletdk, entityOnChain, "read", "GetExitPlan",
"ExitStatus", "ExitSummary",
)
grant(
wavewalletdk, entityOnChain, "write", "PrepareSend", "Send",
"Deposit", "SweepWallet", "Exit",
)
inspect := wavewalletrpc.WalletInspectionService_ServiceDesc.ServiceName
grant(inspect, entityActivity, "read",
"InspectActivity",
)
grant("walletrpc.VersionService", entityInfo, "read",
"Version",
)
grant(
"walletrpc.WalletService", entityInfo, "read", "Ping",
"Network",
)
grant(
"walletrpc.WalletService", entityInfo, "write",
"ChangePassphrase",
)
grant(
"walletrpc.WalletService", entityActivity, "read",
"GetTransactions", "TransactionNotifications",
)
grant(
"walletrpc.WalletService", entityAddress, "write",
"NextAddress",
)
grant(
"walletrpc.WalletService", entityOnChain, "read",
"AccountNumber", "Accounts", "Balance",
"SpentnessNotifications", "AccountNotifications",
)
grant(
"walletrpc.WalletService", entityOnChain, "write",
"RenameAccount", "NextAccount", "ImportPrivateKey",
"FundTransaction", "SignTransaction", "PublishTransaction",
)
return permissions
}
// wavedReadOnlyPermissions returns the read op for every logical entity. A
// macaroon baked with these ops can invoke every read method across the daemon
// surface but no mutating method — the daemon's equivalent of lnd's
// readonly.macaroon.
func wavedReadOnlyPermissions() []bakery.Op {
ops := make([]bakery.Op, 0, len(wavedEntities))
for _, entity := range wavedEntities {
ops = append(ops, bakery.Op{
Entity: entity,
Action: "read",
})
}
return ops
}
// registeredRPCPermissions maps every registered gRPC method to the macaroon
// permission it requires.
func registeredRPCPermissions(grpcServer *grpc.Server) (map[string][]bakery.Op,
error) {
info := grpcServer.GetServiceInfo()
permissions := make(map[string][]bakery.Op)
for serviceName, serviceInfo := range info {
for _, method := range serviceInfo.Methods {
fullMethod := "/" + serviceName + "/" + method.Name
ops, ok := wavedRPCPermissions[fullMethod]
if !ok {
return nil, fmt.Errorf("no macaroon "+
"permission registered for %s",
fullMethod)
}
permissions[fullMethod] = append(
[]bakery.Op(nil), ops...,
)
}
}
return permissions, nil
}