diff --git a/cmd-access.go b/cmd-access.go index 1166b11a..ff2f1f87 100644 --- a/cmd-access.go +++ b/cmd-access.go @@ -31,7 +31,9 @@ func runAccessCmd(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code } - + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-cat.go b/cmd-cat.go index e7bdb28e..1c2f0d1c 100644 --- a/cmd-cat.go +++ b/cmd-cat.go @@ -34,6 +34,9 @@ func runCatCmd(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code } + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-cp.go b/cmd-cp.go index cca3a5ba..ec6f91a6 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -29,7 +29,9 @@ func runCopyCmd(ctx *cli.Context) { if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code } - + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-ls.go b/cmd-ls.go index 7f50cdbc..4944d0a4 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -32,6 +32,9 @@ func runListCmd(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code } + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-mb.go b/cmd-mb.go index a6900b51..1dc1a5b8 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -32,6 +32,9 @@ func runMakeBucketCmd(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code } + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-options.go b/cmd-options.go index 7f9cbb81..21297044 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -265,14 +265,14 @@ EXAMPLES: USAGE: mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} check - mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} yes + mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} install EXAMPLES: 1. Check for new updates $ mc update check 2. Download new minio client locally and update - $ mc update yes + $ mc update install `, } diff --git a/cmd-sync.go b/cmd-sync.go index dfac6f8e..beca59b8 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -29,6 +29,9 @@ func runSyncCmd(ctx *cli.Context) { if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code } + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) diff --git a/cmd-update.go b/cmd-update.go index edfa5417..2e8b195d 100644 --- a/cmd-update.go +++ b/cmd-update.go @@ -19,6 +19,7 @@ package main import ( "errors" "fmt" + "runtime" "time" "encoding/json" @@ -31,7 +32,7 @@ import ( ) const ( - mcUpdateURL = "http://dl.minio.io/updates/mc.json" + mcUpdateURL = "http://dl.minio.io:9000/binaries/" ) type updateResults struct { @@ -56,17 +57,21 @@ func runUpdateCmd(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code } + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } + mcUpdateBinaryURL := mcUpdateURL + runtime.GOOS + "/mc" switch ctx.Args().First() { case "check": - req, err := getRequest(mcUpdateURL) + req, err := getRequest(mcUpdateBinaryURL) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("Unable to update:", mcUpdateURL) + console.Fatalln("Unable to update:", mcUpdateBinaryURL) } res, err := http.DefaultTransport.RoundTrip(req) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("Unable to retrieve:", mcUpdateURL) + console.Fatalln("Unable to retrieve:", mcUpdateBinaryURL) } if res.StatusCode != http.StatusOK { msg := fmt.Sprint("Received invalid HTTP status: ", res.StatusCode) @@ -91,7 +96,7 @@ func runUpdateCmd(ctx *cli.Context) { if latest.After(current) { printUpdateNotify("new", "old") } - case "yes": + case "install": console.Fatalln("Functionality not implemented yet") } } diff --git a/config.go b/config.go index ab8bbe00..f41cd9aa 100644 --- a/config.go +++ b/config.go @@ -138,8 +138,8 @@ func newConfigV1() *configV1 { func newConfig() (config quick.Config) { conf := newConfigV1() s3HostConf := new(hostConfig) - s3HostConf.AccessKeyID = globalAccessKeyID - s3HostConf.SecretAccessKey = globalSecretAccessKey + s3HostConf.AccessKeyID = "" + s3HostConf.SecretAccessKey = "" playHostConfig := new(hostConfig) playHostConfig.AccessKeyID = "" diff --git a/hostconfig.go b/hostconfig.go index 49ceef97..46e04694 100644 --- a/hostconfig.go +++ b/hostconfig.go @@ -82,12 +82,6 @@ func getHostConfig(requestURL string) (*hostConfig, error) { if hostCfg == nil { return nil, iodine.New(errInvalidAuth{}, nil) } - // verify Auth key validity for all hosts - if hostCfg.AccessKeyID != globalAccessKeyID && hostCfg.SecretAccessKey != globalSecretAccessKey { - if !client.IsValidAccessKey(hostCfg.AccessKeyID) || !client.IsValidSecretKey(hostCfg.SecretAccessKey) { - return nil, iodine.New(errInvalidAuthKeys{}, nil) - } - } return hostCfg, nil } } diff --git a/pkg/client/s3/bucket.go b/pkg/client/s3/bucket.go index 029bc1b7..5e7a9ce0 100644 --- a/pkg/client/s3/bucket.go +++ b/pkg/client/s3/bucket.go @@ -58,9 +58,16 @@ func (c *s3Client) listBucketsInternal() ([]*client.Item, error) { if err != nil { return nil, iodine.New(err, nil) } - if c.AccessKeyID != "" && c.SecretAccessKey != "" { - c.signRequest(req, c.Host) + + // do not ignore signatures for 'listBuckets()' + // it is never a public request, + // + // so lets aggressively verify + if c.AccessKeyID == "" || c.SecretAccessKey == "" { + msg := "Authorization key cannot be empty for listing buckets, please choose a valid bucketname if its a public request" + return nil, iodine.New(errors.New(msg), nil) } + c.signRequest(req, c.Host) res, err = c.Transport.RoundTrip(req) if err != nil { diff --git a/pkg/client/s3/bucket_list.go b/pkg/client/s3/bucket_list.go index 54134a65..aec4921b 100644 --- a/pkg/client/s3/bucket_list.go +++ b/pkg/client/s3/bucket_list.go @@ -25,6 +25,7 @@ import ( "net/http" "net/url" "os" + "strings" "time" "github.com/minio-io/mc/pkg/client" @@ -142,8 +143,22 @@ func (c *s3Client) listRecursive(itemCh chan client.ItemOnChannel) { } } +func (c *s3Client) isValidQueryURL(queryURL string) bool { + u, err := url.Parse(queryURL) + if err != nil { + return false + } + if !strings.Contains(u.Scheme, "http") { + return false + } + return true +} + // populate s3 response and decode results into listBucketResults{} func (c *s3Client) decodeBucketResults(queryURL string) (*listBucketResults, error) { + if !c.isValidQueryURL(queryURL) { + return nil, iodine.New(InvalidQueryURL{URL: queryURL}, nil) + } bres := &listBucketResults{} req, err := c.newRequest("GET", queryURL, nil) if err != nil { diff --git a/pkg/client/s3/client.go b/pkg/client/s3/client.go index 2010c354..d2812865 100644 --- a/pkg/client/s3/client.go +++ b/pkg/client/s3/client.go @@ -111,8 +111,15 @@ func (c *s3Client) url2BucketAndObject() (bucketName, objectName string) { // storage implementation. func (c *s3Client) bucketURL(bucket string) string { var url string - // TODO: Bucket names can contain ".". This second check should be removed. - // when minio server supports buckets with "." + // Avoid bucket names with "." in them + // Citing - http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html + // + // ===================== + // When using virtual hosted–style buckets with SSL, the SSL wild card certificate + // only matches buckets that do not contain periods. To work around this, use HTTP + // or write your own certificate verification logic. + // ===================== + // if client.IsValidBucketName(bucket) && !strings.Contains(bucket, ".") { // if localhost use PathStyle if strings.Contains(c.Host, "localhost") || strings.Contains(c.Host, "127.0.0.1") { diff --git a/pkg/client/s3/errors.go b/pkg/client/s3/errors.go index 84dcd8f9..2c2887af 100644 --- a/pkg/client/s3/errors.go +++ b/pkg/client/s3/errors.go @@ -103,11 +103,13 @@ func (e InvalidAuthorizationKey) Error() string { return e.Err.Error() } -// AuthorizationKeyEmpty - empty auth key provided -type AuthorizationKeyEmpty GenericError +// InvalidQueryURL - generic error +type InvalidQueryURL struct { + URL string +} -func (e AuthorizationKeyEmpty) Error() string { - return e.Err.Error() +func (e InvalidQueryURL) Error() string { + return "Invalid query URL: " + e.URL } /* **** SAMPLE ERROR RESPONSE ****