Validate object lock when setting replication config. (#10200)

Check if object lock is enabled on
destination bucket while setting replication
configuration on a object lock enabled bucket.
This commit is contained in:
poornas 2020-08-04 23:02:27 -07:00 committed by GitHub
parent 1cdaced8b6
commit 88daaef76b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -107,6 +107,7 @@ const (
ErrNoSuchWebsiteConfiguration ErrNoSuchWebsiteConfiguration
ErrReplicationConfigurationNotFoundError ErrReplicationConfigurationNotFoundError
ErrReplicationDestinationNotFoundError ErrReplicationDestinationNotFoundError
ErrReplicationDestinationMissingLock
ErrReplicationTargetNotFoundError ErrReplicationTargetNotFoundError
ErrBucketRemoteIdenticalToSource ErrBucketRemoteIdenticalToSource
ErrBucketRemoteAlreadyExists ErrBucketRemoteAlreadyExists
@ -830,6 +831,11 @@ var errorCodes = errorCodeMap{
Description: "The replication destination bucket does not exist", Description: "The replication destination bucket does not exist",
HTTPStatusCode: http.StatusNotFound, HTTPStatusCode: http.StatusNotFound,
}, },
ErrReplicationDestinationMissingLock: {
Code: "ReplicationDestinationMissingLockError",
Description: "The replication destination bucket does not have object locking enabled",
HTTPStatusCode: http.StatusBadRequest,
},
ErrReplicationTargetNotFoundError: { ErrReplicationTargetNotFoundError: {
Code: "XminioAdminReplicationTargetNotFoundError", Code: "XminioAdminReplicationTargetNotFoundError",
Description: "The replication target does not exist", Description: "The replication target does not exist",
@ -1909,6 +1915,8 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) {
apiErr = ErrReplicationConfigurationNotFoundError apiErr = ErrReplicationConfigurationNotFoundError
case BucketReplicationDestinationNotFound: case BucketReplicationDestinationNotFound:
apiErr = ErrReplicationDestinationNotFoundError apiErr = ErrReplicationDestinationNotFoundError
case BucketReplicationDestinationMissingLock:
apiErr = ErrReplicationDestinationMissingLock
case BucketRemoteTargetNotFound: case BucketRemoteTargetNotFound:
apiErr = ErrReplicationTargetNotFoundError apiErr = ErrReplicationTargetNotFoundError
case BucketRemoteAlreadyExists: case BucketRemoteAlreadyExists:

View File

@ -56,6 +56,14 @@ func validateReplicationDestination(ctx context.Context, bucket string, rCfg *re
if found, _ := clnt.BucketExists(ctx, rCfg.GetDestination().Bucket); !found { if found, _ := clnt.BucketExists(ctx, rCfg.GetDestination().Bucket); !found {
return false, BucketReplicationDestinationNotFound{Bucket: rCfg.GetDestination().Bucket} return false, BucketReplicationDestinationNotFound{Bucket: rCfg.GetDestination().Bucket}
} }
if ret, err := globalBucketObjectLockSys.Get(bucket); err == nil {
if ret.LockEnabled {
lock, _, _, _, err := clnt.GetObjectLockConfig(ctx, rCfg.GetDestination().Bucket)
if err != nil || lock != "Enabled" {
return false, BucketReplicationDestinationMissingLock{Bucket: rCfg.GetDestination().Bucket}
}
}
}
// validate replication ARN against target endpoint // validate replication ARN against target endpoint
c, ok := globalBucketTargetSys.arnRemotesMap[rCfg.ReplicationArn] c, ok := globalBucketTargetSys.arnRemotesMap[rCfg.ReplicationArn]
if ok { if ok {

View File

@ -362,6 +362,13 @@ func (e BucketReplicationDestinationNotFound) Error() string {
return "Destination bucket does not exist: " + e.Bucket return "Destination bucket does not exist: " + e.Bucket
} }
// BucketReplicationDestinationMissingLock bucket does not have object lock enabled.
type BucketReplicationDestinationMissingLock GenericError
func (e BucketReplicationDestinationMissingLock) Error() string {
return "Destination bucket does not have object lock enabled: " + e.Bucket
}
// BucketRemoteTargetNotFound remote target does not exist. // BucketRemoteTargetNotFound remote target does not exist.
type BucketRemoteTargetNotFound GenericError type BucketRemoteTargetNotFound GenericError