Skip to content

Commit

Permalink
acl: Check the account alongside the public key
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Jul 5, 2024
1 parent 5ef73c8 commit 68a2ab1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog for NeoFS Node

### Added
- Indexes inspection command to neofs-lens (#2882)
- Check the account alongside the public key in ACL (#2883)

### Fixed
- Control service's Drop call does not clean metabase (#2822)
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.2
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240305074711-35bc78d84dc4
github.com/nspcc-dev/neofs-contract v0.19.2-0.20240506202632-e78d64ecdfc2
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.20240705070503-e3543cb5d21b
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 @@ -136,8 +136,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.19.2-0.20240506202632-e78d64ecdfc2 h1:VT9/vs92xth7c2PIxiGt1NIK77VK2kjSFqLMWmMY/pc=
github.com/nspcc-dev/neofs-contract v0.19.2-0.20240506202632-e78d64ecdfc2/go.mod h1:5nBFjgF2/SNpEty5oZzfTLck3YCSHLgnL4Tlv2xo54c=
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.20240705070503-e3543cb5d21b h1:PRP0B3W7l3VhvZPYwm5FUUfkSsPkfs9LK0j+VWAX69o=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12.0.20240705070503-e3543cb5d21b/go.mod h1:JdsEM1qgNukrWqgOBDChcYp8oY4XUzidcKaxY4hNJvQ=
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
1 change: 1 addition & 0 deletions pkg/services/object/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (c *Checker) CheckEACL(msg any, reqInfo v2.RequestInfo) error {
WithOperation(eaclSDK.Operation(reqInfo.Operation())).
WithContainerID(&cnr).
WithSenderKey(reqInfo.SenderKey()).
WithAccount(reqInfo.SenderAccount()).

Check warning on line 202 in pkg/services/object/acl/acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/acl.go#L202

Added line #L202 was not covered by tests
WithHeaderSource(hdrSrc).
WithEACLTable(&table),
)
Expand Down
31 changes: 21 additions & 10 deletions pkg/services/object/acl/v2/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2

import (
"bytes"
"fmt"

core "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-sdk-go/container"
Expand All @@ -18,8 +19,9 @@ type senderClassifier struct {
}

type classifyResult struct {
role acl.Role
key []byte
role acl.Role
key []byte
account []byte
}

func (c senderClassifier) classify(
Expand All @@ -31,13 +33,19 @@ func (c senderClassifier) classify(
return nil, err
}

sc, err := ownerID.GetScriptHash()
if err != nil {
return nil, fmt.Errorf("owner get scripthash: %w", err)

Check warning on line 38 in pkg/services/object/acl/v2/classifier.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L36-L38

Added lines #L36 - L38 were not covered by tests
}

// TODO: #767 get owner from neofs.id if present

// if request owner is the same as container owner, return RoleUser
if ownerID.Equals(cnr.Owner()) {
return &classifyResult{
role: acl.RoleOwner,
key: ownerKey,
role: acl.RoleOwner,
key: ownerKey,
account: sc.BytesBE(),

Check warning on line 48 in pkg/services/object/acl/v2/classifier.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L46-L48

Added lines #L46 - L48 were not covered by tests
}, nil
}

Expand All @@ -48,8 +56,9 @@ func (c senderClassifier) classify(
zap.String("error", err.Error()))
} else if isInnerRingNode {
return &classifyResult{
role: acl.RoleInnerRing,
key: ownerKey,
role: acl.RoleInnerRing,
key: ownerKey,
account: sc.BytesBE(),

Check warning on line 61 in pkg/services/object/acl/v2/classifier.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L59-L61

Added lines #L59 - L61 were not covered by tests
}, nil
}

Expand All @@ -62,15 +71,17 @@ func (c senderClassifier) classify(
zap.String("error", err.Error()))
} else if isContainerNode {
return &classifyResult{
role: acl.RoleContainer,
key: ownerKey,
role: acl.RoleContainer,
key: ownerKey,
account: sc.BytesBE(),

Check warning on line 76 in pkg/services/object/acl/v2/classifier.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L74-L76

Added lines #L74 - L76 were not covered by tests
}, nil
}

// if none of above, return RoleOthers
return &classifyResult{
role: acl.RoleOthers,
key: ownerKey,
role: acl.RoleOthers,
key: ownerKey,
account: sc.BytesBE(),

Check warning on line 84 in pkg/services/object/acl/v2/classifier.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L82-L84

Added lines #L82 - L84 were not covered by tests
}, nil
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/services/object/acl/v2/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type RequestInfo struct {
// e.g. Put, Search
obj *oid.ID

senderKey []byte
senderKey []byte
senderAccount []byte

bearer *bearer.Token // bearer token of request

Expand Down Expand Up @@ -88,6 +89,11 @@ func (r RequestInfo) SenderKey() []byte {
return r.senderKey
}

// SenderAccount returns account of the request's sender.
func (r RequestInfo) SenderAccount() []byte {
return r.senderAccount

Check warning on line 94 in pkg/services/object/acl/v2/request.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/request.go#L93-L94

Added lines #L93 - L94 were not covered by tests
}

// Operation returns request's operation.
func (r RequestInfo) Operation() acl.Op {
return r.operation
Expand Down
1 change: 1 addition & 0 deletions pkg/services/object/acl/v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ func (b Service) findRequestInfo(req MetaWithToken, idCnr cid.ID, op acl.Op) (in
// it is assumed that at the moment the key will be valid,
// otherwise the request would not pass validation
info.senderKey = res.key
info.senderAccount = res.account

Check warning on line 631 in pkg/services/object/acl/v2/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/service.go#L631

Added line #L631 was not covered by tests

// add bearer token if it is present in request
info.bearer = req.bearer
Expand Down

0 comments on commit 68a2ab1

Please sign in to comment.