2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-02 02:15:17 -05:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2017-11-25 14:58:29 -05:00
|
|
|
import (
|
2018-03-15 16:27:16 -04:00
|
|
|
"context"
|
2022-10-25 13:52:29 -04:00
|
|
|
"encoding/base64"
|
2020-05-14 02:55:38 -04:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2018-03-15 16:27:16 -04:00
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
"github.com/minio/minio-go/v7/pkg/s3utils"
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/logger"
|
2017-11-25 14:58:29 -05:00
|
|
|
)
|
2016-12-02 02:15:17 -05:00
|
|
|
|
|
|
|
// Checks on GetObject arguments, bucket and object.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkGetObjArgs(ctx context.Context, bucket, object string) error {
|
|
|
|
return checkBucketAndObjectNames(ctx, bucket, object)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks on DeleteObject arguments, bucket and object.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkDelObjArgs(ctx context.Context, bucket, object string) error {
|
|
|
|
return checkBucketAndObjectNames(ctx, bucket, object)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks bucket and object name validity, returns nil if both are valid.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkBucketAndObjectNames(ctx context.Context, bucket, object string) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
// Verify if bucket is valid.
|
2019-08-20 23:40:52 -04:00
|
|
|
if !isMinioMetaBucketName(bucket) && s3utils.CheckValidBucketName(bucket) != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return BucketNameInvalid{Bucket: bucket}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
// Verify if object is valid.
|
2018-01-29 21:43:13 -05:00
|
|
|
if len(object) == 0 {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{Bucket: bucket, Object: object}
|
2018-01-29 21:43:13 -05:00
|
|
|
}
|
|
|
|
if !IsValidObjectPrefix(object) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{Bucket: bucket, Object: object}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2020-05-14 02:55:38 -04:00
|
|
|
if runtime.GOOS == globalWindowsOSName && strings.Contains(object, "\\") {
|
|
|
|
// Objects cannot be contain \ in Windows and is listed as `Characters to Avoid`.
|
|
|
|
return ObjectNameInvalid{Bucket: bucket, Object: object}
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for all ListObjects arguments validity.
|
2020-09-10 12:18:19 -04:00
|
|
|
func checkListObjsArgs(ctx context.Context, bucket, prefix, marker string, obj getBucketInfoI) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
// Verify if bucket exists before validating object name.
|
|
|
|
// This is done on purpose since the order of errors is
|
|
|
|
// important here bucket does not exist error should
|
|
|
|
// happen before we return an error for invalid object name.
|
|
|
|
// FIXME: should be moved to handler layer.
|
2018-04-05 18:04:40 -04:00
|
|
|
if err := checkBucketExist(ctx, bucket, obj); err != nil {
|
|
|
|
return err
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
// Validates object prefix validity after bucket exists.
|
|
|
|
if !IsValidObjectPrefix(prefix) {
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, ObjectNameInvalid{
|
2016-12-02 02:15:17 -05:00
|
|
|
Bucket: bucket,
|
|
|
|
Object: prefix,
|
|
|
|
})
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: prefix,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for all ListMultipartUploads arguments validity.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkListMultipartArgs(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string, obj ObjectLayer) error {
|
2020-02-25 10:52:28 -05:00
|
|
|
if err := checkListObjsArgs(ctx, bucket, prefix, keyMarker, obj); err != nil {
|
2016-12-02 02:15:17 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if uploadIDMarker != "" {
|
2019-12-06 02:16:06 -05:00
|
|
|
if HasSuffix(keyMarker, SlashSeparator) {
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, InvalidUploadIDKeyCombination{
|
2016-12-02 02:15:17 -05:00
|
|
|
UploadIDMarker: uploadIDMarker,
|
|
|
|
KeyMarker: keyMarker,
|
|
|
|
})
|
2018-04-05 18:04:40 -04:00
|
|
|
return InvalidUploadIDKeyCombination{
|
|
|
|
UploadIDMarker: uploadIDMarker,
|
|
|
|
KeyMarker: keyMarker,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2022-11-09 19:41:16 -05:00
|
|
|
_, err := base64.RawURLEncoding.DecodeString(uploadIDMarker)
|
2022-10-25 13:52:29 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return MalformedUploadID{
|
|
|
|
UploadID: uploadIDMarker,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for NewMultipartUpload arguments validity, also validates if bucket exists.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkNewMultipartArgs(ctx context.Context, bucket, object string, obj ObjectLayer) error {
|
|
|
|
return checkObjectArgs(ctx, bucket, object, obj)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
2023-08-17 12:37:55 -04:00
|
|
|
func checkMultipartObjectArgs(ctx context.Context, bucket, object, uploadID string, obj ObjectLayer) error {
|
|
|
|
_, err := base64.RawURLEncoding.DecodeString(uploadID)
|
|
|
|
if err != nil {
|
|
|
|
return MalformedUploadID{
|
|
|
|
UploadID: uploadID,
|
|
|
|
}
|
|
|
|
}
|
2018-04-05 18:04:40 -04:00
|
|
|
return checkObjectArgs(ctx, bucket, object, obj)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
2023-08-17 12:37:55 -04:00
|
|
|
// Checks for PutObjectPart arguments validity, also validates if bucket exists.
|
|
|
|
func checkPutObjectPartArgs(ctx context.Context, bucket, object, uploadID string, obj ObjectLayer) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID, obj)
|
|
|
|
}
|
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Checks for ListParts arguments validity, also validates if bucket exists.
|
2023-08-17 12:37:55 -04:00
|
|
|
func checkListPartsArgs(ctx context.Context, bucket, object, uploadID string, obj ObjectLayer) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID, obj)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for CompleteMultipartUpload arguments validity, also validates if bucket exists.
|
2023-08-17 12:37:55 -04:00
|
|
|
func checkCompleteMultipartArgs(ctx context.Context, bucket, object, uploadID string, obj ObjectLayer) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID, obj)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for AbortMultipartUpload arguments validity, also validates if bucket exists.
|
2023-08-17 12:37:55 -04:00
|
|
|
func checkAbortMultipartArgs(ctx context.Context, bucket, object, uploadID string, obj ObjectLayer) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID, obj)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// Checks Object arguments validity, also validates if bucket exists.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkObjectArgs(ctx context.Context, bucket, object string, obj ObjectLayer) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
// Verify if bucket exists before validating object name.
|
|
|
|
// This is done on purpose since the order of errors is
|
|
|
|
// important here bucket does not exist error should
|
|
|
|
// happen before we return an error for invalid object name.
|
|
|
|
// FIXME: should be moved to handler layer.
|
2018-04-05 18:04:40 -04:00
|
|
|
if err := checkBucketExist(ctx, bucket, obj); err != nil {
|
|
|
|
return err
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2019-07-12 00:38:12 -04:00
|
|
|
|
|
|
|
if err := checkObjectNameForLengthAndSlash(bucket, object); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-05 21:59:38 -05:00
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Validates object name validity after bucket exists.
|
|
|
|
if !IsValidObjectName(object) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2019-07-12 00:38:12 -04:00
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// Checks for PutObject arguments validity, also validates if bucket exists.
|
2020-10-06 15:03:57 -04:00
|
|
|
func checkPutObjectArgs(ctx context.Context, bucket, object string, obj getBucketInfoI) error {
|
2018-02-09 18:19:30 -05:00
|
|
|
// Verify if bucket exists before validating object name.
|
|
|
|
// This is done on purpose since the order of errors is
|
|
|
|
// important here bucket does not exist error should
|
|
|
|
// happen before we return an error for invalid object name.
|
|
|
|
// FIXME: should be moved to handler layer.
|
2018-04-05 18:04:40 -04:00
|
|
|
if err := checkBucketExist(ctx, bucket, obj); err != nil {
|
|
|
|
return err
|
2018-02-09 18:19:30 -05:00
|
|
|
}
|
|
|
|
|
2019-07-12 00:38:12 -04:00
|
|
|
if err := checkObjectNameForLengthAndSlash(bucket, object); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-09 18:19:30 -05:00
|
|
|
if len(object) == 0 ||
|
|
|
|
!IsValidObjectPrefix(object) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
}
|
2018-02-09 18:19:30 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-10 12:18:19 -04:00
|
|
|
type getBucketInfoI interface {
|
2022-07-25 20:51:32 -04:00
|
|
|
GetBucketInfo(ctx context.Context, bucket string, opts BucketOptions) (bucketInfo BucketInfo, err error)
|
2020-09-10 12:18:19 -04:00
|
|
|
}
|
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Checks whether bucket exists and returns appropriate error if not.
|
2020-09-10 12:18:19 -04:00
|
|
|
func checkBucketExist(ctx context.Context, bucket string, obj getBucketInfoI) error {
|
2022-07-25 20:51:32 -04:00
|
|
|
_, err := obj.GetBucketInfo(ctx, bucket, BucketOptions{})
|
2016-12-02 02:15:17 -05:00
|
|
|
if err != nil {
|
2018-04-10 12:36:37 -04:00
|
|
|
return err
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|