2020-09-29 12:37:19 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2023-07-28 12:44:35 +00:00
|
|
|
"bytes"
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-05-31 08:55:40 +00:00
|
|
|
"crypto/ecdsa"
|
2023-07-28 12:44:35 +00:00
|
|
|
"crypto/elliptic"
|
|
|
|
"crypto/sha256"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-02-15 08:28:42 +00:00
|
|
|
"strconv"
|
2020-09-29 12:37:19 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
2023-07-28 12:44:35 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
2023-07-28 12:44:35 +00:00
|
|
|
netmapSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2023-07-28 12:44:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-09-29 12:37:19 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// FormatValidator represents an object format validator.
|
2020-10-03 10:14:09 +00:00
|
|
|
type FormatValidator struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// FormatValidatorOption represents a FormatValidator constructor option.
|
2020-10-03 10:14:09 +00:00
|
|
|
type FormatValidatorOption func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2023-07-28 12:44:35 +00:00
|
|
|
netState netmap.State
|
|
|
|
e LockSource
|
|
|
|
ir InnerRing
|
|
|
|
netmap netmap.Source
|
|
|
|
containers container.Source
|
|
|
|
verifyTokenIssuer bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type InnerRing interface {
|
|
|
|
InnerRingKeys() ([][]byte, error)
|
2020-10-03 10:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteHandler is an interface of delete queue processor.
|
|
|
|
type DeleteHandler interface {
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteObjects places objects to a removal queue.
|
2022-02-16 15:49:19 +00:00
|
|
|
//
|
2022-03-05 08:46:02 +00:00
|
|
|
// Returns apistatus.LockNonRegularObject if at least one object
|
2022-02-16 15:49:19 +00:00
|
|
|
// is locked.
|
2022-05-31 17:00:41 +00:00
|
|
|
DeleteObjects(oid.Address, ...oid.Address) error
|
2022-02-16 15:49:19 +00:00
|
|
|
}
|
|
|
|
|
2023-03-15 01:07:27 +00:00
|
|
|
// LockSource is a source of lock relations between the objects.
|
|
|
|
type LockSource interface {
|
|
|
|
// IsLocked must clarify object's lock status.
|
2023-04-12 14:01:29 +00:00
|
|
|
IsLocked(ctx context.Context, address oid.Address) (bool, error)
|
2023-03-15 01:07:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 15:49:19 +00:00
|
|
|
// Locker is an object lock storage interface.
|
|
|
|
type Locker interface {
|
|
|
|
// Lock list of objects as locked by locker in the specified container.
|
|
|
|
//
|
2022-03-05 08:46:02 +00:00
|
|
|
// Returns apistatus.LockNonRegularObject if at least object in locked
|
2022-02-16 15:49:19 +00:00
|
|
|
// list is irregular (not type of REGULAR).
|
|
|
|
Lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error
|
2020-10-03 10:14:09 +00:00
|
|
|
}
|
2020-09-29 12:37:19 +00:00
|
|
|
|
|
|
|
var errNilObject = errors.New("object is nil")
|
|
|
|
|
|
|
|
var errNilID = errors.New("missing identifier")
|
|
|
|
|
|
|
|
var errNilCID = errors.New("missing container identifier")
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
var errNoExpirationEpoch = errors.New("missing expiration epoch attribute")
|
|
|
|
|
|
|
|
var errTombstoneExpiration = errors.New("tombstone body and header contain different expiration values")
|
|
|
|
|
2023-07-13 13:43:41 +00:00
|
|
|
var errMissingSignature = errors.New("missing signature")
|
|
|
|
|
2020-10-03 10:14:09 +00:00
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return new(cfg)
|
|
|
|
}
|
|
|
|
|
2020-09-29 12:37:19 +00:00
|
|
|
// NewFormatValidator creates, initializes and returns FormatValidator instance.
|
2020-10-03 10:14:09 +00:00
|
|
|
func NewFormatValidator(opts ...FormatValidatorOption) *FormatValidator {
|
|
|
|
cfg := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &FormatValidator{
|
|
|
|
cfg: cfg,
|
|
|
|
}
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates object format.
|
|
|
|
//
|
2020-09-30 17:53:12 +00:00
|
|
|
// Does not validate payload checksum and content.
|
2022-04-04 13:04:18 +00:00
|
|
|
// If unprepared is true, only fields set by user are validated.
|
2020-09-30 17:53:12 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns nil error if the object has valid structure.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) Validate(ctx context.Context, obj *objectSDK.Object, unprepared bool) error {
|
2020-09-29 12:37:19 +00:00
|
|
|
if obj == nil {
|
|
|
|
return errNilObject
|
2022-05-12 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, idSet := obj.ID()
|
|
|
|
if !unprepared && !idSet {
|
2020-09-29 12:37:19 +00:00
|
|
|
return errNilID
|
2022-05-12 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, cnrSet := obj.ContainerID()
|
|
|
|
if !cnrSet {
|
2020-09-29 12:37:19 +00:00
|
|
|
return errNilCID
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
if err := v.checkOwner(obj); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-14 17:25:16 +00:00
|
|
|
if err := v.checkAttributes(obj); err != nil {
|
|
|
|
return fmt.Errorf("invalid attributes: %w", err)
|
|
|
|
}
|
2020-10-01 11:42:17 +00:00
|
|
|
|
2022-04-04 13:04:18 +00:00
|
|
|
if !unprepared {
|
|
|
|
if err := v.validateSignatureKey(obj); err != nil {
|
|
|
|
return fmt.Errorf("(%T) could not validate signature key: %w", v, err)
|
|
|
|
}
|
2021-02-15 08:28:42 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
if err := v.checkExpiration(ctx, obj); err != nil {
|
2022-04-04 13:04:18 +00:00
|
|
|
return fmt.Errorf("object did not pass expiration check: %w", err)
|
|
|
|
}
|
2021-10-14 17:25:16 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
if err := objectSDK.CheckHeaderVerificationFields(obj); err != nil {
|
2022-04-04 13:04:18 +00:00
|
|
|
return fmt.Errorf("(%T) could not validate header fields: %w", v, err)
|
|
|
|
}
|
2021-10-14 17:25:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
if obj = obj.Parent(); obj != nil {
|
2022-04-04 13:04:18 +00:00
|
|
|
// Parent object already exists.
|
2023-04-12 14:01:29 +00:00
|
|
|
return v.Validate(ctx, obj, false)
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) validateSignatureKey(obj *objectSDK.Object) error {
|
2022-05-16 13:15:31 +00:00
|
|
|
sig := obj.Signature()
|
|
|
|
if sig == nil {
|
2023-07-13 13:43:41 +00:00
|
|
|
return errMissingSignature
|
2022-05-16 13:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var sigV2 refs.Signature
|
|
|
|
sig.WriteToV2(&sigV2)
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
binKey := sigV2.GetKey()
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
var key frostfsecdsa.PublicKey
|
2022-05-18 15:20:08 +00:00
|
|
|
|
|
|
|
err := key.Decode(binKey)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("decode public key: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
token := obj.SessionToken()
|
2023-07-17 13:46:46 +00:00
|
|
|
ownerID := *obj.OwnerID()
|
2020-09-29 12:37:19 +00:00
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
if token == nil || !token.AssertAuthKey(&key) {
|
2023-07-17 13:46:46 +00:00
|
|
|
return v.checkOwnerKey(ownerID, key)
|
|
|
|
}
|
|
|
|
|
2023-07-28 12:44:35 +00:00
|
|
|
if v.verifyTokenIssuer {
|
|
|
|
signerIsIROrContainerNode, err := v.isIROrContainerNode(obj, binKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if signerIsIROrContainerNode {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !token.Issuer().Equals(ownerID) {
|
|
|
|
return fmt.Errorf("(%T) different token issuer and object owner identifiers %s/%s", v, token.Issuer(), ownerID)
|
|
|
|
}
|
|
|
|
return nil
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-28 12:44:35 +00:00
|
|
|
func (v *FormatValidator) isIROrContainerNode(obj *objectSDK.Object, signerKey []byte) (bool, error) {
|
|
|
|
pKey, err := keys.NewPublicKeyFromBytes(signerKey, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("(%T) failed to unmarshal signer public key: %w", v, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
isIR, err := v.isInnerRingKey(pKey.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("(%T) failed to check if signer is inner ring node: %w", v, err)
|
|
|
|
}
|
|
|
|
if isIR {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
isContainerNode, err := v.isContainerNode(pKey.Bytes(), obj)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("(%T) failed to check if signer is container node: %w", v, err)
|
|
|
|
}
|
|
|
|
return isContainerNode, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *FormatValidator) isInnerRingKey(key []byte) (bool, error) {
|
|
|
|
innerRingKeys, err := v.ir.InnerRingKeys()
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range innerRingKeys {
|
|
|
|
if bytes.Equal(innerRingKeys[i], key) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *FormatValidator) isContainerNode(key []byte, obj *objectSDK.Object) (bool, error) {
|
|
|
|
cnrID, containerIDSet := obj.ContainerID()
|
|
|
|
if !containerIDSet {
|
|
|
|
return false, errNilCID
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrIDBin := make([]byte, sha256.Size)
|
|
|
|
cnrID.Encode(cnrIDBin)
|
|
|
|
|
|
|
|
cnr, err := v.containers.Get(cnrID)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to get container (id=%s): %w", cnrID.EncodeToString(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lastNetmap, err := netmap.GetLatestNetworkMap(v.netmap)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to get latest netmap: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
isContainerNode, err := v.isContainerNodeKey(lastNetmap, cnr, cnrIDBin, key)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to check latest netmap for container nodes: %w", err)
|
|
|
|
}
|
|
|
|
if isContainerNode {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
previousNetmap, err := netmap.GetPreviousNetworkMap(v.netmap)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to get previous netmap: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
isContainerNode, err = v.isContainerNodeKey(previousNetmap, cnr, cnrIDBin, key)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to check previous netmap for container nodes: %w", err)
|
|
|
|
}
|
|
|
|
return isContainerNode, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *FormatValidator) isContainerNodeKey(nm *netmapSDK.NetMap, cnr *container.Container, cnrIDBin, key []byte) (bool, error) {
|
|
|
|
cnrVectors, err := nm.ContainerNodes(cnr.Value.PlacementPolicy(), cnrIDBin)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range cnrVectors {
|
|
|
|
for j := range cnrVectors[i] {
|
|
|
|
if bytes.Equal(cnrVectors[i][j].PublicKey(), key) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
func (v *FormatValidator) checkOwnerKey(id user.ID, key frostfsecdsa.PublicKey) error {
|
2022-05-17 13:59:46 +00:00
|
|
|
var id2 user.ID
|
2022-05-18 15:20:08 +00:00
|
|
|
user.IDFromKey(&id2, (ecdsa.PublicKey)(key))
|
2020-09-29 12:37:19 +00:00
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
if !id.Equals(id2) {
|
2021-05-31 10:30:59 +00:00
|
|
|
return fmt.Errorf("(%T) different owner identifiers %s/%s", v, id, id2)
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-30 11:07:28 +00:00
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// ContentMeta describes FrostFS meta information that brings object's payload if the object
|
2022-11-01 17:32:43 +00:00
|
|
|
// is one of:
|
|
|
|
// - object.TypeTombstone;
|
|
|
|
// - object.TypeLock.
|
|
|
|
type ContentMeta struct {
|
2023-07-06 12:36:41 +00:00
|
|
|
typ objectSDK.Type
|
2022-11-01 17:32:43 +00:00
|
|
|
|
|
|
|
objs []oid.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type returns object's type.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (i ContentMeta) Type() objectSDK.Type {
|
2022-11-01 17:32:43 +00:00
|
|
|
return i.typ
|
|
|
|
}
|
|
|
|
|
|
|
|
// Objects returns objects that the original object's payload affects:
|
|
|
|
// - inhumed objects, if the original object is a Tombstone;
|
|
|
|
// - locked objects, if the original object is a Lock;
|
|
|
|
// - nil, if the original object is a Regular object.
|
|
|
|
func (i ContentMeta) Objects() []oid.ID {
|
|
|
|
return i.objs
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ValidateContent validates payload content according to the object type.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) ValidateContent(o *objectSDK.Object) (ContentMeta, error) {
|
2022-11-01 17:32:43 +00:00
|
|
|
meta := ContentMeta{
|
|
|
|
typ: o.Type(),
|
|
|
|
}
|
|
|
|
|
2020-12-01 11:23:28 +00:00
|
|
|
switch o.Type() {
|
2023-07-06 12:36:41 +00:00
|
|
|
case objectSDK.TypeTombstone:
|
2023-04-06 10:02:37 +00:00
|
|
|
if err := v.fillAndValidateTombstoneMeta(o, &meta); err != nil {
|
|
|
|
return ContentMeta{}, err
|
2020-09-30 11:07:28 +00:00
|
|
|
}
|
2023-07-06 12:36:41 +00:00
|
|
|
case objectSDK.TypeLock:
|
2023-04-06 10:02:37 +00:00
|
|
|
if err := v.fillAndValidateLockMeta(o, &meta); err != nil {
|
2022-11-01 17:32:43 +00:00
|
|
|
return ContentMeta{}, err
|
2021-02-19 09:29:42 +00:00
|
|
|
}
|
2023-04-06 10:02:37 +00:00
|
|
|
default:
|
|
|
|
// ignore all other object types, they do not need payload formatting
|
|
|
|
}
|
2021-02-19 09:29:42 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
return meta, nil
|
|
|
|
}
|
2021-02-19 09:29:42 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) fillAndValidateLockMeta(o *objectSDK.Object, meta *ContentMeta) error {
|
2023-04-06 10:02:37 +00:00
|
|
|
if len(o.Payload()) == 0 {
|
|
|
|
return errors.New("empty payload in lock")
|
|
|
|
}
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if _, ok := o.ContainerID(); !ok {
|
|
|
|
return errors.New("missing container")
|
|
|
|
}
|
2020-12-17 16:54:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if _, ok := o.ID(); !ok {
|
|
|
|
return errors.New("missing ID")
|
|
|
|
}
|
|
|
|
// check that LOCK object has correct expiration epoch
|
|
|
|
lockExp, err := expirationEpochAttribute(o)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("lock object expiration epoch: %w", err)
|
|
|
|
}
|
2020-12-17 16:54:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if currEpoch := v.netState.CurrentEpoch(); lockExp < currEpoch {
|
|
|
|
return fmt.Errorf("lock object expiration: %d; current: %d", lockExp, currEpoch)
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var lock objectSDK.Lock
|
2022-11-01 17:32:43 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if err = lock.Unmarshal(o.Payload()); err != nil {
|
|
|
|
return fmt.Errorf("decode lock payload: %w", err)
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
num := lock.NumberOfMembers()
|
|
|
|
if num == 0 {
|
|
|
|
return errors.New("missing locked members")
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
meta.objs = make([]oid.ID, num)
|
|
|
|
lock.ReadMembers(meta.objs)
|
|
|
|
return nil
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) fillAndValidateTombstoneMeta(o *objectSDK.Object, meta *ContentMeta) error {
|
2023-04-06 10:02:37 +00:00
|
|
|
if len(o.Payload()) == 0 {
|
|
|
|
return fmt.Errorf("(%T) empty payload in tombstone", v)
|
2020-09-30 11:07:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
tombstone := objectSDK.NewTombstone()
|
2023-04-06 10:02:37 +00:00
|
|
|
|
|
|
|
if err := tombstone.Unmarshal(o.Payload()); err != nil {
|
|
|
|
return fmt.Errorf("(%T) could not unmarshal tombstone content: %w", v, err)
|
|
|
|
}
|
|
|
|
// check if the tombstone has the same expiration in the body and the header
|
|
|
|
exp, err := expirationEpochAttribute(o)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if exp != tombstone.ExpirationEpoch() {
|
|
|
|
return errTombstoneExpiration
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark all objects from the tombstone body as removed in the storage engine
|
|
|
|
if _, ok := o.ContainerID(); !ok {
|
|
|
|
return errors.New("missing container ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
meta.objs = tombstone.Members()
|
|
|
|
return nil
|
2020-09-30 11:07:28 +00:00
|
|
|
}
|
2020-10-03 10:14:09 +00:00
|
|
|
|
2021-02-15 08:28:42 +00:00
|
|
|
var errExpired = errors.New("object has expired")
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) checkExpiration(ctx context.Context, obj *objectSDK.Object) error {
|
2021-02-19 09:29:42 +00:00
|
|
|
exp, err := expirationEpochAttribute(obj)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, errNoExpirationEpoch) {
|
|
|
|
return nil // objects without expiration attribute are valid
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-02-15 08:28:42 +00:00
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
if exp < v.netState.CurrentEpoch() {
|
2023-03-15 01:07:27 +00:00
|
|
|
// an object could be expired but locked;
|
|
|
|
// put such an object is a correct operation
|
|
|
|
|
|
|
|
cID, _ := obj.ContainerID()
|
|
|
|
oID, _ := obj.ID()
|
|
|
|
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cID)
|
|
|
|
addr.SetObject(oID)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
locked, err := v.e.IsLocked(ctx, addr)
|
2023-03-15 01:07:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("locking status check for an expired object: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !locked {
|
|
|
|
return errExpired
|
|
|
|
}
|
2021-02-19 09:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func expirationEpochAttribute(obj *objectSDK.Object) (uint64, error) {
|
2021-02-19 09:29:42 +00:00
|
|
|
for _, a := range obj.Attributes() {
|
2023-03-06 13:11:42 +00:00
|
|
|
if a.Key() != objectV2.SysAttributeExpEpoch && a.Key() != objectV2.SysAttributeExpEpochNeoFS {
|
2021-02-19 09:29:42 +00:00
|
|
|
continue
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
return strconv.ParseUint(a.Value(), 10, 64)
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
return 0, errNoExpirationEpoch
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:20:13 +00:00
|
|
|
var (
|
|
|
|
errDuplAttr = errors.New("duplication of attributes detected")
|
|
|
|
errEmptyAttrVal = errors.New("empty attribute value")
|
|
|
|
)
|
2021-06-23 13:30:14 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) checkAttributes(obj *objectSDK.Object) error {
|
2021-06-23 13:30:14 +00:00
|
|
|
as := obj.Attributes()
|
|
|
|
|
|
|
|
mUnique := make(map[string]struct{}, len(as))
|
|
|
|
|
|
|
|
for _, a := range as {
|
|
|
|
key := a.Key()
|
|
|
|
|
|
|
|
if _, was := mUnique[key]; was {
|
|
|
|
return errDuplAttr
|
|
|
|
}
|
|
|
|
|
2021-06-23 14:20:13 +00:00
|
|
|
if a.Value() == "" {
|
|
|
|
return errEmptyAttrVal
|
|
|
|
}
|
|
|
|
|
2021-06-23 13:30:14 +00:00
|
|
|
mUnique[key] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-14 17:25:16 +00:00
|
|
|
var errIncorrectOwner = errors.New("incorrect object owner")
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) checkOwner(obj *objectSDK.Object) error {
|
2022-05-17 13:59:46 +00:00
|
|
|
if idOwner := obj.OwnerID(); idOwner == nil || len(idOwner.WalletBytes()) == 0 {
|
2021-10-14 17:25:16 +00:00
|
|
|
return errIncorrectOwner
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithNetState returns options to set the network state interface.
|
2021-02-15 08:28:42 +00:00
|
|
|
func WithNetState(netState netmap.State) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netState = netState
|
|
|
|
}
|
|
|
|
}
|
2023-03-15 01:07:27 +00:00
|
|
|
|
|
|
|
// WithLockSource return option to set the Storage Engine.
|
|
|
|
func WithLockSource(e LockSource) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.e = e
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 12:44:35 +00:00
|
|
|
|
|
|
|
// WithInnerRing return option to set Inner Ring source.
|
|
|
|
func WithInnerRing(ir InnerRing) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.ir = ir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithNetmapSource return option to set Netmap source.
|
|
|
|
func WithNetmapSource(ns netmap.Source) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netmap = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithContainersSource return option to set Containers source.
|
|
|
|
func WithContainersSource(cs container.Source) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.containers = cs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithVerifySessionTokenIssuer return option to set verify session token issuer value.
|
|
|
|
func WithVerifySessionTokenIssuer(verifySessionTokenIssuer bool) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.verifyTokenIssuer = verifySessionTokenIssuer
|
|
|
|
}
|
|
|
|
}
|