Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: move RequiredPermissions to dedicated dir #371

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 0 additions & 134 deletions macaroons.go
Original file line number Diff line number Diff line change
@@ -1,146 +1,12 @@
package pool

import (
"gopkg.in/macaroon-bakery.v2/bakery"
)

const (
// poolMacaroonLocation is the value we use for the pool macaroons'
// "Location" field when baking them.
poolMacaroonLocation = "pool"
)

var (
// RequiredPermissions is a map of all pool RPC methods and their
// required macaroon permissions to access poold.
RequiredPermissions = map[string][]bakery.Op{
"/poolrpc.Trader/GetInfo": {{
Entity: "account",
Action: "read",
}, {
Entity: "order",
Action: "read",
}, {
Entity: "auction",
Action: "read",
}, {
Entity: "auth",
Action: "read",
}},
"/poolrpc.Trader/StopDaemon": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/QuoteAccount": {{
Entity: "account",
Action: "read",
}},
"/poolrpc.Trader/InitAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/ListAccounts": {{
Entity: "account",
Action: "read",
}},
"/poolrpc.Trader/CloseAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/WithdrawAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/DepositAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/RenewAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/BumpAccountFee": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/RecoverAccounts": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/SubmitOrder": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/ListOrders": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/CancelOrder": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/QuoteOrder": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/AuctionFee": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/Leases": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/BatchSnapshot": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/GetLsatTokens": {{
Entity: "auth",
Action: "read",
}},
"/poolrpc.Trader/LeaseDurations": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/NextBatchInfo": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/NodeRatings": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/BatchSnapshots": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/OfferSidecar": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/RegisterSidecar": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/ExpectSidecarChannel": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/DecodeSidecarTicket": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/ListSidecars": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/CancelSidecar": {{
Entity: "order",
Action: "write",
}},
}

// macDbDefaultPw is the default encryption password used to encrypt the
// pool macaroon database. The macaroon service requires us to set a
// non-nil password so we set it to an empty string. This will cause the
Expand Down
133 changes: 133 additions & 0 deletions perms/perms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package perms

import "gopkg.in/macaroon-bakery.v2/bakery"

// RequiredPermissions is a map of all pool RPC methods and their required
// macaroon permissions to access poold.
var RequiredPermissions = map[string][]bakery.Op{
"/poolrpc.Trader/GetInfo": {{
Entity: "account",
Action: "read",
}, {
Entity: "order",
Action: "read",
}, {
Entity: "auction",
Action: "read",
}, {
Entity: "auth",
Action: "read",
}},
"/poolrpc.Trader/StopDaemon": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/QuoteAccount": {{
Entity: "account",
Action: "read",
}},
"/poolrpc.Trader/InitAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/ListAccounts": {{
Entity: "account",
Action: "read",
}},
"/poolrpc.Trader/CloseAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/WithdrawAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/DepositAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/RenewAccount": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/BumpAccountFee": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/RecoverAccounts": {{
Entity: "account",
Action: "write",
}},
"/poolrpc.Trader/SubmitOrder": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/ListOrders": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/CancelOrder": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/QuoteOrder": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/AuctionFee": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/Leases": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/BatchSnapshot": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/GetLsatTokens": {{
Entity: "auth",
Action: "read",
}},
"/poolrpc.Trader/LeaseDurations": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/NextBatchInfo": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/NodeRatings": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/BatchSnapshots": {{
Entity: "auction",
Action: "read",
}},
"/poolrpc.Trader/OfferSidecar": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/RegisterSidecar": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/ExpectSidecarChannel": {{
Entity: "order",
Action: "write",
}},
"/poolrpc.Trader/DecodeSidecarTicket": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/ListSidecars": {{
Entity: "order",
Action: "read",
}},
"/poolrpc.Trader/CancelSidecar": {{
Entity: "order",
Action: "write",
}},
}
6 changes: 4 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"sync"
"sync/atomic"

"github.com/lightninglabs/pool/perms"

"github.com/btcsuite/btcd/btcec/v2"
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lightninglabs/aperture/lsat"
Expand Down Expand Up @@ -163,7 +165,7 @@ func (s *Server) Start() error {
Checkers: []macaroons.Checker{
macaroons.IPLockChecker,
},
RequiredPerms: RequiredPermissions,
RequiredPerms: perms.RequiredPermissions,
DBPassword: macDbDefaultPw,
LndClient: &s.lndServices.LndServices,
EphemeralKey: lndclient.SharedKeyNUMS,
Expand Down Expand Up @@ -378,7 +380,7 @@ func (s *Server) StartAsSubserver(lndClient lnrpc.LightningClient,
Checkers: []macaroons.Checker{
macaroons.IPLockChecker,
},
RequiredPerms: RequiredPermissions,
RequiredPerms: perms.RequiredPermissions,
DBPassword: macDbDefaultPw,
LndClient: &s.lndServices.LndServices,
EphemeralKey: lndclient.SharedKeyNUMS,
Expand Down