forked from TrueCloudLab/frostfs-node
aarifullin
04aa7874b2
* Make `verifyClient` method perform APE check if a container was created with zero-filled basic ACL. * Object verbs are used in APE, until tree verbs are introduced. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package tree
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/ape/converter"
|
|
aperequest "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/ape/request"
|
|
core "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
cnrSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
|
nativeschema "git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
)
|
|
|
|
func (s *Service) checkAPE(container *core.Container, cid cid.ID, operation acl.Op, role acl.Role, publicKey *keys.PublicKey) error {
|
|
namespace := ""
|
|
cntNamespace, hasNamespace := strings.CutSuffix(cnrSDK.ReadDomain(container.Value).Zone(), ".ns")
|
|
if hasNamespace {
|
|
namespace = cntNamespace
|
|
}
|
|
|
|
schemaMethod, err := converter.SchemaMethodFromACLOperation(operation)
|
|
if err != nil {
|
|
return apeErr(err)
|
|
}
|
|
schemaRole, err := converter.SchemaRoleFromACLRole(role)
|
|
if err != nil {
|
|
return apeErr(err)
|
|
}
|
|
reqProps := map[string]string{
|
|
nativeschema.PropertyKeyActorPublicKey: hex.EncodeToString(publicKey.Bytes()),
|
|
nativeschema.PropertyKeyActorRole: schemaRole,
|
|
}
|
|
|
|
var resourceName string
|
|
if namespace == "root" || namespace == "" {
|
|
resourceName = fmt.Sprintf(nativeschema.ResourceFormatRootContainerObjects, cid.EncodeToString())
|
|
} else {
|
|
resourceName = fmt.Sprintf(nativeschema.ResourceFormatNamespaceContainerObjects, namespace, cid.EncodeToString())
|
|
}
|
|
|
|
request := aperequest.NewRequest(
|
|
schemaMethod,
|
|
aperequest.NewResource(resourceName, make(map[string]string)),
|
|
reqProps,
|
|
)
|
|
|
|
status, found, err := s.router.IsAllowed(apechain.Ingress, engine.NewRequestTarget(namespace, cid.EncodeToString()), request)
|
|
if err != nil {
|
|
return apeErr(err)
|
|
}
|
|
if found && status == apechain.Allow {
|
|
return nil
|
|
}
|
|
err = fmt.Errorf("access to operation %s is denied by access policy engine: %s", schemaMethod, status.String())
|
|
return apeErr(err)
|
|
}
|
|
|
|
func apeErr(err error) error {
|
|
errAccessDenied := &apistatus.ObjectAccessDenied{}
|
|
errAccessDenied.WriteReason(err.Error())
|
|
return errAccessDenied
|
|
}
|