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

Bugfix: Pass remote share id and shared secret in OCM call #3852

Merged
merged 18 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"

ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/ocm/provider"
"github.com/cs3org/reva/pkg/ocm/provider/authorizer/registry"
Expand Down Expand Up @@ -118,6 +119,8 @@ func (s *service) GetInfoByDomain(ctx context.Context, req *ocmprovider.GetInfoB
}

func (s *service) IsProviderAllowed(ctx context.Context, req *ocmprovider.IsProviderAllowedRequest) (*ocmprovider.IsProviderAllowedResponse, error) {
log := appctx.GetLogger(ctx)
log.Debug().Msgf("is provider '%s' allowed?", req.Provider.Domain)
err := s.pa.IsProviderAllowed(ctx, req.Provider)
if err != nil {
return &ocmprovider.IsProviderAllowedResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (s *service) getWebdavProtocol(ctx context.Context, share *ocm.Share, m *oc
return &ocmd.WebDAV{
Permissions: perms,
URL: s.webdavURL(ctx, share),
SharedSecret: share.Token,
}
}

Expand Down Expand Up @@ -299,7 +300,9 @@ func (s *service) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareReq
newShareReq := &client.NewShareRequest{
ShareWith: formatOCMUser(req.Grantee.GetUserId()),
Name: ocmshare.Name,
ResourceID: fmt.Sprintf("%s:%s", req.ResourceId.StorageId, req.ResourceId.OpaqueId),
// FIXME: https://github.com/pondersource/nc-sciencemesh/issues/293#issuecomment-1537528109
// ResourceID: fmt.Sprintf("%s:%s", req.ResourceId.StorageId, req.ResourceId.OpaqueId),
ResourceID: ocmshare.Id.OpaqueId,
gmgigi96 marked this conversation as resolved.
Show resolved Hide resolved
Owner: formatOCMUser(&userpb.UserId{
OpaqueId: info.Owner.OpaqueId,
Idp: s.conf.ProviderDomain, // FIXME: this is not generally true in case of resharing
Expand Down
4 changes: 3 additions & 1 deletion internal/http/services/ocmd/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
"github.com/cs3org/reva/internal/http/services/reqres"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/utils"
"github.com/go-playground/validator/v10"
)
Expand Down Expand Up @@ -78,14 +79,15 @@ type createShareRequest struct {
// synchronization between the two services.
func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

log := appctx.GetLogger(ctx)
req, err := getCreateShareRequest(r)
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, err.Error(), nil)
return
}

_, meshProvider, err := getIDAndMeshProvider(req.Sender)
log.Debug().Msgf("Determined Mesh Provider '%s' from req.Sender '%s'", meshProvider, req.Sender)
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, err.Error(), nil)
return
Expand Down
3 changes: 3 additions & 0 deletions internal/http/services/sciencemesh/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {

perm, viewMode := getPermissionsByRole(req.Role)

log.Debug().Msg("calling gatewayClient.CreateOCMShare from sciencemesh/share.go")
shareRes, err := h.gatewayClient.CreateOCMShare(ctx, &ocm.CreateOCMShareRequest{
ResourceId: statRes.Info.Id,
Grantee: &providerpb.Grantee{
Expand All @@ -120,6 +121,8 @@ func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
share.NewWebappAccessMethod(viewMode),
},
})
log.Debug().Msg("called gatewayClient.CreateOCMShare from sciencemesh/share.go")

switch {
case err != nil:
reqres.WriteError(w, r, reqres.APIErrorServerError, "error sending a grpc CreateOCMShare", err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/ocm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/cs3org/reva/internal/http/services/ocmd"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rhttp"
"github.com/pkg/errors"
Expand Down Expand Up @@ -195,6 +196,8 @@ func (c *OCMClient) NewShare(ctx context.Context, endpoint string, r *NewShareRe
return nil, err
}

log := appctx.GetLogger(ctx)
log.Debug().Msgf("Sending OCM /shares POST to %s: %s", url, body)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body)
if err != nil {
return nil, errors.Wrap(err, "error creating request")
Expand Down
3 changes: 3 additions & 0 deletions pkg/ocm/provider/authorizer/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sync"

ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/ocm/provider"
"github.com/cs3org/reva/pkg/ocm/provider/authorizer/registry"
Expand Down Expand Up @@ -114,6 +115,7 @@ func (a *authorizer) GetInfoByDomain(ctx context.Context, domain string) (*ocmpr
}

func (a *authorizer) IsProviderAllowed(ctx context.Context, pi *ocmprovider.ProviderInfo) error {
log := appctx.GetLogger(ctx)
var err error
normalizedDomain, err := normalizeDomain(pi.Domain)
if err != nil {
Expand Down Expand Up @@ -142,6 +144,7 @@ func (a *authorizer) IsProviderAllowed(ctx context.Context, pi *ocmprovider.Prov

var ocmHost string
for _, p := range a.providers {
log.Debug().Msgf("Comparing '%s' to '%s'", p.Domain, normalizedDomain)
if p.Domain == normalizedDomain {
ocmHost, err = a.getOCMHost(p)
if err != nil {
Expand Down