Skip to content

Commit

Permalink
define permissions for service accounts
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Aug 21, 2023
1 parent ca1b994 commit ae3b406
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/auth/manager/serviceaccounts/serviceaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func (m *manager) Authenticate(ctx context.Context, userID string, secret string
}
return &userpb.User{
// TODO: more details for service users?
Id: &userpb.UserId{OpaqueId: userID},
Id: &userpb.UserId{
OpaqueId: userID,
Type: userpb.UserType_USER_TYPE_SERVICE,
},
}, scope, nil
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,6 @@ func (n *Node) ReadUserPermissions(ctx context.Context, u *userpb.User) (ap prov
return OwnerPermissions(), false, nil
}

if u.Id.GetOpaqueId() == "service-user-id" {
return OwnerPermissions(), false, nil
}

ap = provider.ResourcePermissions{}

// for an efficient group lookup convert the list of groups to a map
Expand Down
20 changes: 20 additions & 0 deletions pkg/storage/utils/decomposedfs/node/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/pkg/appctx"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
Expand Down Expand Up @@ -84,6 +85,21 @@ func OwnerPermissions() provider.ResourcePermissions {
}
}

// ServiceAccountPermissions defines the permissions for nodes when requested by a service account
func ServiceAccountPermissions() provider.ResourcePermissions {
// TODO: Different permissions for different service accounts
return provider.ResourcePermissions{
Stat: true,
ListContainer: true,
GetPath: true, // for search index
InitiateFileUpload: true, // for personal data export
InitiateFileDownload: true, // for full-text-search
RemoveGrant: true, // for share expiry
ListRecycle: true, // for purge-trash-bin command
PurgeRecycle: true, // for purge-trash-bin command
}
}

// Permissions implements permission checks
type Permissions struct {
lu PathLookup
Expand Down Expand Up @@ -113,6 +129,10 @@ func (p *Permissions) assemblePermissions(ctx context.Context, n *Node, failOnTr
return NoPermissions(), nil
}

if u.GetId().GetType() == userpb.UserType_USER_TYPE_SERVICE {
return ServiceAccountPermissions(), nil
}

// are we reading a revision?
if strings.Contains(n.ID, RevisionIDDelimiter) {
// verify revision key format
Expand Down

0 comments on commit ae3b406

Please sign in to comment.