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 12, 2024
1 parent 7009a45 commit f8ccf59
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 @@ -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
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).

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L197 was not covered by tests
WithRole(eaclRole).
WithOperation(eaclSDK.Operation(reqInfo.Operation())).
WithContainerID(&cnr).
WithSenderKey(reqInfo.SenderKey()).
WithHeaderSource(hdrSrc).
WithEACLTable(&table),
)
WithEACLTable(&table)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L203 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/acl.go#L205-L206

Added lines #L205 - L206 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L209 was not covered by tests

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,

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L43-L45

Added lines #L43 - L45 were not covered by tests
}, 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,

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L56-L58

Added lines #L56 - L58 were not covered by tests
}, 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,

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L71-L73

Added lines #L71 - L73 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: ownerID,

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/v2/classifier.go#L79-L81

Added lines #L79 - L81 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 *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

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 f8ccf59

Please sign in to comment.