* feat: Implemet the vault-storage feat: Separate the storage-users and graph to handle feat: move the space create cache configurate the vault srorage Postprocessing hide the assignment of the MountID to VaultStorageProviderID behind a flag to avoid the ID mismatch configurate the proxy to create the vault home space update the filter Make the graph able to handle vault prefix. no extra service needed apply the vault filter to sharedbyme and sharedwithme added vault-storage docker use squashed reva fix the finishUpload event restict webdav copy/move from the vault feat: provide the mfa to webdav and grpc feat: refactoring: provide the mfa to webdav and grpc mfa collaboration fix GetRootDriveChildren and more fix: send the MFA header in HTTP clients from the collaboration service provide the default storage user vault configuration update create_home middleware Update deployments/examples/ocis_full/vault-storage.yml Co-authored-by: Martin <github@diemattels.at> Update services/gateway/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/graph/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/graph/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/storage-users/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/proxy/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/storage-users/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update deployments/examples/ocis_full/vault-storage.yml Co-authored-by: Martin <github@diemattels.at> bump reva deduplicate the requireMFA middeware on vault routes. fix AppendPlainToOpaque. added the changlog and comments * feat: add the vault mode search * Update changelog/unreleased/enhancement-vault-storage.md Co-authored-by: Martin <github@diemattels.at> * update the readme. the reva vault storage provider configuration disabled by default * feat: [OCISDEV-531] add vault capabilities to the OCS capabilities endpoint * the port range allocated. the configuration updated. --------- Co-authored-by: Martin <github@diemattels.at>
146 lines
4.2 KiB
Go
146 lines
4.2 KiB
Go
package imgsource
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
|
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
|
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
|
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/config"
|
|
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/errors"
|
|
"github.com/owncloud/reva/v2/pkg/bytesize"
|
|
revactx "github.com/owncloud/reva/v2/pkg/ctx"
|
|
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
|
|
"github.com/owncloud/reva/v2/pkg/rhttp"
|
|
"github.com/owncloud/reva/v2/pkg/storagespace"
|
|
gmmetadata "go-micro.dev/v4/metadata"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
const (
|
|
// TokenTransportHeader holds the header key for the reva transfer token
|
|
// "github.com/owncloud/reva/v2/internal/http/services/datagateway" is internal so we redeclare it here
|
|
TokenTransportHeader = "X-Reva-Transfer"
|
|
)
|
|
|
|
// CS3 implements a CS3 image source
|
|
type CS3 struct {
|
|
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
|
|
insecure bool
|
|
maxImageFileSize uint64
|
|
}
|
|
|
|
// NewCS3Source configures a new CS3 image source
|
|
func NewCS3Source(cfg config.Thumbnail, gatewaySelector pool.Selectable[gateway.GatewayAPIClient], b bytesize.ByteSize) CS3 {
|
|
return CS3{
|
|
gatewaySelector: gatewaySelector,
|
|
insecure: cfg.CS3AllowInsecure,
|
|
maxImageFileSize: b.Bytes(),
|
|
}
|
|
}
|
|
|
|
// Get downloads the file from a cs3 service
|
|
// The caller MUST make sure to close the returned ReadCloser
|
|
func (s CS3) Get(ctx context.Context, path string) (io.ReadCloser, error) {
|
|
auth, ok := ContextGetAuthorization(ctx)
|
|
if !ok {
|
|
return nil, errors.ErrCS3AuthorizationMissing
|
|
}
|
|
ref, err := storagespace.ParseReference(path)
|
|
if err != nil {
|
|
// If the path is not a spaces reference try to handle it like a plain
|
|
// path reference.
|
|
ref = provider.Reference{
|
|
Path: path,
|
|
}
|
|
}
|
|
|
|
ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, auth)
|
|
|
|
// Bridge MFA status from go-micro metadata into outgoing gRPC metadata.
|
|
// The autoprop-prefixed key is then forwarded automatically at every
|
|
// subsequent gRPC hop by the metadata interceptor.
|
|
if md, ok := gmmetadata.FromContext(ctx); ok {
|
|
if v, ok := md.Get(revactx.MFAOutgoingHeader); ok && v != "" {
|
|
ctx = metadata.AppendToOutgoingContext(ctx, revactx.MFAOutgoingHeader, v)
|
|
}
|
|
}
|
|
|
|
err = s.checkImageFileSize(ctx, ref)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gwc, err := s.gatewaySelector.Next()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rsp, err := gwc.InitiateFileDownload(ctx, &provider.InitiateFileDownloadRequest{Ref: &ref})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if rsp.GetStatus().GetCode() != rpc.Code_CODE_OK {
|
|
return nil, fmt.Errorf("could not load image: %s", rsp.GetStatus().GetMessage())
|
|
}
|
|
var ep, tk string
|
|
for _, p := range rsp.GetProtocols() {
|
|
if p.GetProtocol() == "spaces" {
|
|
ep, tk = p.GetDownloadEndpoint(), p.GetToken()
|
|
break
|
|
}
|
|
}
|
|
if (ep == "" || tk == "") && len(rsp.GetProtocols()) > 0 {
|
|
ep, tk = rsp.GetProtocols()[0].GetDownloadEndpoint(), rsp.GetProtocols()[0].GetToken()
|
|
}
|
|
|
|
httpReq, err := rhttp.NewRequest(ctx, "GET", ep, nil)
|
|
tracing.InjectTracingHeaders(ctx, httpReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
httpReq.Header.Set(revactx.TokenHeader, auth)
|
|
httpReq.Header.Set(TokenTransportHeader, tk)
|
|
|
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
|
|
MinVersion: tls.VersionTLS12,
|
|
InsecureSkipVerify: s.insecure, //nolint:gosec
|
|
}
|
|
client := &http.Client{}
|
|
|
|
resp, err := client.Do(httpReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return nil, fmt.Errorf("could not get the image \"%s\". Request returned with statuscode %d ", path, resp.StatusCode)
|
|
}
|
|
|
|
return resp.Body, nil
|
|
}
|
|
|
|
func (s CS3) checkImageFileSize(ctx context.Context, ref provider.Reference) error {
|
|
gwc, err := s.gatewaySelector.Next()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
stat, err := gwc.Stat(ctx, &provider.StatRequest{Ref: &ref})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if stat.GetStatus().GetCode() != rpc.Code_CODE_OK {
|
|
return fmt.Errorf("could not stat image: %s", stat.GetStatus().GetMessage())
|
|
}
|
|
if stat.GetInfo().GetSize() > s.maxImageFileSize {
|
|
return errors.ErrImageTooLarge
|
|
}
|
|
return nil
|
|
}
|