2021-05-19 12:18:07 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-19 12:26:41 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
cntClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
2023-04-26 09:05:33 +00:00
|
|
|
containerEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/container"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
2021-05-19 12:18:07 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
func (cp *Processor) processSetEACL(e containerEvent.SetEACL) bool {
|
2021-05-19 12:18:07 +00:00
|
|
|
if !cp.alphabetState.IsAlphabet() {
|
2023-04-12 14:35:10 +00:00
|
|
|
cp.log.Info(logs.ContainerNonAlphabetModeIgnoreSetEACL)
|
2023-05-26 10:24:41 +00:00
|
|
|
return true
|
2021-05-19 12:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := cp.checkSetEACL(e)
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
cp.log.Error(logs.ContainerSetEACLCheckFailed,
|
2021-05-19 12:18:07 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
return false
|
2021-05-19 12:18:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
if err := cp.morphClient.NotarySignAndInvokeTX(e.NotaryRequest().MainTransaction); err != nil {
|
|
|
|
cp.log.Error(logs.ContainerCouldNotApproveSetEACL,
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2021-05-19 12:18:07 +00:00
|
|
|
}
|
|
|
|
|
2023-04-26 09:05:33 +00:00
|
|
|
func (cp *Processor) checkSetEACL(e containerEvent.SetEACL) error {
|
2021-05-27 12:07:39 +00:00
|
|
|
binTable := e.Table()
|
2021-05-19 12:28:10 +00:00
|
|
|
|
|
|
|
// unmarshal table
|
|
|
|
table := eacl.NewTable()
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
err := table.Unmarshal(binTable)
|
2021-05-19 12:28:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid binary table: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
idCnr, ok := table.CID()
|
|
|
|
if !ok {
|
|
|
|
return errors.New("missing container ID in eACL table")
|
|
|
|
}
|
|
|
|
|
2021-05-19 12:28:10 +00:00
|
|
|
// receive owner of the related container
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr, err := cntClient.Get(cp.cnrClient, idCnr)
|
2021-05-19 12:28:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not receive the container: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-06-06 16:23:15 +00:00
|
|
|
// ACL extensions can be disabled by basic ACL, check it
|
2022-06-17 13:40:51 +00:00
|
|
|
if !cnr.Value.BasicACL().Extendable() {
|
2022-06-06 16:23:15 +00:00
|
|
|
return errors.New("ACL extension disabled by container basic ACL")
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
err = cp.verifySignature(signatureVerificationData{
|
2022-06-28 07:01:05 +00:00
|
|
|
ownerContainer: cnr.Value.Owner(),
|
2022-05-18 15:20:08 +00:00
|
|
|
verb: session.VerbContainerSetEACL,
|
|
|
|
idContainerSet: true,
|
|
|
|
idContainer: idCnr,
|
|
|
|
binTokenSession: e.SessionToken(),
|
|
|
|
binPublicKey: e.PublicKey(),
|
|
|
|
signature: e.Signature(),
|
|
|
|
signedData: binTable,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("auth eACL table setting: %w", err)
|
2021-05-28 12:39:27 +00:00
|
|
|
}
|
2021-05-27 12:07:39 +00:00
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
return nil
|
2021-05-19 12:18:07 +00:00
|
|
|
}
|