Skip to content

Commit 3e69b05

Browse files
committed
multi: allow custom session with all read-only perms
In this commit, a special case is added to the creation of a custom session to allow the user to specify custom URIs as well as the permissions for all read-only endpoints.
1 parent 15cd1bd commit 3e69b05

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

perms/permissions_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,10 @@ func TestMatchRegexURI(t *testing.T) {
7878
uris, isRegex = m.MatchRegexURI("/poolrpc.Trader/.*")
7979
require.True(t, isRegex)
8080
require.Empty(t, uris)
81+
82+
// Assert that the read-only permission's keyword is not seen as a valid
83+
// regex.
84+
uris, isRegex = m.MatchRegexURI("***readonly***")
85+
require.False(t, isRegex)
86+
require.Empty(t, uris)
8187
}

session_rpcserver.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import (
1919
"gopkg.in/macaroon.v2"
2020
)
2121

22+
// readOnlyAction defines the keyword that a permission action should be set to
23+
// when the entity is set to "uri" in order to activate the special case that
24+
// will result in all read-only permissions known to lit to be added to a
25+
// session's macaroon. The purpose of the three '*'s is to make this keyword
26+
// an invalid URI and an invalid regex so that it does not ever clash with the
27+
// other special cases.
28+
const readOnlyAction = "***readonly***"
29+
2230
// sessionRpcServer is the gRPC server for the Session RPC interface.
2331
type sessionRpcServer struct {
2432
litrpc.UnimplementedSessionsServer
@@ -152,6 +160,20 @@ func (s *sessionRpcServer) AddSession(_ context.Context,
152160
continue
153161
}
154162

163+
// If the action specified was equal to the
164+
// readOnlyAction keyword, then this is taken to mean
165+
// that the permissions for all read-only URIs should be
166+
// granted.
167+
if op.Action == readOnlyAction {
168+
readPerms := s.cfg.permMgr.ActivePermissions(
169+
true,
170+
)
171+
172+
permissions = append(permissions, readPerms...)
173+
174+
continue
175+
}
176+
155177
// First check if this is a regex URI.
156178
uris, isRegex := s.cfg.permMgr.MatchRegexURI(op.Action)
157179
if isRegex {

0 commit comments

Comments
 (0)