Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move unwrapping and wrapping of paths to the gateway #2016

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/wrap-unwrap-in-gateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: move wrapping and unwrapping of paths to the storage gateway

We've moved the wrapping and unwrapping of reference paths to the storage gateway so that the storageprovider doesn't have to know its mount path.

https://github.com/cs3org/reva/pull/2016
20 changes: 20 additions & 0 deletions internal/grpc/interceptors/auth/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ func checkIfNestedResource(ctx context.Context, ref *provider.Reference, parent

return strings.HasPrefix(childPath, parentPath), nil

// resourcePath := statResponse.Info.Path

// if strings.HasPrefix(ref.GetPath(), resourcePath) {
// // The path corresponds to the resource to which the token has access.
// // We allow access to it.
// return true, nil
// }

// // If we arrived here that could mean that ref.GetPath is not prefixed with the storage mount path but resourcePath is
// // because it was returned by the gateway which will prefix it. To fix that we remove the mount path from the resourcePath.
// // resourcePath = "/users/<name>/some/path"
// // After the split we have [" ", "users", "<name>/some/path"].
// trimmedPath := "/" + strings.SplitN(resourcePath, "/", 3)[2]
// if strings.HasPrefix(ref.GetPath(), trimmedPath) {
// // The path corresponds to the resource to which the token has access.
// // We allow access to it.
// return true, nil
// }

// return false, nil
}

func extractRef(req interface{}) (*provider.Reference, bool) {
Expand Down
18 changes: 12 additions & 6 deletions internal/grpc/services/gateway/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,25 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St
}

log.Info().Msg("mount path will be:" + refPath)
createRefReq := &provider.CreateReferenceRequest{
Ref: &provider.Reference{Path: refPath},
TargetUri: targetURI,
}

c, err := s.findByPath(ctx, refPath)
c, p, err := s.findByPath(ctx, refPath)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
}
return status.NewInternal(ctx, err, "error finding storage provider"), nil
}

pRef, err := unwrap(&provider.Reference{Path: refPath}, p.ProviderPath)
if err != nil {
log.Err(err).Msg("gateway: error unwrapping")
return &rpc.Status{
Code: rpc.Code_CODE_INTERNAL,
}, nil
}
createRefReq := &provider.CreateReferenceRequest{
Ref: pRef,
TargetUri: targetURI,
}
createRefRes, err := c.CreateReference(ctx, createRefReq)
if err != nil {
log.Err(err).Msg("gateway: error calling GetHome")
Expand Down
Loading