2023-11-10 14:56:41 +00:00
|
|
|
package iam
|
|
|
|
|
|
|
|
import (
|
2024-04-12 10:56:26 +00:00
|
|
|
"errors"
|
2023-11-10 14:56:41 +00:00
|
|
|
"fmt"
|
2023-12-18 14:00:31 +00:00
|
|
|
"strings"
|
2023-11-10 14:56:41 +00:00
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
|
|
|
)
|
|
|
|
|
|
|
|
const PropertyKeyFilePath = "FilePath"
|
|
|
|
|
2024-03-29 12:47:49 +00:00
|
|
|
var actionToNativeOpMap = map[string][]string{
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionAbortMultipartUpload: {native.MethodGetContainer, native.MethodDeleteObject, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionCreateBucket: {native.MethodGetContainer, native.MethodPutContainer, native.MethodSetContainerEACL, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionDeleteBucket: {native.MethodGetContainer, native.MethodDeleteContainer, native.MethodSearchObject, native.MethodHeadObject, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionDeleteBucketPolicy: {native.MethodGetContainer},
|
2024-04-12 06:45:31 +00:00
|
|
|
s3ActionDeleteObject: {native.MethodGetContainer, native.MethodDeleteObject, native.MethodPutObject, native.MethodHeadObject, native.MethodGetObject, native.MethodRangeObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionDeleteObjectTagging: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
2024-04-12 06:45:31 +00:00
|
|
|
s3ActionDeleteObjectVersion: {native.MethodGetContainer, native.MethodDeleteObject, native.MethodPutObject, native.MethodHeadObject, native.MethodGetObject, native.MethodRangeObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionDeleteObjectVersionTagging: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionGetBucketACL: {native.MethodGetContainer, native.MethodGetContainerEACL, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionGetBucketCORS: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject},
|
|
|
|
s3ActionGetBucketLocation: {native.MethodGetContainer},
|
|
|
|
s3ActionGetBucketNotification: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionGetBucketObjectLockConfiguration: {native.MethodGetContainer, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionGetBucketPolicy: {native.MethodGetContainer},
|
|
|
|
s3ActionGetBucketPolicyStatus: {native.MethodGetContainer},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionGetBucketTagging: {native.MethodGetContainer, native.MethodGetObject},
|
|
|
|
s3ActionGetBucketVersioning: {native.MethodGetContainer, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionGetLifecycleConfiguration: { /*not implemented yet*/ },
|
|
|
|
s3ActionGetObject: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject, native.MethodSearchObject, native.MethodRangeObject, native.MethodHashObject},
|
|
|
|
s3ActionGetObjectACL: {native.MethodGetContainer, native.MethodGetContainerEACL, native.MethodGetObject, native.MethodHeadObject},
|
|
|
|
s3ActionGetObjectAttributes: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionGetObjectLegalHold: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject},
|
|
|
|
s3ActionGetObjectRetention: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject},
|
|
|
|
s3ActionGetObjectTagging: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionGetObjectVersion: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject, native.MethodSearchObject, native.MethodRangeObject, native.MethodHashObject},
|
|
|
|
s3ActionGetObjectVersionACL: {native.MethodGetContainer, native.MethodGetContainerEACL, native.MethodGetObject, native.MethodHeadObject},
|
|
|
|
s3ActionGetObjectVersionAttributes: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionGetObjectVersionTagging: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionListAllMyBuckets: {native.MethodListContainers, native.MethodGetContainer},
|
|
|
|
s3ActionListBucket: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject, native.MethodSearchObject, native.MethodRangeObject, native.MethodHashObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionListBucketMultipartUploads: {native.MethodGetContainer, native.MethodGetObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionListBucketVersions: {native.MethodGetContainer, native.MethodGetObject, native.MethodHeadObject, native.MethodSearchObject, native.MethodRangeObject, native.MethodHashObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionListMultipartUploadParts: {native.MethodGetContainer, native.MethodGetObject},
|
|
|
|
s3ActionPutBucketACL: {native.MethodGetContainer, native.MethodSetContainerEACL, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionPutBucketCORS: {native.MethodGetContainer, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionPutBucketNotification: {native.MethodGetContainer, native.MethodHeadObject, native.MethodDeleteObject, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionPutBucketObjectLockConfiguration: {native.MethodGetContainer, native.MethodGetObject, native.MethodPutObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionPutBucketPolicy: {native.MethodGetContainer},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionPutBucketTagging: {native.MethodGetContainer, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionPutBucketVersioning: {native.MethodGetContainer, native.MethodGetObject, native.MethodPutObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionPutLifecycleConfiguration: { /*not implemented yet*/ },
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionPutObject: {native.MethodGetContainer, native.MethodPutObject, native.MethodGetObject, native.MethodHeadObject, native.MethodRangeObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionPutObjectACL: {native.MethodGetContainer, native.MethodGetContainerEACL, native.MethodSetContainerEACL, native.MethodGetObject, native.MethodHeadObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionPutObjectLegalHold: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionPutObjectRetention: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
|
|
|
s3ActionPutObjectTagging: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
2024-03-29 12:47:49 +00:00
|
|
|
s3ActionPutObjectVersionACL: {native.MethodGetContainer, native.MethodGetContainerEACL, native.MethodSetContainerEACL, native.MethodGetObject, native.MethodHeadObject},
|
2024-04-12 10:21:00 +00:00
|
|
|
s3ActionPutObjectVersionTagging: {native.MethodGetContainer, native.MethodHeadObject, native.MethodGetObject, native.MethodPutObject},
|
2024-01-26 09:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var containerNativeOperations = map[string]struct{}{
|
|
|
|
native.MethodPutContainer: {},
|
|
|
|
native.MethodDeleteContainer: {},
|
|
|
|
native.MethodGetContainer: {},
|
|
|
|
native.MethodListContainers: {},
|
|
|
|
native.MethodSetContainerEACL: {},
|
|
|
|
native.MethodGetContainerEACL: {},
|
|
|
|
}
|
|
|
|
|
|
|
|
var objectNativeOperations = map[string]struct{}{
|
|
|
|
native.MethodGetObject: {},
|
|
|
|
native.MethodPutObject: {},
|
|
|
|
native.MethodHeadObject: {},
|
|
|
|
native.MethodDeleteObject: {},
|
|
|
|
native.MethodSearchObject: {},
|
|
|
|
native.MethodRangeObject: {},
|
|
|
|
native.MethodHashObject: {},
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
|
|
|
|
2024-04-12 10:56:26 +00:00
|
|
|
var errConditionKeyNotApplicable = errors.New("condition key is not applicable")
|
|
|
|
|
2023-11-10 14:56:41 +00:00
|
|
|
type NativeResolver interface {
|
|
|
|
GetUserKey(account, name string) (string, error)
|
2024-01-26 09:26:20 +00:00
|
|
|
GetBucketInfo(bucket string) (*BucketInfo, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type BucketInfo struct {
|
|
|
|
Namespace string
|
|
|
|
Container string
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ConvertToNativeChain(p Policy, resolver NativeResolver) (*chain.Chain, error) {
|
|
|
|
if err := p.Validate(ResourceBasedPolicyType); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var engineChain chain.Chain
|
|
|
|
|
|
|
|
for _, statement := range p.Statement {
|
|
|
|
status := formStatus(statement)
|
2024-03-29 12:47:49 +00:00
|
|
|
if status != chain.Allow {
|
|
|
|
// Most s3 methods share the same native operations. Deny rules must not affect shared native operations,
|
|
|
|
// therefore this code skips all deny rules for native protocol. Deny is applied for s3 protocol only, in this case.
|
|
|
|
continue
|
|
|
|
}
|
2023-11-10 14:56:41 +00:00
|
|
|
|
|
|
|
action, actionInverted := statement.action()
|
2023-11-28 14:56:36 +00:00
|
|
|
nativeActions, err := formNativeActionNames(action)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ruleAction := chain.Actions{Inverted: actionInverted, Names: nativeActions}
|
2023-11-10 14:56:41 +00:00
|
|
|
if len(ruleAction.Names) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
resource, resourceInverted := statement.resource()
|
2024-01-26 09:26:20 +00:00
|
|
|
groupedResources, err := formNativeResourceNamesAndConditions(resource, resolver, getActionTypes(nativeActions))
|
2023-11-10 14:56:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
groupedConditions, err := convertToNativeChainCondition(statement.Conditions, resolver)
|
|
|
|
if err != nil {
|
2024-04-12 10:56:26 +00:00
|
|
|
if errors.Is(err, errConditionKeyNotApplicable) {
|
|
|
|
continue
|
|
|
|
}
|
2023-11-10 14:56:41 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
splitConditions := splitGroupedConditions(groupedConditions)
|
|
|
|
|
|
|
|
principals, principalCondFn, err := getNativePrincipalsAndConditionFunc(statement, resolver)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, groupedResource := range groupedResources {
|
|
|
|
for _, principal := range principals {
|
|
|
|
for _, conditions := range splitConditions {
|
2024-01-26 09:54:39 +00:00
|
|
|
var principalCondition []chain.Condition
|
|
|
|
if principal != Wildcard {
|
|
|
|
principalCondition = []chain.Condition{principalCondFn(principal)}
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleConditions := append(principalCondition, groupedResource.Conditions...)
|
2023-11-10 14:56:41 +00:00
|
|
|
|
|
|
|
r := chain.Rule{
|
|
|
|
Status: status,
|
|
|
|
Actions: ruleAction,
|
|
|
|
Resources: chain.Resources{
|
|
|
|
Inverted: resourceInverted,
|
|
|
|
Names: groupedResource.Names,
|
|
|
|
},
|
|
|
|
Condition: append(ruleConditions, conditions...),
|
|
|
|
}
|
|
|
|
engineChain.Rules = append(engineChain.Rules, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(engineChain.Rules) == 0 {
|
|
|
|
return nil, ErrActionsNotApplicable
|
|
|
|
}
|
|
|
|
|
|
|
|
return &engineChain, nil
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:26:20 +00:00
|
|
|
func getActionTypes(nativeActions []string) ActionTypes {
|
|
|
|
var res ActionTypes
|
|
|
|
for _, action := range nativeActions {
|
|
|
|
if res.Object && res.Container {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
_, isObj := objectNativeOperations[action]
|
|
|
|
_, isCnr := containerNativeOperations[action]
|
|
|
|
|
2024-03-29 12:47:49 +00:00
|
|
|
res.Object = res.Object || isObj || action == Wildcard
|
|
|
|
res.Container = res.Container || isCnr || action == Wildcard
|
2024-01-26 09:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2023-11-10 14:56:41 +00:00
|
|
|
func getNativePrincipalsAndConditionFunc(statement Statement, resolver NativeResolver) ([]string, formPrincipalConditionFunc, error) {
|
|
|
|
var principals []string
|
|
|
|
var op chain.ConditionType
|
|
|
|
statementPrincipal, inverted := statement.principal()
|
|
|
|
if _, ok := statementPrincipal[Wildcard]; ok { // this can be true only if 'inverted' false
|
|
|
|
principals = []string{Wildcard}
|
|
|
|
op = chain.CondStringLike
|
|
|
|
} else {
|
|
|
|
for principalType, principal := range statementPrincipal {
|
|
|
|
if principalType != AWSPrincipalType {
|
|
|
|
return nil, nil, fmt.Errorf("unsupported principal type '%s'", principalType)
|
|
|
|
}
|
|
|
|
parsedPrincipal, err := formNativePrincipal(principal, resolver)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("parse principal: %w", err)
|
|
|
|
}
|
|
|
|
principals = append(principals, parsedPrincipal...)
|
|
|
|
}
|
|
|
|
|
|
|
|
op = chain.CondStringEquals
|
|
|
|
if inverted {
|
|
|
|
op = chain.CondStringNotEquals
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return principals, func(principal string) chain.Condition {
|
|
|
|
return chain.Condition{
|
2024-05-13 10:54:37 +00:00
|
|
|
Op: op,
|
|
|
|
Kind: chain.KindRequest,
|
|
|
|
Key: native.PropertyKeyActorPublicKey,
|
|
|
|
Value: principal,
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertToNativeChainCondition(c Conditions, resolver NativeResolver) ([]GroupedConditions, error) {
|
|
|
|
return convertToChainConditions(c, func(gr GroupedConditions) (GroupedConditions, error) {
|
|
|
|
for i := range gr.Conditions {
|
2024-04-12 10:56:26 +00:00
|
|
|
if gr.Conditions[i].Key == condKeyAWSMFAPresent {
|
|
|
|
return GroupedConditions{}, errConditionKeyNotApplicable
|
|
|
|
}
|
2023-11-10 14:56:41 +00:00
|
|
|
if gr.Conditions[i].Key == condKeyAWSPrincipalARN {
|
|
|
|
gr.Conditions[i].Key = native.PropertyKeyActorPublicKey
|
|
|
|
val, err := formPrincipalKey(gr.Conditions[i].Value, resolver)
|
|
|
|
if err != nil {
|
|
|
|
return GroupedConditions{}, err
|
|
|
|
}
|
|
|
|
gr.Conditions[i].Value = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gr, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type GroupedResources struct {
|
|
|
|
Names []string
|
|
|
|
Conditions []chain.Condition
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:26:20 +00:00
|
|
|
type ActionTypes struct {
|
|
|
|
Object bool
|
|
|
|
Container bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func formNativeResourceNamesAndConditions(names []string, resolver NativeResolver, actionTypes ActionTypes) ([]GroupedResources, error) {
|
|
|
|
if !actionTypes.Object && !actionTypes.Container {
|
|
|
|
return nil, ErrActionsNotApplicable
|
|
|
|
}
|
|
|
|
|
2023-11-10 14:56:41 +00:00
|
|
|
res := make([]GroupedResources, 0, len(names))
|
|
|
|
|
2024-03-29 12:47:49 +00:00
|
|
|
combined := make(map[string]struct{})
|
2023-11-10 14:56:41 +00:00
|
|
|
|
2023-12-19 07:35:14 +00:00
|
|
|
for _, resource := range names {
|
|
|
|
if err := validateResource(resource); err != nil {
|
2023-11-10 14:56:41 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-12-19 07:35:14 +00:00
|
|
|
if resource == Wildcard {
|
|
|
|
res = res[:0]
|
2024-01-26 09:54:39 +00:00
|
|
|
return append(res, formWildcardNativeResource(actionTypes)), nil
|
2023-12-19 07:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(resource, s3ResourcePrefix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var bkt, obj string
|
|
|
|
s3Resource := strings.TrimPrefix(resource, s3ResourcePrefix)
|
|
|
|
if s3Resource == Wildcard {
|
2023-11-10 14:56:41 +00:00
|
|
|
res = res[:0]
|
2024-01-26 09:54:39 +00:00
|
|
|
return append(res, formWildcardNativeResource(actionTypes)), nil
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-19 07:35:14 +00:00
|
|
|
if sepIndex := strings.Index(s3Resource, "/"); sepIndex < 0 {
|
|
|
|
bkt = s3Resource
|
|
|
|
} else {
|
|
|
|
bkt = s3Resource[:sepIndex]
|
|
|
|
obj = s3Resource[sepIndex+1:]
|
|
|
|
if len(obj) == 0 {
|
|
|
|
obj = Wildcard
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:26:20 +00:00
|
|
|
bktInfo, err := resolver.GetBucketInfo(bkt)
|
2023-11-10 14:56:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:26:20 +00:00
|
|
|
if obj == Wildcard && actionTypes.Object { // this corresponds to arn:aws:s3:::BUCKET/ or arn:aws:s3:::BUCKET/*
|
2024-03-29 12:47:49 +00:00
|
|
|
combined[fmt.Sprintf(native.ResourceFormatNamespaceContainerObjects, bktInfo.Namespace, bktInfo.Container)] = struct{}{}
|
|
|
|
combined[fmt.Sprintf(native.ResourceFormatNamespaceContainer, bktInfo.Namespace, bktInfo.Container)] = struct{}{}
|
2024-01-26 09:26:20 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if obj == "" && actionTypes.Container { // this corresponds to arn:aws:s3:::BUCKET
|
2024-03-29 12:47:49 +00:00
|
|
|
combined[fmt.Sprintf(native.ResourceFormatNamespaceContainer, bktInfo.Namespace, bktInfo.Container)] = struct{}{}
|
2023-11-10 14:56:41 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, GroupedResources{
|
2024-03-29 12:47:49 +00:00
|
|
|
Names: []string{
|
|
|
|
fmt.Sprintf(native.ResourceFormatNamespaceContainerObjects, bktInfo.Namespace, bktInfo.Container),
|
|
|
|
fmt.Sprintf(native.ResourceFormatNamespaceContainer, bktInfo.Namespace, bktInfo.Container),
|
|
|
|
},
|
2023-11-10 14:56:41 +00:00
|
|
|
Conditions: []chain.Condition{
|
|
|
|
{
|
2024-05-13 10:54:37 +00:00
|
|
|
Op: chain.CondStringLike,
|
|
|
|
Kind: chain.KindResource,
|
|
|
|
Key: PropertyKeyFilePath,
|
|
|
|
Value: obj,
|
2023-11-10 14:56:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(combined) != 0 {
|
2024-03-29 12:47:49 +00:00
|
|
|
gr := GroupedResources{Names: make([]string, 0, len(combined))}
|
|
|
|
for key := range combined {
|
|
|
|
gr.Names = append(gr.Names, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, gr)
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:54:39 +00:00
|
|
|
func formWildcardNativeResource(actionTypes ActionTypes) GroupedResources {
|
|
|
|
groupedNames := make([]string, 0, 2)
|
|
|
|
if actionTypes.Object {
|
|
|
|
groupedNames = append(groupedNames, native.ResourceFormatAllObjects)
|
|
|
|
}
|
|
|
|
if actionTypes.Container {
|
|
|
|
groupedNames = append(groupedNames, native.ResourceFormatAllContainers)
|
|
|
|
}
|
|
|
|
|
|
|
|
return GroupedResources{Names: groupedNames}
|
|
|
|
}
|
|
|
|
|
2023-11-10 14:56:41 +00:00
|
|
|
func formNativePrincipal(principal []string, resolver NativeResolver) ([]string, error) {
|
|
|
|
res := make([]string, len(principal))
|
|
|
|
|
|
|
|
var err error
|
|
|
|
for i := range principal {
|
|
|
|
if res[i], err = formPrincipalKey(principal[i], resolver); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func formPrincipalKey(principal string, resolver NativeResolver) (string, error) {
|
|
|
|
account, user, err := parsePrincipalAsIAMUser(principal)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := resolver.GetUserKey(account, user)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("get user key: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return key, nil
|
|
|
|
}
|
|
|
|
|
2023-11-28 14:56:36 +00:00
|
|
|
func formNativeActionNames(names []string) ([]string, error) {
|
2024-03-29 12:47:49 +00:00
|
|
|
uniqueActions := make(map[string]struct{}, len(names))
|
2023-11-10 14:56:41 +00:00
|
|
|
|
2023-12-19 07:35:14 +00:00
|
|
|
for _, action := range names {
|
|
|
|
if action == Wildcard {
|
|
|
|
return []string{Wildcard}, nil
|
|
|
|
}
|
|
|
|
|
2024-03-29 12:47:49 +00:00
|
|
|
isIAM, err := validateAction(action)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if isIAM {
|
2023-12-19 07:35:14 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-03-29 12:47:49 +00:00
|
|
|
if action[len(s3ActionPrefix):] == Wildcard {
|
2023-11-28 14:56:36 +00:00
|
|
|
return []string{Wildcard}, nil
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
2023-12-19 07:35:14 +00:00
|
|
|
|
2024-03-29 12:47:49 +00:00
|
|
|
nativeActions := actionToNativeOpMap[action]
|
|
|
|
if len(nativeActions) == 0 {
|
|
|
|
return nil, ErrActionsNotApplicable
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, nativeAction := range nativeActions {
|
|
|
|
uniqueActions[nativeAction] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res := make([]string, 0, len(uniqueActions))
|
|
|
|
for key := range uniqueActions {
|
|
|
|
res = append(res, key)
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-28 14:56:36 +00:00
|
|
|
return res, nil
|
2023-11-10 14:56:41 +00:00
|
|
|
}
|