2023-12-27 14:18:15 +00:00
|
|
|
package ape
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-03-11 14:55:50 +00:00
|
|
|
"errors"
|
2023-12-27 14:18:15 +00:00
|
|
|
"fmt"
|
|
|
|
|
2024-05-08 07:02:54 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2024-05-02 17:26:06 +00:00
|
|
|
frostfsidcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/frostfsid"
|
2024-05-08 07:02:54 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
2024-09-10 08:15:30 +00:00
|
|
|
checkercore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/common/ape"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
2024-05-29 08:11:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
2023-12-27 14:18:15 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2024-03-15 12:16:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2023-12-27 14:18:15 +00:00
|
|
|
policyengine "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
2024-03-12 12:09:55 +00:00
|
|
|
nativeschema "git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
2024-04-11 10:51:39 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2023-12-27 14:18:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type checkerImpl struct {
|
2024-09-10 08:15:30 +00:00
|
|
|
checkerCore checkercore.CheckCore
|
|
|
|
frostFSIDClient frostfsidcore.SubjectProvider
|
|
|
|
headerProvider HeaderProvider
|
|
|
|
nm netmap.Source
|
|
|
|
cnrSource container.Source
|
|
|
|
nodePK []byte
|
2024-04-15 13:51:19 +00:00
|
|
|
}
|
|
|
|
|
2024-07-01 15:42:15 +00:00
|
|
|
func NewChecker(localOverrideStorage policyengine.LocalOverrideStorage, morphChainStorage policyengine.MorphRuleChainStorageReader, headerProvider HeaderProvider, frostFSIDClient frostfsidcore.SubjectProvider, nm netmap.Source, st netmap.State, cnrSource container.Source, nodePK []byte) Checker {
|
2023-12-27 14:18:15 +00:00
|
|
|
return &checkerImpl{
|
2024-09-10 08:15:30 +00:00
|
|
|
checkerCore: checkercore.New(localOverrideStorage, morphChainStorage, frostFSIDClient, st),
|
|
|
|
frostFSIDClient: frostFSIDClient,
|
|
|
|
headerProvider: headerProvider,
|
|
|
|
nm: nm,
|
|
|
|
cnrSource: cnrSource,
|
|
|
|
nodePK: nodePK,
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Prm struct {
|
|
|
|
Namespace string
|
|
|
|
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// Object ID is omitted for some methods.
|
|
|
|
Object *oid.ID
|
|
|
|
|
|
|
|
// If Header is set, then object attributes and properties will be parsed from
|
|
|
|
// a request/response's header.
|
|
|
|
Header *objectV2.Header
|
|
|
|
|
|
|
|
// Method must be represented only as a constant represented in native schema.
|
|
|
|
Method string
|
|
|
|
|
|
|
|
// Role must be representedonly as a constant represented in native schema.
|
|
|
|
Role string
|
|
|
|
|
|
|
|
// An encoded sender's public key string.
|
|
|
|
SenderKey string
|
2024-02-14 11:14:07 +00:00
|
|
|
|
2024-03-15 12:16:52 +00:00
|
|
|
// An encoded container's owner user ID.
|
|
|
|
ContainerOwner user.ID
|
|
|
|
|
2024-02-14 11:14:07 +00:00
|
|
|
// If SoftAPECheck is set to true, then NoRuleFound is interpreted as allow.
|
|
|
|
SoftAPECheck bool
|
2024-04-04 11:55:38 +00:00
|
|
|
|
2024-05-29 08:11:45 +00:00
|
|
|
// The request's bearer token. It is used in order to check APE overrides with the token.
|
|
|
|
BearerToken *bearer.Token
|
2024-07-12 09:02:20 +00:00
|
|
|
|
|
|
|
// XHeaders from the request.
|
|
|
|
XHeaders []session.XHeader
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
2024-09-10 08:15:30 +00:00
|
|
|
var errMissingOID = errors.New("object ID is not set")
|
2023-12-27 14:18:15 +00:00
|
|
|
|
2024-09-10 08:15:30 +00:00
|
|
|
// CheckAPE prepares an APE-request and checks if it is permitted by policies.
|
2023-12-27 14:18:15 +00:00
|
|
|
func (c *checkerImpl) CheckAPE(ctx context.Context, prm Prm) error {
|
2024-03-12 12:09:55 +00:00
|
|
|
// APE check is ignored for some inter-node requests.
|
|
|
|
if prm.Role == nativeschema.PropertyValueContainerRoleContainer {
|
|
|
|
return nil
|
|
|
|
} else if prm.Role == nativeschema.PropertyValueContainerRoleIR {
|
|
|
|
switch prm.Method {
|
|
|
|
case nativeschema.MethodGetObject,
|
|
|
|
nativeschema.MethodHeadObject,
|
|
|
|
nativeschema.MethodSearchObject,
|
|
|
|
nativeschema.MethodRangeObject,
|
|
|
|
nativeschema.MethodHashObject:
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-27 14:18:15 +00:00
|
|
|
r, err := c.newAPERequest(ctx, prm)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create ape request: %w", err)
|
|
|
|
}
|
2024-04-11 10:51:39 +00:00
|
|
|
pub, err := keys.NewPublicKeyFromString(prm.SenderKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-12-27 14:18:15 +00:00
|
|
|
|
2024-09-10 08:15:30 +00:00
|
|
|
return c.checkerCore.CheckAPE(checkercore.CheckPrm{
|
|
|
|
Request: r,
|
|
|
|
PublicKey: pub,
|
2024-09-27 10:45:57 +00:00
|
|
|
Namespace: prm.Namespace,
|
2024-09-10 08:15:30 +00:00
|
|
|
Container: prm.Container,
|
|
|
|
ContainerOwner: prm.ContainerOwner,
|
|
|
|
BearerToken: prm.BearerToken,
|
|
|
|
SoftAPECheck: prm.SoftAPECheck,
|
|
|
|
})
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|