mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
Removes max limit requirement on accessKey and secretKey length (#4730)
This commit is contained in:
parent
108decfa76
commit
0f401b67ad
@ -29,6 +29,7 @@ const (
|
|||||||
accessKeyMinLen = 5
|
accessKeyMinLen = 5
|
||||||
|
|
||||||
// Maximum length for Minio access key.
|
// Maximum length for Minio access key.
|
||||||
|
// There is no max length enforcement for access keys
|
||||||
accessKeyMaxLen = 20
|
accessKeyMaxLen = 20
|
||||||
|
|
||||||
// Minimum length for Minio secret key for both server and gateway mode.
|
// Minimum length for Minio secret key for both server and gateway mode.
|
||||||
@ -36,11 +37,8 @@ const (
|
|||||||
|
|
||||||
// Maximum secret key length for Minio, this
|
// Maximum secret key length for Minio, this
|
||||||
// is used when autogenerating new credentials.
|
// is used when autogenerating new credentials.
|
||||||
secretKeyMaxLenMinio = 40
|
// There is no max length enforcement for secret keys
|
||||||
|
secretKeyMaxLen = 40
|
||||||
// Maximum secret key length allowed from client side
|
|
||||||
// caters for both server and gateway mode.
|
|
||||||
secretKeyMaxLen = 100
|
|
||||||
|
|
||||||
// Alpha numeric table used for generating access keys.
|
// Alpha numeric table used for generating access keys.
|
||||||
alphaNumericTable = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
alphaNumericTable = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
@ -51,18 +49,18 @@ const (
|
|||||||
|
|
||||||
// Common errors generated for access and secret key validation.
|
// Common errors generated for access and secret key validation.
|
||||||
var (
|
var (
|
||||||
errInvalidAccessKeyLength = errors.New("Invalid access key, access key should be 5 to 20 characters in length")
|
errInvalidAccessKeyLength = errors.New("Invalid access key, access key should be minimum 5 characters in length")
|
||||||
errInvalidSecretKeyLength = errors.New("Invalid secret key, secret key should be 8 to 100 characters in length")
|
errInvalidSecretKeyLength = errors.New("Invalid secret key, secret key should be minimum 8 characters in length")
|
||||||
)
|
)
|
||||||
|
|
||||||
// isAccessKeyValid - validate access key for right length.
|
// isAccessKeyValid - validate access key for right length.
|
||||||
func isAccessKeyValid(accessKey string) bool {
|
func isAccessKeyValid(accessKey string) bool {
|
||||||
return len(accessKey) >= accessKeyMinLen && len(accessKey) <= accessKeyMaxLen
|
return len(accessKey) >= accessKeyMinLen
|
||||||
}
|
}
|
||||||
|
|
||||||
// isSecretKeyValid - validate secret key for right length.
|
// isSecretKeyValid - validate secret key for right length.
|
||||||
func isSecretKeyValid(secretKey string) bool {
|
func isSecretKeyValid(secretKey string) bool {
|
||||||
return len(secretKey) >= secretKeyMinLen && len(secretKey) <= secretKeyMaxLen
|
return len(secretKey) >= secretKeyMinLen
|
||||||
}
|
}
|
||||||
|
|
||||||
// credential container for access and secret keys.
|
// credential container for access and secret keys.
|
||||||
@ -116,24 +114,35 @@ func createCredential(accessKey, secretKey string) (cred credential, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a new credential object
|
// Initialize a new credential object
|
||||||
func mustGetNewCredential() credential {
|
func getNewCredential(accessKeyLen, secretKeyLen int) (cred credential, err error) {
|
||||||
// Generate access key.
|
// Generate access key.
|
||||||
keyBytes := make([]byte, accessKeyMaxLen)
|
keyBytes := make([]byte, accessKeyLen)
|
||||||
_, err := rand.Read(keyBytes)
|
_, err = rand.Read(keyBytes)
|
||||||
fatalIf(err, "Unable to generate access key.")
|
if err != nil {
|
||||||
for i := 0; i < accessKeyMaxLen; i++ {
|
return cred, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < accessKeyLen; i++ {
|
||||||
keyBytes[i] = alphaNumericTable[keyBytes[i]%alphaNumericTableLen]
|
keyBytes[i] = alphaNumericTable[keyBytes[i]%alphaNumericTableLen]
|
||||||
}
|
}
|
||||||
accessKey := string(keyBytes)
|
accessKey := string(keyBytes)
|
||||||
|
|
||||||
// Generate secret key.
|
// Generate secret key.
|
||||||
keyBytes = make([]byte, secretKeyMaxLenMinio)
|
keyBytes = make([]byte, secretKeyLen)
|
||||||
_, err = rand.Read(keyBytes)
|
_, err = rand.Read(keyBytes)
|
||||||
fatalIf(err, "Unable to generate secret key.")
|
if err != nil {
|
||||||
secretKey := string([]byte(base64.StdEncoding.EncodeToString(keyBytes))[:secretKeyMaxLenMinio])
|
return cred, err
|
||||||
|
}
|
||||||
|
|
||||||
cred, err := createCredential(accessKey, secretKey)
|
secretKey := string([]byte(base64.StdEncoding.EncodeToString(keyBytes))[:secretKeyLen])
|
||||||
fatalIf(err, "Unable to generate new credential.")
|
cred, err = createCredential(accessKey, secretKey)
|
||||||
|
|
||||||
|
return cred, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustGetNewCredential() credential {
|
||||||
|
// Generate Minio credentials with Minio key max lengths.
|
||||||
|
cred, err := getNewCredential(accessKeyMaxLen, secretKeyMaxLen)
|
||||||
|
fatalIf(err, "Unable to generate new credentials.")
|
||||||
return cred
|
return cred
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ func TestMustGetNewCredential(t *testing.T) {
|
|||||||
if !cred.IsValid() {
|
if !cred.IsValid() {
|
||||||
t.Fatalf("Failed to get new valid credential")
|
t.Fatalf("Failed to get new valid credential")
|
||||||
}
|
}
|
||||||
if len(cred.SecretKey) != secretKeyMaxLenMinio {
|
if len(cred.SecretKey) != secretKeyMaxLen {
|
||||||
t.Fatalf("Invalid length %d of the secretKey credential generated, expected %d", len(cred.SecretKey), secretKeyMaxLenMinio)
|
t.Fatalf("Invalid length %d of the secretKey credential generated, expected %d", len(cred.SecretKey), secretKeyMaxLen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,18 +36,14 @@ func TestCreateCredential(t *testing.T) {
|
|||||||
expectedResult bool
|
expectedResult bool
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
// Access key too small.
|
// Access key too small (min 5 chars).
|
||||||
{"user", "pass", false, errInvalidAccessKeyLength},
|
{"user", "pass", false, errInvalidAccessKeyLength},
|
||||||
// Access key too long.
|
// Long access key is ok.
|
||||||
{"user12345678901234567", "pass", false, errInvalidAccessKeyLength},
|
{"user123456789012345678901234567890", "password", true, nil},
|
||||||
// Access key contains unsuppported characters.
|
// Secret key too small (min 8 chars).
|
||||||
{"!@#$", "pass", false, errInvalidAccessKeyLength},
|
|
||||||
// Secret key too small.
|
|
||||||
{"myuser", "pass", false, errInvalidSecretKeyLength},
|
{"myuser", "pass", false, errInvalidSecretKeyLength},
|
||||||
// Secret key too long.
|
// Long secret key is ok.
|
||||||
{"myuser", "pass1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", false, errInvalidSecretKeyLength},
|
{"myuser", "pass1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", true, nil},
|
||||||
// Success when access key contains leading/trailing spaces.
|
|
||||||
{" user ", cred.SecretKey, true, nil},
|
|
||||||
{"myuser", "mypassword", true, nil},
|
{"myuser", "mypassword", true, nil},
|
||||||
{cred.AccessKey, cred.SecretKey, true, nil},
|
{cred.AccessKey, cred.SecretKey, true, nil},
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,12 @@ func testAuthenticate(authType string, t *testing.T) {
|
|||||||
t.Fatalf("unable initialize config file, %s", err)
|
t.Fatalf("unable initialize config file, %s", err)
|
||||||
}
|
}
|
||||||
defer removeAll(testPath)
|
defer removeAll(testPath)
|
||||||
|
// Create access and secret keys in length, 300 and 600
|
||||||
serverCred := serverConfig.GetCredential()
|
cred, err := getNewCredential(300, 600)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to get new credential, %v", err)
|
||||||
|
}
|
||||||
|
serverConfig.SetCredential(cred)
|
||||||
|
|
||||||
// Define test cases.
|
// Define test cases.
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -33,24 +37,16 @@ func testAuthenticate(authType string, t *testing.T) {
|
|||||||
secretKey string
|
secretKey string
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
// Access key too small.
|
// Access key (less than 5 chrs) too small.
|
||||||
{"user", "pass", errInvalidAccessKeyLength},
|
{"user", cred.SecretKey, errInvalidAccessKeyLength},
|
||||||
// Access key too long.
|
// Secret key (less than 8 chrs) too small.
|
||||||
{"user12345678901234567", "pass", errInvalidAccessKeyLength},
|
{cred.AccessKey, "pass", errInvalidSecretKeyLength},
|
||||||
// Access key contains unsuppported characters.
|
|
||||||
{"!@#$", "pass", errInvalidAccessKeyLength},
|
|
||||||
// Success when access key contains leading/trailing spaces.
|
|
||||||
{" " + serverCred.AccessKey + " ", serverCred.SecretKey, errInvalidAccessKeyLength},
|
|
||||||
// Secret key too small.
|
|
||||||
{"myuser", "pass", errInvalidSecretKeyLength},
|
|
||||||
// Secret key too long.
|
|
||||||
{"myuser", "pass1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", errInvalidSecretKeyLength},
|
|
||||||
// Authentication error.
|
// Authentication error.
|
||||||
{"myuser", "mypassword", errInvalidAccessKeyID},
|
{"myuser", "mypassword", errInvalidAccessKeyID},
|
||||||
// Authentication error.
|
// Authentication error.
|
||||||
{serverCred.AccessKey, "mypassword", errAuthentication},
|
{cred.AccessKey, "mypassword", errAuthentication},
|
||||||
// Success.
|
// Success.
|
||||||
{serverCred.AccessKey, serverCred.SecretKey, nil},
|
{cred.AccessKey, cred.SecretKey, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run tests.
|
// Run tests.
|
||||||
|
@ -52,8 +52,8 @@ FLAGS:
|
|||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
ENVIRONMENT VARIABLES:
|
ENVIRONMENT VARIABLES:
|
||||||
ACCESS:
|
ACCESS:
|
||||||
MINIO_ACCESS_KEY: Custom username or access key of 5 to 20 characters in length.
|
MINIO_ACCESS_KEY: Custom username or access key of minimum 5 characters in length.
|
||||||
MINIO_SECRET_KEY: Custom password or secret key of 8 to 40 characters in length.
|
MINIO_SECRET_KEY: Custom password or secret key of minimum 8 characters in length.
|
||||||
|
|
||||||
BROWSER:
|
BROWSER:
|
||||||
MINIO_BROWSER: To disable web browser access, set this value to "off".
|
MINIO_BROWSER: To disable web browser access, set this value to "off".
|
||||||
|
@ -34,8 +34,8 @@ $ tree ~/.minio
|
|||||||
|Field|Type|Description|
|
|Field|Type|Description|
|
||||||
|:---|:---|:---|
|
|:---|:---|:---|
|
||||||
|``credential``| | Auth credential for object storage and web access.|
|
|``credential``| | Auth credential for object storage and web access.|
|
||||||
|``credential.accessKey`` | _string_ | Access key of 5 to 20 characters in length. You may override this field with `MINIO_ACCESS_KEY` environment variable.|
|
|``credential.accessKey`` | _string_ | Access key of minimum 5 characters in length. You may override this field with `MINIO_ACCESS_KEY` environment variable.|
|
||||||
|``credential.secretKey`` | _string_ | Secret key of 8 to 40 characters in length. You may override this field with `MINIO_SECRET_KEY` environment variable.|
|
|``credential.secretKey`` | _string_ | Secret key of minimum 8 characters in length. You may override this field with `MINIO_SECRET_KEY` environment variable.|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user