Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up account alongside pub key in eacl rules in CLI #2915

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog for NeoFS Node
- 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)
- Allow addresses to be used in EACLs created from CLI (#2914)

### Fixed
- Control service's Drop call does not clean metabase (#2822)
Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-cli/modules/acl/extended/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Target is
'user' for container owner,
'system' for Storage nodes in container and Inner Ring nodes,
'others' for all other request senders,
'pubkey:<key1>,<key2>,...' for exact request sender, where <key> is a hex-encoded 33-byte public key.
'pubkey:<key1>,<key2>,...' for exact request sender, where <key> is a hex-encoded 33-byte public key,
'address:<adr1>,<adr2>,...' for exact request sender, where <adr> is a base58 25-byte address. Example: NSiVJYZej4XsxG5CUpdwn7VRQk8iiiDMPM.

When both '--rule' and '--file' arguments are used, '--rule' records will be placed higher in resulting extended ACL table.
`,
Expand Down
9 changes: 9 additions & 0 deletions cmd/neofs-cli/modules/acl/extended/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func TestParseTable(t *testing.T) {
rule: "deny getrange pubkey:036410abb260bbbda89f61c0cad65a4fa15ac5cb83b3c3abf8aee403856fcf65ed",
jsonRecord: `{"operation":"GETRANGE","action":"DENY","filters":[],"targets":[{"role":"ROLE_UNSPECIFIED","keys":["A2QQq7Jgu72on2HAytZaT6FaxcuDs8Or+K7kA4Vvz2Xt"]}]}`,
},
{
name: "valid rule with account",
rule: "deny getrange address:NWcSSzMkw5Vuq3gFmcih5yfCNxfXjWdKz8",
jsonRecord: `{"operation":"GETRANGE","action":"DENY","filters":[],"targets":[{"role":"ROLE_UNSPECIFIED","keys":["NXVYp24sheVFxW8PazdLtZEvUM/gLAhtqQ=="]}]}`,
},
{
name: "missing action",
rule: "get obj:a=b others",
Expand Down Expand Up @@ -57,6 +62,10 @@ func TestParseTable(t *testing.T) {
name: "invalid public key",
rule: "deny get obj:a=b pubkey:0123",
},
{
name: "invalid account",
rule: "deny get obj:a=b account:1234",
},
}

eaclTable := eacl.NewTable()
Expand Down
35 changes: 35 additions & 0 deletions cmd/neofs-cli/modules/util/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
"github.com/nspcc-dev/neofs-sdk-go/eacl"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -276,7 +277,24 @@
}

eacl.AddFormedTarget(r, role, pubs...)
case "address": // targets
var (
err error
accounts []user.ID
)

Check warning on line 284 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L280-L284

Added lines #L280 - L284 were not covered by tests

if len(ss) != 2 {
return nil, fmt.Errorf("invalid address: %s", args[i])

Check warning on line 287 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L286-L287

Added lines #L286 - L287 were not covered by tests
}

accounts, err = parseAccountList(ss[1])
if err != nil {
return nil, err

Check warning on line 292 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L290-L292

Added lines #L290 - L292 were not covered by tests
}

t := eacl.NewTarget()
t.SetAccounts(accounts)
eacl.AddRecordTarget(r, t)

Check warning on line 297 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L295-L297

Added lines #L295 - L297 were not covered by tests
default:
return nil, fmt.Errorf("invalid prefix: %s", ss[0])
}
Expand Down Expand Up @@ -363,6 +381,23 @@
return pubs, nil
}

func parseAccountList(s string) ([]user.ID, error) {
parts := strings.Split(s, ",")
accounts := make([]user.ID, len(parts))

Check warning on line 386 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L384-L386

Added lines #L384 - L386 were not covered by tests

for i := range parts {
st := strings.TrimSpace(parts[i])
acc, err := user.DecodeString(st)
if err != nil {
return nil, fmt.Errorf("invalid account %q: %w", parts[i], err)

Check warning on line 392 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L388-L392

Added lines #L388 - L392 were not covered by tests
}

accounts[i] = acc

Check warning on line 395 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L395

Added line #L395 was not covered by tests
}

return accounts, nil

Check warning on line 398 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L398

Added line #L398 was not covered by tests
}

// eaclOperationsFromString parses list of eacl.Operation separated by comma.
func eaclOperationsFromString(s string) ([]eacl.Operation, error) {
ss := strings.Split(s, ",")
Expand Down
Loading