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 <[email protected]>
  • Loading branch information
smallhive committed Aug 8, 2024
1 parent 523317d commit 4dbc22d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog for NeoFS Node
- Indexes inspection command to neofs-lens (#2882)
- Add objects sanity checker to neofs-lens (#2506)
- Support for 0.20.0+ neofs-contract archive format (#2872)
- Check the account alongside the public key in ACL (#2883)

### Fixed
- Control service's Drop call does not clean metabase (#2822)
Expand Down
11 changes: 8 additions & 3 deletions pkg/services/object/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,19 @@ func (c *Checker) CheckEACL(msg any, reqInfo v2.RequestInfo) error {
eaclRole = eaclSDK.RoleOthers
}

action, _ := c.validator.CalculateAction(new(eaclSDK.ValidationUnit).
vu := new(eaclSDK.ValidationUnit).
WithRole(eaclRole).
WithOperation(eaclSDK.Operation(reqInfo.Operation())).
WithContainerID(&cnr).
WithSenderKey(reqInfo.SenderKey()).
WithHeaderSource(hdrSrc).
WithEACLTable(&table),
)
WithEACLTable(&table)

if sa := reqInfo.SenderAccount(); sa != nil && !sa.IsZero() {
vu.WithAccount(*sa)
}

action, _ := c.validator.CalculateAction(vu)

if action != eaclSDK.ActionAllow {
return errEACLDeniedByRule
Expand Down
26 changes: 16 additions & 10 deletions pkg/services/object/acl/v2/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
)

Expand All @@ -18,8 +19,9 @@ type senderClassifier struct {
}

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

func (c senderClassifier) classify(
Expand All @@ -38,8 +40,9 @@ func (c senderClassifier) classify(
// 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: ownerID,
}, nil
}

Expand All @@ -50,8 +53,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: ownerID,
}, nil
}

Expand All @@ -64,15 +68,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: ownerID,
}, nil
}

// if none of above, return RoleOthers
return &classifyResult{
role: acl.RoleOthers,
key: ownerKey,
role: acl.RoleOthers,
key: ownerKey,
account: ownerID,
}, 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 *user.ID

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() *user.ID {
return r.senderAccount
}

// 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

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

0 comments on commit 4dbc22d

Please sign in to comment.