Skip to content

Commit

Permalink
Relax isValidBucketName to allow reading existing buckets. (#708)
Browse files Browse the repository at this point in the history
Add a stricter check for MakeBucket alone to avoid
creating newer buckets with capitalized letters.

Fixes minio/mc#2157
  • Loading branch information
harshavardhana authored Jun 19, 2017
1 parent b752793 commit 79aa9c3
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 149 deletions.
6 changes: 4 additions & 2 deletions api-get-object-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import (
"io"
"os"
"path/filepath"

"github.com/minio/minio-go/pkg/s3utils"
)

// FGetObject - download contents of an object to a local file.
func (c Client) FGetObject(bucketName, objectName, filePath string) error {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return err
}

Expand Down
9 changes: 5 additions & 4 deletions api-get-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/minio/minio-go/pkg/encrypt"
"github.com/minio/minio-go/pkg/s3utils"
)

// GetEncryptedObject deciphers and streams data stored in the server after applying a specifed encryption materials,
Expand Down Expand Up @@ -57,10 +58,10 @@ func (c Client) GetEncryptedObject(bucketName, objectName string, encryptMateria
// GetObject - returns an seekable, readable object.
func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return nil, err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return nil, err
}

Expand Down Expand Up @@ -627,10 +628,10 @@ func newObject(reqCh chan<- getRequest, resCh <-chan getResponse, doneCh chan<-
// go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
func (c Client) getObject(bucketName, objectName string, reqHeaders RequestHeaders) (io.ReadCloser, ObjectInfo, error) {
// Validate input arguments.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return nil, ObjectInfo{}, err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return nil, ObjectInfo{}, err
}

Expand Down
9 changes: 5 additions & 4 deletions api-get-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import (
"net/url"

"github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio-go/pkg/s3utils"
)

// GetBucketPolicy - get bucket policy at a given path.
func (c Client) GetBucketPolicy(bucketName, objectPrefix string) (bucketPolicy policy.BucketPolicy, err error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return policy.BucketPolicyNone, err
}
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
return policy.BucketPolicyNone, err
}
policyInfo, err := c.getBucketPolicy(bucketName)
Expand All @@ -48,10 +49,10 @@ func (c Client) GetBucketPolicy(bucketName, objectPrefix string) (bucketPolicy p
// ListBucketPolicies - list all policies for a given prefix and all its children.
func (c Client) ListBucketPolicies(bucketName, objectPrefix string) (bucketPolicies map[string]policy.BucketPolicy, err error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return map[string]policy.BucketPolicy{}, err
}
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
return map[string]policy.BucketPolicy{}, err
}
policyInfo, err := c.getBucketPolicy(bucketName)
Expand Down
22 changes: 12 additions & 10 deletions api-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"net/http"
"net/url"
"strings"

"github.com/minio/minio-go/pkg/s3utils"
)

// ListBuckets list all buckets owned by this authenticated user.
Expand Down Expand Up @@ -87,15 +89,15 @@ func (c Client) ListObjectsV2(bucketName, objectPrefix string, recursive bool, d
// Return object owner information by default
fetchOwner := true
// Validate bucket name.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
defer close(objectStatCh)
objectStatCh <- ObjectInfo{
Err: err,
}
return objectStatCh
}
// Validate incoming object prefix.
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
defer close(objectStatCh)
objectStatCh <- ObjectInfo{
Err: err,
Expand Down Expand Up @@ -170,11 +172,11 @@ func (c Client) ListObjectsV2(bucketName, objectPrefix string, recursive bool, d
// ?max-keys - Sets the maximum number of keys returned in the response body.
func (c Client) listObjectsV2Query(bucketName, objectPrefix, continuationToken string, fetchOwner bool, delimiter string, maxkeys int) (ListBucketV2Result, error) {
// Validate bucket name.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ListBucketV2Result{}, err
}
// Validate object prefix.
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
return ListBucketV2Result{}, err
}
// Get resources properly escaped and lined up before
Expand Down Expand Up @@ -266,15 +268,15 @@ func (c Client) ListObjects(bucketName, objectPrefix string, recursive bool, don
delimiter = ""
}
// Validate bucket name.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
defer close(objectStatCh)
objectStatCh <- ObjectInfo{
Err: err,
}
return objectStatCh
}
// Validate incoming object prefix.
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
defer close(objectStatCh)
objectStatCh <- ObjectInfo{
Err: err,
Expand Down Expand Up @@ -350,11 +352,11 @@ func (c Client) ListObjects(bucketName, objectPrefix string, recursive bool, don
// ?max-keys - Sets the maximum number of keys returned in the response body.
func (c Client) listObjectsQuery(bucketName, objectPrefix, objectMarker, delimiter string, maxkeys int) (ListBucketResult, error) {
// Validate bucket name.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ListBucketResult{}, err
}
// Validate object prefix.
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
return ListBucketResult{}, err
}
// Get resources properly escaped and lined up before
Expand Down Expand Up @@ -442,15 +444,15 @@ func (c Client) listIncompleteUploads(bucketName, objectPrefix string, recursive
delimiter = ""
}
// Validate bucket name.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
defer close(objectMultipartStatCh)
objectMultipartStatCh <- ObjectMultipartInfo{
Err: err,
}
return objectMultipartStatCh
}
// Validate incoming object prefix.
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
defer close(objectMultipartStatCh)
objectMultipartStatCh <- ObjectMultipartInfo{
Err: err,
Expand Down
4 changes: 2 additions & 2 deletions api-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// GetBucketNotification - get bucket notification at a given path.
func (c Client) GetBucketNotification(bucketName string) (bucketNotification BucketNotification, err error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return BucketNotification{}, err
}
notification, err := c.getBucketNotification(bucketName)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, even
defer close(notificationInfoCh)

// Validate the bucket name.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
notificationInfoCh <- NotificationInfo{
Err: err,
}
Expand Down
4 changes: 2 additions & 2 deletions api-presigned.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (c Client) presignURL(method string, bucketName string, objectName string,
if method == "" {
return nil, ErrInvalidArgument("method cannot be empty.")
}
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return nil, err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return nil, err
}
if err := isValidExpiry(expires); err != nil {
Expand Down
24 changes: 7 additions & 17 deletions api-put-bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/url"

"github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio-go/pkg/s3utils"
)

/// Bucket operations
Expand All @@ -46,7 +47,7 @@ func (c Client) MakeBucket(bucketName string, location string) (err error) {
}()

// Validate the input arguments.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketNameStrict(bucketName); err != nil {
return err
}

Expand All @@ -59,17 +60,6 @@ func (c Client) MakeBucket(bucketName string, location string) (err error) {
location = c.region
}
}

// Try creating bucket with the provided region, in case of
// invalid region error let's guess the appropriate region
// from S3 API headers

// Create a done channel to control 'newRetryTimer' go routine.
doneCh := make(chan struct{}, 1)

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)

// PUT bucket request metadata.
reqMetadata := requestMetadata{
bucketName: bucketName,
Expand Down Expand Up @@ -118,10 +108,10 @@ func (c Client) MakeBucket(bucketName string, location string) (err error) {
// writeonly - anonymous put/delete access to a given object prefix.
func (c Client) SetBucketPolicy(bucketName string, objectPrefix string, bucketPolicy policy.BucketPolicy) error {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
}
if err := isValidObjectPrefix(objectPrefix); err != nil {
if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil {
return err
}

Expand Down Expand Up @@ -150,7 +140,7 @@ func (c Client) SetBucketPolicy(bucketName string, objectPrefix string, bucketPo
// Saves a new bucket policy.
func (c Client) putBucketPolicy(bucketName string, policyInfo policy.BucketAccessPolicy) error {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
}

Expand Down Expand Up @@ -196,7 +186,7 @@ func (c Client) putBucketPolicy(bucketName string, policyInfo policy.BucketAcces
// Removes all policies on a bucket.
func (c Client) removeBucketPolicy(bucketName string) error {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
}
// Get resources properly escaped and lined up before
Expand All @@ -220,7 +210,7 @@ func (c Client) removeBucketPolicy(bucketName string) error {
// SetBucketNotification saves a new bucket notification.
func (c Client) SetBucketNotification(bucketName string, bucketNotification BucketNotification) error {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions api-put-object-common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"io/ioutil"
"math"
"os"

"github.com/minio/minio-go/pkg/s3utils"
)

// Verify if reader is *os.File
Expand Down Expand Up @@ -168,10 +170,10 @@ func hashCopyN(hashAlgorithms map[string]hash.Hash, hashSums map[string][]byte,
// or initiate a new request to fetch a new upload id.
func (c Client) newUploadID(bucketName, objectName string, metaData map[string][]string) (uploadID string, err error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return "", err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return "", err
}

Expand Down
4 changes: 2 additions & 2 deletions api-put-object-copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
// CopyObject - copy a source object into a new object with the provided name in the provided bucket
func (c Client) CopyObject(bucketName string, objectName string, objectSource string, cpCond CopyConditions) error {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return err
}
if objectSource == "" {
Expand Down
8 changes: 4 additions & 4 deletions api-put-object-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import (
// FPutObject - Create an object in a bucket, with contents from file at filePath.
func (c Client) FPutObject(bucketName, objectName, filePath, contentType string) (n int64, err error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return 0, err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return 0, err
}

Expand Down Expand Up @@ -116,10 +116,10 @@ func (c Client) FPutObject(bucketName, objectName, filePath, contentType string)
// specific sections and not having to create temporary files.
func (c Client) putObjectMultipartFromFile(bucketName, objectName string, fileReader io.ReaderAt, fileSize int64, metaData map[string][]string, progress io.Reader) (int64, error) {
// Input validation.
if err := isValidBucketName(bucketName); err != nil {
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return 0, err
}
if err := isValidObjectName(objectName); err != nil {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return 0, err
}

Expand Down
Loading

0 comments on commit 79aa9c3

Please sign in to comment.