Skip to content

Commit

Permalink
Check the account alongside the public key (#2883)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Aug 12, 2024
2 parents 0cbd3d0 + f8ccf59 commit 1c1cae7
Show file tree
Hide file tree
Showing 57 changed files with 172 additions and 267 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog for NeoFS Node
- Add objects sanity checker to neofs-lens (#2506)
- Support for 0.20.0+ neofs-contract archive format (#2872)
- `neofs-cli control object status` command (#2886)
- Check the account alongside the public key in ACL (#2883)

### Fixed
- Control service's Drop call does not clean metabase (#2822)
Expand Down
8 changes: 1 addition & 7 deletions cmd/neofs-cli/modules/acl/extended/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,5 @@ func TestParseTable(t *testing.T) {
}

func equalRecords(t *testing.T, r1, r2 *eacl.Record) {
d1, err := r1.Marshal()
require.NoError(t, err)

d2, err := r2.Marshal()
require.NoError(t, err)

require.Equal(t, d1, d2)
require.Equal(t, r1.Marshal(), r2.Marshal())
}
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/container/get_eacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ var getExtendedACLCmd = &cobra.Command{
data, err = eaclTable.MarshalJSON()
common.ExitOnErr(cmd, "can't encode to JSON: %w", err)
} else {
data, err = eaclTable.Marshal()
common.ExitOnErr(cmd, "can't encode to binary: %w", err)
data = eaclTable.Marshal()
}

cmd.Println("dumping data to file:", containerPathTo)
Expand Down
8 changes: 2 additions & 6 deletions cmd/neofs-cli/modules/container/set_eacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
cmd.Println("eACL modification request accepted for processing (the operation may not be completed yet)")

if containerAwait {
exp, err := eaclTable.Marshal()
common.ExitOnErr(cmd, "broken EACL table: %w", err)
exp := eaclTable.Marshal()

cmd.Println("awaiting...")

Expand All @@ -124,10 +123,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
if err == nil {
// compare binary values because EACL could have been set already
table := res.EACL()
got, err := table.Marshal()
if err != nil {
continue
}
got := table.Marshal()

if bytes.Equal(exp, got) {
cmd.Println("EACL has been persisted on sidechain")
Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/object/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func getObject(cmd *cobra.Command, _ []string) {
objToStore := res.Header()
// TODO(@acid-ant): #1932 Use streams to marshal/unmarshal payload
objToStore.SetPayload(payloadBuffer.Bytes())
objBytes, err := objToStore.Marshal()
common.ExitOnErr(cmd, "", err)
objBytes := objToStore.Marshal()
_, err = out.Write(objBytes)
common.ExitOnErr(cmd, "unable to write binary object in out: %w ", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/object/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
case toJSON:
return hdr.MarshalJSON()
case toProto:
return hdr.Marshal()
return hdr.Marshal(), nil
default:
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/object/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error
case toJSON:
return info.MarshalJSON()
case toProto:
return info.Marshal()
return info.Marshal(), nil
default:
b := bytes.NewBuffer(nil)
if splitID := info.SplitID(); splitID != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/util/convert_eacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func convertEACLTable(cmd *cobra.Command, _ []string) {
data, err = table.MarshalJSON()
common.ExitOnErr(cmd, "can't JSON encode extended ACL table: %w", err)
} else {
data, err = table.Marshal()
common.ExitOnErr(cmd, "can't binary encode extended ACL table: %w", err)
data = table.Marshal()
}

if len(to) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-lens/internal/storage/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func getFunc(cmd *cobra.Command, _ []string) {
common.WriteObjectToFile(cmd, vOut, obj.Payload(), true)
return
}
data, err := obj.Marshal()
common.ExitOnErr(cmd, common.Errf("could not marshal object: %w", err))
data := obj.Marshal()
common.WriteObjectToFile(cmd, vOut, data, false)
}
13 changes: 2 additions & 11 deletions cmd/neofs-lens/internal/storage/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ func checkShard(cmd *cobra.Command, sh storageShard) (int, error) {
func checkObject(objHeader object.Object, storage commonb.Storage) error {
// header len check

raw, err := objHeader.Marshal()
if err != nil {
return fmt.Errorf("object from metabase cannot be marshaled: %w", err)
}

raw := objHeader.Marshal()
if lenRead := len(raw); lenRead > object.MaxHeaderLen {
return fmt.Errorf("header cannot be larger than %d bytes, read %d", object.MaxHeaderLen, lenRead)
}
Expand All @@ -226,12 +222,7 @@ func checkObject(objHeader object.Object, storage commonb.Storage) error {
return fmt.Errorf("object get from %s storage: %w", storage.Type(), err)
}

storageRaw, err := res.Object.CutPayload().Marshal()
if err != nil {
return fmt.Errorf("object from %s storage cannot be marshaled: %w", storage.Type(), err)
}

if !bytes.Equal(raw, storageRaw) {
if !bytes.Equal(raw, res.Object.CutPayload().Marshal()) {
return errors.New("object from metabase does not match object from storage")
}

Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-node/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,7 @@ func (s *morphEACLFetcher) GetEACL(cnr cid.ID) (*containercore.EACL, error) {
return nil, err
}

binTable, err := eaclInfo.Value.Marshal()
if err != nil {
return nil, fmt.Errorf("marshal eACL table: %w", err)
}

if !eaclInfo.Signature.Verify(binTable) {
if !eaclInfo.Signature.Verify(eaclInfo.Value.Marshal()) {
// TODO(@cthulhu-rider): #1387 use "const" error
return nil, errors.New("invalid signature of the eACL table")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/nspcc-dev/neo-go v0.106.3
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240305074711-35bc78d84dc4
github.com/nspcc-dev/neofs-contract v0.20.0
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12.0.20240807160341-3528eb5bb1cc
github.com/nspcc-dev/tzhash v1.8.0
github.com/olekukonko/tablewriter v0.0.5
github.com/panjf2000/ants/v2 v2.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240305074711-35bc78d84dc4 h1:ar
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240305074711-35bc78d84dc4/go.mod h1:7Tm1NKEoUVVIUlkVwFrPh7GG5+Lmta2m7EGr4oVpBd8=
github.com/nspcc-dev/neofs-contract v0.20.0 h1:ARE/3mSN+P9qi/10NBsf7QyPiYrvnxeEgYUN13vHRlo=
github.com/nspcc-dev/neofs-contract v0.20.0/go.mod h1:YxtKYE/5cMNiqwWcQWzeizbB9jizauLni+p8wXxfhsQ=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12 h1:mdxtlSU2I4oVZ/7AXTLKyz8uUPbDWikZw4DM8gvrddA=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12/go.mod h1:JdsEM1qgNukrWqgOBDChcYp8oY4XUzidcKaxY4hNJvQ=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12.0.20240807160341-3528eb5bb1cc h1:WjVjs1vGILIVXC0lhJGWy2ek5FfT9S0HCOite/4tsks=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12.0.20240807160341-3528eb5bb1cc/go.mod h1:ewV84r1NACvoBfbKQKzRLUun+Xn5+z9JVqsuCVgv9xI=
github.com/nspcc-dev/rfc6979 v0.2.1 h1:8wWxkamHWFmO790GsewSoKUSJjVnL1fmdRpokU/RgRM=
github.com/nspcc-dev/rfc6979 v0.2.1/go.mod h1:Tk7h5kyUWkhjyO3zUgFFhy1v2vQv3BvQEntakdtqrWc=
github.com/nspcc-dev/tzhash v1.8.0 h1:pJvzME2mZzP/h5rcy/Wb6amT9FJBFeKbJ3HEnWEeUpY=
Expand Down
29 changes: 6 additions & 23 deletions pkg/core/object/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,14 @@ func TestFormatValidator_Validate(t *testing.T) {
content := object.NewTombstone()
content.SetMembers([]oid.ID{oidtest.ID()})

data, err := content.Marshal()
require.NoError(t, err)

obj.SetPayload(data)
obj.SetPayload(content.Marshal())

_, err = v.ValidateContent(obj)
require.Error(t, err) // no members in tombstone

content.SetMembers([]oid.ID{oidtest.ID()})

data, err = content.Marshal()
require.NoError(t, err)

obj.SetPayload(data)
obj.SetPayload(content.Marshal())

_, err = v.ValidateContent(obj)
require.Error(t, err) // no expiration epoch in tombstone
Expand All @@ -198,10 +192,8 @@ func TestFormatValidator_Validate(t *testing.T) {

content.SetExpirationEpoch(10)
content.SetMembers([]oid.ID{id})
data, err = content.Marshal()
require.NoError(t, err)

obj.SetPayload(data)
obj.SetPayload(content.Marshal())

contentGot, err := v.ValidateContent(obj)
require.NoError(t, err) // all good
Expand All @@ -223,10 +215,7 @@ func TestFormatValidator_Validate(t *testing.T) {
content.SetExpirationEpoch(1) // some non-default value

t.Run("empty members", func(t *testing.T) {
data, err := content.Marshal()
require.NoError(t, err)

obj.SetPayload(data)
obj.SetPayload(content.Marshal())

_, err = v.ValidateContent(obj)
require.ErrorIs(t, err, errEmptySGMembers)
Expand All @@ -237,10 +226,7 @@ func TestFormatValidator_Validate(t *testing.T) {

content.SetMembers([]oid.ID{id, id})

data, err := content.Marshal()
require.NoError(t, err)

obj.SetPayload(data)
obj.SetPayload(content.Marshal())

_, err = v.ValidateContent(obj)
require.Error(t, err)
Expand All @@ -250,10 +236,7 @@ func TestFormatValidator_Validate(t *testing.T) {
ids := []oid.ID{oidtest.ID(), oidtest.ID()}
content.SetMembers(ids)

data, err := content.Marshal()
require.NoError(t, err)

obj.SetPayload(data)
obj.SetPayload(content.Marshal())

content, err := v.ValidateContent(obj)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/blobstor/exists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func testObject(sz uint64) *objectSDK.Object {
raw.SetPayload(make([]byte, sz))

// fit the binary size to the required
data, _ := raw.Marshal()
data := raw.Marshal()
if ln := uint64(len(data)); ln > sz {
raw.SetPayload(raw.Payload()[:sz-(ln-sz)])
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/local_object_storage/blobstor/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ func TestBlobStor_GetBytes(t *testing.T) {
return &BlobStor{cfg: cfg{log: zap.NewNop(), storage: subs}}
}

obj := objecttest.Object(t)
obj := objecttest.Object()
addr := object.AddressOf(&obj)
objBin, err := obj.Marshal()
require.NoError(t, err)
objBin := obj.Marshal()

bs := newBlobStorWithStorages(new(getBytesOnlySubStorage), &getBytesOnlySubStorage{
m: map[oid.Address][]byte{addr: objBin},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ func prepare(t *testing.T, count int, s common.Storage, min, max uint64) []objec
for i := range objects {
objects[i].obj = NewObject(min + uint64(rand.Intn(int(max-min+1)))) // not too large
objects[i].addr = objectCore.AddressOf(objects[i].obj)

raw, err := objects[i].obj.Marshal()
require.NoError(t, err)
objects[i].raw = raw
objects[i].raw = objects[i].obj.Marshal()
}

for i := range objects {
Expand Down Expand Up @@ -89,7 +86,7 @@ func NewObject(sz uint64) *objectSDK.Object {
raw.SetPayload(payload)

// fit the binary size to the required
data, _ := raw.Marshal()
data := raw.Marshal()
if ln := uint64(len(data)); ln > sz {
raw.SetPayload(raw.Payload()[:sz-(ln-sz)])
}
Expand Down
21 changes: 9 additions & 12 deletions pkg/local_object_storage/blobstor/peapod/peapod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ func _newTestPeapod(tb testing.TB, path string, readOnly bool) *peapod.Peapod {
func TestPeapod_Get(t *testing.T) {
ppd := newTestPeapod(t)
addr := oidtest.Address()
obj := objecttest.Object(t)
obj := objecttest.Object()

data, err := obj.Marshal()
require.NoError(t, err)
data := obj.Marshal()

getPrm := common.GetPrm{Address: addr}

_, err = ppd.Get(getPrm)
_, err := ppd.Get(getPrm)
require.ErrorIs(t, err, apistatus.ErrObjectNotFound)

_, err = ppd.Put(common.PutPrm{
Expand Down Expand Up @@ -167,12 +166,11 @@ func TestPeapod_Iterate(t *testing.T) {
func TestPeapod_Put(t *testing.T) {
ppd := newTestPeapod(t)
addr := oidtest.Address()
obj := objecttest.Object(t)
obj := objecttest.Object()

data, err := obj.Marshal()
require.NoError(t, err)
data := obj.Marshal()

_, err = ppd.Put(common.PutPrm{
_, err := ppd.Put(common.PutPrm{
Address: addr,
RawData: data,
})
Expand All @@ -199,12 +197,11 @@ func TestPeapod_Put(t *testing.T) {
func TestPeapod_Delete(t *testing.T) {
ppd := newTestPeapod(t)
addr := oidtest.Address()
obj := objecttest.Object(t)
obj := objecttest.Object()

data, err := obj.Marshal()
require.NoError(t, err)
data := obj.Marshal()

_, err = ppd.Delete(common.DeletePrm{
_, err := ppd.Delete(common.DeletePrm{
Address: addr,
})
require.ErrorIs(t, err, apistatus.ErrObjectNotFound)
Expand Down
6 changes: 1 addition & 5 deletions pkg/local_object_storage/blobstor/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ func (b *BlobStor) Put(prm common.PutPrm) (common.PutRes, error) {
}
if prm.RawData == nil {
// marshal object
data, err := prm.Object.Marshal()
if err != nil {
return common.PutRes{}, fmt.Errorf("could not marshal the object: %w", err)
}
prm.RawData = data
prm.RawData = prm.Object.Marshal()
}

var overflow bool
Expand Down
4 changes: 2 additions & 2 deletions pkg/local_object_storage/engine/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestStorageEngine_ContainerCleanUp(t *testing.T) {
}
require.NoError(t, e.Open())

o1 := objecttest.Object(t)
o2 := objecttest.Object(t)
o1 := objecttest.Object()
o2 := objecttest.Object()
o2.SetPayload(make([]byte, errSmallSize+1))

var prmPut PutPrm
Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func generateObjectWithCID(t testing.TB, cnr cid.ID) *object.Object {

obj := object.New()
obj.SetID(oidtest.ID())
owner := usertest.ID(t)
owner := usertest.ID()
obj.SetOwnerID(&owner)
obj.SetContainerID(cnr)
obj.SetVersion(&ver)
Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/engine/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestChildrenExpiration(t *testing.T) {
const numOfShards = 5
const currEpoch = 10
es := &epochState{e: currEpoch}
owner := usertest.ID(t)
owner := usertest.ID()

e := New()
for i := 0; i < numOfShards; i++ {
Expand Down
5 changes: 2 additions & 3 deletions pkg/local_object_storage/engine/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ func TestStorageEngine_GetBytes(t *testing.T) {
obj := generateObjectWithCID(t, cidtest.ID())
addr := object.AddressOf(obj)

objBin, err := obj.Marshal()
require.NoError(t, err)
objBin := obj.Marshal()

err = Put(e, obj)
err := Put(e, obj)
require.NoError(t, err)

b, err := e.GetBytes(addr)
Expand Down
Loading

0 comments on commit 1c1cae7

Please sign in to comment.