@ -25,7 +25,6 @@ import (
"path"
"path"
"strings"
"strings"
"sync"
"sync"
"time"
miniogopolicy "github.com/minio/minio-go/v6/pkg/policy"
miniogopolicy "github.com/minio/minio-go/v6/pkg/policy"
"github.com/minio/minio-go/v6/pkg/set"
"github.com/minio/minio-go/v6/pkg/set"
@ -61,6 +60,11 @@ func (sys *PolicySys) removeDeletedBuckets(bucketInfos []BucketInfo) {
// Set - sets policy to given bucket name. If policy is empty, existing policy is removed.
// Set - sets policy to given bucket name. If policy is empty, existing policy is removed.
func ( sys * PolicySys ) Set ( bucketName string , policy policy . Policy ) {
func ( sys * PolicySys ) Set ( bucketName string , policy policy . Policy ) {
if globalIsGateway {
// Set policy is a non-op under gateway mode.
return
}
sys . Lock ( )
sys . Lock ( )
defer sys . Unlock ( )
defer sys . Unlock ( )
@ -84,10 +88,22 @@ func (sys *PolicySys) IsAllowed(args policy.Args) bool {
sys . RLock ( )
sys . RLock ( )
defer sys . RUnlock ( )
defer sys . RUnlock ( )
if globalIsGateway {
// When gateway is enabled, no cached value
// is used to validate bucket policies.
objAPI := newObjectLayerFn ( )
if objAPI != nil {
config , err := objAPI . GetBucketPolicy ( context . Background ( ) , args . BucketName )
if err == nil {
return config . IsAllowed ( args )
}
}
} else {
// If policy is available for given bucket, check the policy.
// If policy is available for given bucket, check the policy.
if p , found := sys . bucketPolicyMap [ args . BucketName ] ; found {
if p , found := sys . bucketPolicyMap [ args . BucketName ] ; found {
return p . IsAllowed ( args )
return p . IsAllowed ( args )
}
}
}
// As policy is not available for given bucket name, returns IsOwner i.e.
// As policy is not available for given bucket name, returns IsOwner i.e.
// operation is allowed only for owner.
// operation is allowed only for owner.
@ -135,21 +151,11 @@ func (sys *PolicySys) Init(objAPI ObjectLayer) error {
return errInvalidArgument
return errInvalidArgument
}
}
defer func ( ) {
// In gateway mode, we don't need to load the policies
// Refresh PolicySys in background.
// from the backend.
go func ( ) {
if globalIsGateway {
ticker := time . NewTicker ( globalRefreshBucketPolicyInterval )
return nil
defer ticker . Stop ( )
for {
select {
case <- GlobalServiceDoneCh :
return
case <- ticker . C :
sys . refresh ( objAPI )
}
}
}
} ( )
} ( )
doneCh := make ( chan struct { } )
doneCh := make ( chan struct { } )
defer close ( doneCh )
defer close ( doneCh )