Skip to content

Commit

Permalink
expand token validation for public links
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 30, 2024
1 parent 958b13f commit a5639f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/grpc/interceptors/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package auth

import (
"context"
"fmt"
"time"

"github.com/bluele/gcache"
Expand Down Expand Up @@ -199,6 +200,7 @@ func (ss *wrappedServerStream) Context() context.Context {
}

func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token.Manager, gatewayAddr string, unprotected bool) (*userpb.User, map[string]*authpb.Scope, error) {
fmt.Println(tkn)
u, tokenScope, err := mgr.DismantleToken(ctx, tkn)
if err != nil {
return nil, nil, err
Expand Down
10 changes: 8 additions & 2 deletions internal/grpc/interceptors/auth/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func expandAndVerifyScope(ctx context.Context, req interface{}, tokenScope map[s
if err != nil {
return err
}
log.Trace().Msg("Extracting scope from token")
log.Trace().Msgf("Extracting scope:%+v from token", tokenScope)
if ref, ok := extractRef(req, tokenScope); ok {
// The request is for a storage reference. This can be the case for multiple scenarios:
// - If the path is not empty, the request might be coming from a share where the accessor is
Expand Down Expand Up @@ -87,7 +87,7 @@ func expandAndVerifyScope(ctx context.Context, req interface{}, tokenScope map[s
}
}
} else {
log.Trace().Msg("Token scope is not ok")
log.Trace().Msgf("Token scope is not ok. req:%+v, tokenScope:%+v", req, tokenScope, req, tokenScope)
}

if checkLightweightScope(ctx, req, tokenScope, client) {
Expand Down Expand Up @@ -322,6 +322,8 @@ func checkIfNestedResource(ctx context.Context, ref *provider.Reference, parent
func extractRefForReaderRole(req interface{}) (*provider.Reference, bool) {
switch v := req.(type) {
// Read requests
case *provider.GetPathRequest:
return &provider.Reference{ResourceId: v.ResourceId}, true
case *registry.GetStorageProvidersRequest:
return v.GetRef(), true
case *provider.StatRequest:
Expand All @@ -348,6 +350,8 @@ func extractRefForReaderRole(req interface{}) (*provider.Reference, bool) {
func extractRefForUploaderRole(req interface{}) (*provider.Reference, bool) {
switch v := req.(type) {
// Write Requests
case *provider.GetPathRequest:
return &provider.Reference{ResourceId: v.ResourceId}, true
case *registry.GetStorageProvidersRequest:
return v.GetRef(), true
case *provider.StatRequest:
Expand All @@ -366,6 +370,8 @@ func extractRefForUploaderRole(req interface{}) (*provider.Reference, bool) {
func extractRefForEditorRole(req interface{}) (*provider.Reference, bool) {
switch v := req.(type) {
// Remaining edit Requests
case *provider.GetPathRequest:
return &provider.Reference{ResourceId: v.ResourceId}, true
case *provider.DeleteRequest:
return v.GetRef(), true
case *provider.MoveRequest:
Expand Down

0 comments on commit a5639f4

Please sign in to comment.