2022-02-11 12:25:05 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-03-17 08:17:45 +00:00
|
|
|
"errors"
|
2022-02-11 12:25:05 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
objectV2 "github.com/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2023-01-20 09:57:53 +00:00
|
|
|
apistatus "github.com/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/container/acl"
|
|
|
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
sessionSDK "github.com/TrueCloudLab/frostfs-sdk-go/session"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/user"
|
2022-02-11 12:25:05 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Service checks basic ACL rules.
|
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
|
|
|
|
c senderClassifier
|
|
|
|
}
|
|
|
|
|
|
|
|
type putStreamBasicChecker struct {
|
|
|
|
source *Service
|
|
|
|
next object.PutObjectStream
|
|
|
|
}
|
|
|
|
|
|
|
|
type getStreamBasicChecker struct {
|
|
|
|
checker ACLChecker
|
|
|
|
|
|
|
|
object.GetObjectStream
|
|
|
|
|
|
|
|
info RequestInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
type rangeStreamBasicChecker struct {
|
|
|
|
checker ACLChecker
|
|
|
|
|
|
|
|
object.GetObjectRangeStream
|
|
|
|
|
|
|
|
info RequestInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
type searchStreamBasicChecker struct {
|
|
|
|
checker ACLChecker
|
|
|
|
|
|
|
|
object.SearchStream
|
|
|
|
|
|
|
|
info RequestInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents Service constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2022-09-28 07:41:01 +00:00
|
|
|
log *logger.Logger
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
containers container.Source
|
|
|
|
|
|
|
|
checker ACLChecker
|
|
|
|
|
|
|
|
irFetcher InnerRingFetcher
|
|
|
|
|
2022-03-29 12:49:39 +00:00
|
|
|
nm netmap.Source
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
next object.ServiceServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New is a constructor for object ACL checking service.
|
|
|
|
func New(opts ...Option) Service {
|
|
|
|
cfg := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](cfg)
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
panicOnNil := func(v any, name string) {
|
2022-02-11 12:25:05 +00:00
|
|
|
if v == nil {
|
|
|
|
panic(fmt.Sprintf("ACL service: %s is nil", name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panicOnNil(cfg.next, "next Service")
|
|
|
|
panicOnNil(cfg.nm, "netmap client")
|
|
|
|
panicOnNil(cfg.irFetcher, "inner Ring fetcher")
|
|
|
|
panicOnNil(cfg.checker, "acl checker")
|
|
|
|
panicOnNil(cfg.containers, "container source")
|
|
|
|
|
|
|
|
return Service{
|
|
|
|
cfg: cfg,
|
|
|
|
c: senderClassifier{
|
|
|
|
log: cfg.log,
|
|
|
|
innerRing: cfg.irFetcher,
|
|
|
|
netmap: cfg.nm,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get implements ServiceServer interface, makes ACL checks and calls
|
|
|
|
// next Get method in the ServiceServer pipeline.
|
|
|
|
func (b Service) Get(request *objectV2.GetRequest, stream object.GetObjectStream) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := getContainerIDFromRequest(request)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
obj, err := getObjectIDFromRequestBody(request.GetBody())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
sTok, err := originalSessionToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if sTok != nil {
|
|
|
|
err = assertSessionRelation(*sTok, cnr, obj)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, cnr, acl.OpObjectGet)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
reqInfo.obj = obj
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
if !b.checker.CheckBasicACL(reqInfo) {
|
|
|
|
return basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := b.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b.next.Get(request, &getStreamBasicChecker{
|
|
|
|
GetObjectStream: stream,
|
|
|
|
info: reqInfo,
|
|
|
|
checker: b.checker,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Service) Put(ctx context.Context) (object.PutObjectStream, error) {
|
|
|
|
streamer, err := b.next.Put(ctx)
|
|
|
|
|
|
|
|
return putStreamBasicChecker{
|
|
|
|
source: &b,
|
|
|
|
next: streamer,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Service) Head(
|
|
|
|
ctx context.Context,
|
|
|
|
request *objectV2.HeadRequest) (*objectV2.HeadResponse, error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := getContainerIDFromRequest(request)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
obj, err := getObjectIDFromRequestBody(request.GetBody())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
sTok, err := originalSessionToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if sTok != nil {
|
|
|
|
err = assertSessionRelation(*sTok, cnr, obj)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, cnr, acl.OpObjectHead)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
reqInfo.obj = obj
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
if !b.checker.CheckBasicACL(reqInfo) {
|
|
|
|
return nil, basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := b.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return nil, eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := b.next.Head(ctx, request)
|
|
|
|
if err == nil {
|
2022-03-18 11:04:32 +00:00
|
|
|
if err = b.checker.CheckEACL(resp, reqInfo); err != nil {
|
|
|
|
err = eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Service) Search(request *objectV2.SearchRequest, stream object.SearchStream) error {
|
|
|
|
id, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
sTok, err := originalSessionToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if sTok != nil {
|
|
|
|
err = assertSessionRelation(*sTok, id, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2022-05-18 15:20:08 +00:00
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, id, acl.OpObjectSearch)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !b.checker.CheckBasicACL(reqInfo) {
|
|
|
|
return basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := b.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b.next.Search(request, &searchStreamBasicChecker{
|
|
|
|
checker: b.checker,
|
|
|
|
SearchStream: stream,
|
|
|
|
info: reqInfo,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Service) Delete(
|
|
|
|
ctx context.Context,
|
|
|
|
request *objectV2.DeleteRequest) (*objectV2.DeleteResponse, error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := getContainerIDFromRequest(request)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
obj, err := getObjectIDFromRequestBody(request.GetBody())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
sTok, err := originalSessionToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if sTok != nil {
|
|
|
|
err = assertSessionRelation(*sTok, cnr, obj)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, cnr, acl.OpObjectDelete)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
reqInfo.obj = obj
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
if !b.checker.CheckBasicACL(reqInfo) {
|
|
|
|
return nil, basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := b.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return nil, eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b.next.Delete(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Service) GetRange(request *objectV2.GetRangeRequest, stream object.GetObjectRangeStream) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := getContainerIDFromRequest(request)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
obj, err := getObjectIDFromRequestBody(request.GetBody())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
sTok, err := originalSessionToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if sTok != nil {
|
|
|
|
err = assertSessionRelation(*sTok, cnr, obj)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, cnr, acl.OpObjectRange)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
reqInfo.obj = obj
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
if !b.checker.CheckBasicACL(reqInfo) {
|
|
|
|
return basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := b.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b.next.GetRange(request, &rangeStreamBasicChecker{
|
|
|
|
checker: b.checker,
|
|
|
|
GetObjectRangeStream: stream,
|
|
|
|
info: reqInfo,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Service) GetRangeHash(
|
|
|
|
ctx context.Context,
|
|
|
|
request *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := getContainerIDFromRequest(request)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
obj, err := getObjectIDFromRequestBody(request.GetBody())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
sTok, err := originalSessionToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if sTok != nil {
|
|
|
|
err = assertSessionRelation(*sTok, cnr, obj)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, cnr, acl.OpObjectHash)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
reqInfo.obj = obj
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
if !b.checker.CheckBasicACL(reqInfo) {
|
|
|
|
return nil, basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := b.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return nil, eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b.next.GetRangeHash(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p putStreamBasicChecker) Send(request *objectV2.PutRequest) error {
|
|
|
|
body := request.GetBody()
|
|
|
|
if body == nil {
|
2022-11-10 17:46:52 +00:00
|
|
|
return errEmptyBody
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
part := body.GetObjectPart()
|
|
|
|
if part, ok := part.(*objectV2.PutObjectPartInit); ok {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := getContainerIDFromRequest(request)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
idV2 := part.GetHeader().GetOwnerID()
|
|
|
|
if idV2 == nil {
|
|
|
|
return errors.New("missing object owner")
|
|
|
|
}
|
|
|
|
|
|
|
|
var idOwner user.ID
|
|
|
|
|
|
|
|
err = idOwner.ReadFromV2(*idV2)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
2022-05-17 13:59:46 +00:00
|
|
|
return fmt.Errorf("invalid object owner: %w", err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
objV2 := part.GetObjectID()
|
|
|
|
var obj *oid.ID
|
|
|
|
|
|
|
|
if objV2 != nil {
|
|
|
|
obj = new(oid.ID)
|
|
|
|
|
|
|
|
err = obj.ReadFromV2(*objV2)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
var sTok *sessionSDK.Object
|
|
|
|
|
|
|
|
if tokV2 := request.GetMetaHeader().GetSessionToken(); tokV2 != nil {
|
|
|
|
sTok = new(sessionSDK.Object)
|
|
|
|
|
|
|
|
err = sTok.ReadFromV2(*tokV2)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid session token: %w", err)
|
|
|
|
}
|
2022-09-16 10:22:09 +00:00
|
|
|
|
2022-10-10 15:53:04 +00:00
|
|
|
if sTok.AssertVerb(sessionSDK.VerbObjectDelete) {
|
|
|
|
// if session relates to object's removal, we don't check
|
|
|
|
// relation of the tombstone to the session here since user
|
|
|
|
// can't predict tomb's ID.
|
|
|
|
err = assertSessionRelation(*sTok, cnr, nil)
|
|
|
|
} else {
|
|
|
|
err = assertSessionRelation(*sTok, cnr, obj)
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-18 15:20:08 +00:00
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-06-08 08:53:15 +00:00
|
|
|
bTok, err := originalBearerToken(request.GetMetaHeader())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
req := MetaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
|
|
|
token: sTok,
|
2022-06-08 08:53:15 +00:00
|
|
|
bearer: bTok,
|
2022-02-11 12:25:05 +00:00
|
|
|
src: request,
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
reqInfo, err := p.source.findRequestInfo(req, cnr, acl.OpObjectPut)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:22:09 +00:00
|
|
|
reqInfo.obj = obj
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
if !p.source.checker.CheckBasicACL(reqInfo) || !p.source.checker.StickyBitCheck(reqInfo, idOwner) {
|
2022-02-11 12:25:05 +00:00
|
|
|
return basicACLErr(reqInfo)
|
2022-03-18 11:04:32 +00:00
|
|
|
} else if err := p.source.checker.CheckEACL(request, reqInfo); err != nil {
|
|
|
|
return eACLErr(reqInfo, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.next.Send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p putStreamBasicChecker) CloseAndRecv() (*objectV2.PutResponse, error) {
|
|
|
|
return p.next.CloseAndRecv()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *getStreamBasicChecker) Send(resp *objectV2.GetResponse) error {
|
|
|
|
if _, ok := resp.GetBody().GetObjectPart().(*objectV2.GetObjectPartInit); ok {
|
2022-03-18 11:04:32 +00:00
|
|
|
if err := g.checker.CheckEACL(resp, g.info); err != nil {
|
|
|
|
return eACLErr(g.info, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.GetObjectStream.Send(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *rangeStreamBasicChecker) Send(resp *objectV2.GetRangeResponse) error {
|
2022-03-18 11:04:32 +00:00
|
|
|
if err := g.checker.CheckEACL(resp, g.info); err != nil {
|
|
|
|
return eACLErr(g.info, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g.GetObjectRangeStream.Send(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *searchStreamBasicChecker) Send(resp *objectV2.SearchResponse) error {
|
2022-03-18 11:04:32 +00:00
|
|
|
if err := g.checker.CheckEACL(resp, g.info); err != nil {
|
|
|
|
return eACLErr(g.info, err)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g.SearchStream.Send(resp)
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:40:51 +00:00
|
|
|
func (b Service) findRequestInfo(req MetaWithToken, idCnr cid.ID, op acl.Op) (info RequestInfo, err error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := b.containers.Get(idCnr) // fetch actual container
|
2022-03-17 08:17:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return info, err
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
if req.token != nil {
|
2022-03-29 11:38:01 +00:00
|
|
|
currentEpoch, err := b.nm.Epoch()
|
|
|
|
if err != nil {
|
|
|
|
return info, errors.New("can't fetch current epoch")
|
|
|
|
}
|
2023-01-20 09:57:53 +00:00
|
|
|
if req.token.ExpiredAt(currentEpoch) {
|
|
|
|
return info, apistatus.SessionTokenExpired{}
|
|
|
|
}
|
2022-11-10 17:58:06 +00:00
|
|
|
if req.token.InvalidAt(currentEpoch) {
|
|
|
|
return info, fmt.Errorf("%s: token is invalid at %d epoch)",
|
2022-11-10 17:46:52 +00:00
|
|
|
invalidRequestMessage, currentEpoch)
|
2022-05-18 15:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !assertVerb(*req.token, op) {
|
2022-11-10 17:46:52 +00:00
|
|
|
return info, errInvalidVerb
|
2022-03-29 11:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
// find request role and key
|
2022-06-22 10:55:31 +00:00
|
|
|
res, err := b.c.classify(req, idCnr, cnr.Value)
|
2022-02-11 12:25:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
info.basicACL = cnr.Value.BasicACL()
|
2022-02-11 12:25:05 +00:00
|
|
|
info.requestRole = res.role
|
2022-05-18 15:20:08 +00:00
|
|
|
info.operation = op
|
2022-06-28 07:01:05 +00:00
|
|
|
info.cnrOwner = cnr.Value.Owner()
|
2022-05-31 17:00:41 +00:00
|
|
|
info.idCnr = idCnr
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
// it is assumed that at the moment the key will be valid,
|
|
|
|
// otherwise the request would not pass validation
|
|
|
|
info.senderKey = res.key
|
|
|
|
|
|
|
|
// add bearer token if it is present in request
|
|
|
|
info.bearer = req.bearer
|
|
|
|
|
|
|
|
info.srcRequest = req.src
|
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|