2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2022-05-12 16:37:46 +00:00
|
|
|
"crypto/sha256"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// GetEACL reads the extended ACL table from FrostFS system
|
2022-01-31 13:34:01 +00:00
|
|
|
// through Container contract call.
|
2022-08-01 15:28:40 +00:00
|
|
|
//
|
|
|
|
// Returns apistatus.EACLNotFound if eACL table is missing in the contract.
|
2022-06-22 10:55:31 +00:00
|
|
|
func (c *Client) GetEACL(cnr cid.ID) (*container.EACL, error) {
|
2022-05-12 16:37:46 +00:00
|
|
|
binCnr := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(binCnr)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
prm := client.TestInvokePrm{}
|
|
|
|
prm.SetMethod(eaclMethod)
|
2022-05-12 16:37:46 +00:00
|
|
|
prm.SetArgs(binCnr)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
prms, err := c.client.TestInvoke(prm)
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", eaclMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", eaclMethod, ln)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:18:47 +00:00
|
|
|
arr, err := client.ArrayFromStackItem(prms[0])
|
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get item array of eACL (%s): %w", eaclMethod, err)
|
2020-09-04 12:18:47 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 14:46:34 +00:00
|
|
|
if len(arr) != 4 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected eacl stack item count (%s): %d", eaclMethod, len(arr))
|
2020-09-04 12:18:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
rawEACL, err := client.BytesFromStackItem(arr[0])
|
2020-09-04 12:18:47 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL (%s): %w", eaclMethod, err)
|
2020-09-04 12:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := client.BytesFromStackItem(arr[1])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL signature (%s): %w", eaclMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// Client may not return errors if the table is missing, so check this case additionally.
|
|
|
|
// The absence of a signature in the response can be taken as an eACL absence criterion,
|
|
|
|
// since unsigned table cannot be approved in the storage by design.
|
|
|
|
if len(sig) == 0 {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.EACLNotFound)
|
2022-01-31 13:34:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 16:00:10 +00:00
|
|
|
pub, err := client.BytesFromStackItem(arr[2])
|
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL public key (%s): %w", eaclMethod, err)
|
2021-01-14 16:00:10 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
binToken, err := client.BytesFromStackItem(arr[3])
|
2021-05-25 16:35:41 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL session token (%s): %w", eaclMethod, err)
|
2021-05-25 16:35:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
var res container.EACL
|
|
|
|
|
|
|
|
res.Value = eacl.NewTable()
|
|
|
|
if err = res.Value.Unmarshal(rawEACL); err != nil {
|
2022-01-31 13:34:01 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(binToken) > 0 {
|
2022-06-22 10:55:31 +00:00
|
|
|
res.Session = new(session.Container)
|
2022-01-31 13:34:01 +00:00
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
err = res.Session.Unmarshal(binToken)
|
2022-01-31 13:34:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not unmarshal session token: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 13:18:39 +00:00
|
|
|
// TODO(@cthulhu-rider): #468 implement and use another approach to avoid conversion
|
2022-05-16 13:15:31 +00:00
|
|
|
var sigV2 refs.Signature
|
|
|
|
sigV2.SetKey(pub)
|
|
|
|
sigV2.SetSign(sig)
|
|
|
|
sigV2.SetScheme(refs.ECDSA_RFC6979_SHA256)
|
|
|
|
|
2022-07-22 14:04:37 +00:00
|
|
|
err = res.Signature.ReadFromV2(sigV2)
|
|
|
|
return &res, err
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|