Skip to content

Commit 9cc9740

Browse files
committed
multi: create a read-only perms list
Add a bool parameter to the `getAllPermissions` function to indicate whether or not the permission list should be read only. If so, the list will only include permissions with the "read" action.
1 parent 61ea2d9 commit 9cc9740

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

session_rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
120120
ctx := context.Background()
121121
mac, err := s.superMacBaker(
122122
ctx, sess.MacaroonRootKey, &session.MacaroonRecipe{
123-
Permissions: getAllPermissions(),
123+
Permissions: getAllPermissions(false),
124124
},
125125
)
126126
if err != nil {

subserver_permissions.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ func getAllMethodPermissions() map[string][]bakery.Op {
7575

7676
// getAllPermissions retrieves all the permissions needed to bake a super
7777
// macaroon.
78-
func getAllPermissions() []bakery.Op {
78+
func getAllPermissions(readOnly bool) []bakery.Op {
7979
dedupMap := make(map[string]map[string]bool)
8080

8181
for _, methodPerms := range getAllMethodPermissions() {
8282
for _, methodPerm := range methodPerms {
83+
if readOnly && methodPerm.Action != "read" {
84+
continue
85+
}
86+
8387
if dedupMap[methodPerm.Entity] == nil {
8488
dedupMap[methodPerm.Entity] = make(
8589
map[string]bool,

terminal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func (g *LightningTerminal) startSubservers() error {
509509
// faraday, loop, and pool, all at the same time.
510510
ctx := context.Background()
511511
superMacaroon, err := bakeSuperMacaroon(
512-
ctx, g.basicClient, 0, getAllPermissions(), nil,
512+
ctx, g.basicClient, 0, getAllPermissions(false), nil,
513513
)
514514
if err != nil {
515515
return err

0 commit comments

Comments
 (0)