session_rpcserver: create readonly session

In this commit, we add the ability to create a read only session type.
This commit is contained in:
Elle Mouton 2022-02-02 13:39:34 +02:00
parent 9cc974037b
commit 725f726571
No known key found for this signature in database
GPG key ID: D7D916376026F177

View file

@ -52,9 +52,12 @@ func (s *sessionRpcServer) AddSession(_ context.Context,
return nil, err
}
if typ != session.TypeUIPassword && typ != session.TypeMacaroonAdmin {
if typ != session.TypeUIPassword && typ != session.TypeMacaroonAdmin &&
typ != session.TypeMacaroonReadonly {
return nil, fmt.Errorf("invalid session type, only UI " +
"password and macaroon admin types supported in LiT")
"password, admin and readonly macaroon types " +
"supported in LiT")
}
sess, err := session.NewSession(
@ -116,11 +119,12 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
case session.TypeUIPassword:
authData = []byte("Authorization: Basic " + s.basicAuth)
case session.TypeMacaroonAdmin:
case session.TypeMacaroonAdmin, session.TypeMacaroonReadonly:
ctx := context.Background()
readOnly := sess.Type == session.TypeMacaroonReadonly
mac, err := s.superMacBaker(
ctx, sess.MacaroonRootKey, &session.MacaroonRecipe{
Permissions: getAllPermissions(false),
Permissions: getAllPermissions(readOnly),
},
)
if err != nil {