2023-10-30 15:30:23 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
v2 "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/acl/v2"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-11-16 07:58:55 +00:00
|
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
2023-12-05 10:26:09 +00:00
|
|
|
policyengine "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
2023-10-30 15:30:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type apeCheckerImpl struct {
|
2023-11-20 16:35:16 +00:00
|
|
|
log *logger.Logger
|
|
|
|
chainRouter policyengine.ChainRouter
|
2023-10-30 15:30:23 +00:00
|
|
|
}
|
|
|
|
|
2023-11-20 16:35:16 +00:00
|
|
|
func NewAPEChecker(log *logger.Logger, chainRouter policyengine.ChainRouter) v2.APEChainChecker {
|
2023-10-30 15:30:23 +00:00
|
|
|
return &apeCheckerImpl{
|
2023-11-20 16:35:16 +00:00
|
|
|
log: log,
|
|
|
|
chainRouter: chainRouter,
|
2023-10-30 15:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *apeCheckerImpl) CheckIfRequestPermitted(reqInfo v2.RequestInfo) error {
|
|
|
|
request := new(Request)
|
|
|
|
request.FromRequestInfo(reqInfo)
|
|
|
|
|
2023-12-05 10:26:09 +00:00
|
|
|
cnrTarget := getResource(reqInfo).Name()
|
|
|
|
|
2023-11-20 16:35:16 +00:00
|
|
|
status, ruleFound, err := c.chainRouter.IsAllowed(apechain.Ingress, policyengine.NewRequestTargetWithContainer(cnrTarget), request)
|
2023-11-16 07:58:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-30 15:30:23 +00:00
|
|
|
|
2023-11-16 07:58:55 +00:00
|
|
|
if !ruleFound || status == apechain.Allow {
|
2023-10-30 15:30:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return apeErr(reqInfo, status)
|
|
|
|
}
|
|
|
|
|
|
|
|
const accessDeniedAPEReasonFmt = "access to operation %s is denied by access policy engine: %s"
|
|
|
|
|
2023-11-16 07:58:55 +00:00
|
|
|
func apeErr(req v2.RequestInfo, status apechain.Status) error {
|
2023-10-30 15:30:23 +00:00
|
|
|
errAccessDenied := &apistatus.ObjectAccessDenied{}
|
|
|
|
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedAPEReasonFmt, req.Operation(), status.String()))
|
|
|
|
return errAccessDenied
|
|
|
|
}
|