diff --git a/common-methods.go b/common-methods.go index 62a539e2..3e1744ed 100644 --- a/common-methods.go +++ b/common-methods.go @@ -23,6 +23,7 @@ import ( "runtime" "strings" + "github.com/minio/mc/pkg/console" "github.com/minio/minio/pkg/probe" ) @@ -113,8 +114,32 @@ func newClientFromAlias(alias string, urlStr string) (Client, *probe.Error) { // We have a valid alias and hostConfig. We populate the // credentials from the match found in the config file. s3Config := new(Config) - s3Config.AccessKey = hostCfg.AccessKey - s3Config.SecretKey = hostCfg.SecretKey + + // secretKey retrieved from the environement overrides the one + // present in the config file + keysPairEnv := os.Getenv("MC_SECRET_" + alias) + keysPairArray := strings.Split(keysPairEnv, ":") + var accessKeyEnv, secretKeyEnv string + if len(keysPairArray) >= 1 { + accessKeyEnv = keysPairArray[0] + } + if len(keysPairArray) >= 2 { + secretKeyEnv = keysPairArray[1] + } + if len(keysPairEnv) > 0 && + isValidAccessKey(accessKeyEnv) && isValidSecretKey(secretKeyEnv) { + s3Config.AccessKey = accessKeyEnv + s3Config.SecretKey = secretKeyEnv + } else { + if len(keysPairEnv) > 0 { + console.Errorln("Access/Secret keys associated to `" + alias + "' " + + "are found in your environment but not suitable for use. " + + "Falling back to the standard config.") + } + s3Config.AccessKey = hostCfg.AccessKey + s3Config.SecretKey = hostCfg.SecretKey + } + s3Config.Signature = hostCfg.API s3Config.AppName = "mc" s3Config.AppVersion = mcVersion