mirror of
https://github.com/minio/minio.git
synced 2025-04-20 02:27:50 -04:00
creds: Secretkey should be generated upto 40 characters in length. (#4471)
Current code allowed it wrongly to generate secret key upto 100 we should only use 100 as a value to validate but for generating it should be 40. Fixes #4470
This commit is contained in:
parent
986aa8fabf
commit
1c3f244fc5
@ -25,19 +25,35 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Minimum length for Minio access key.
|
||||||
accessKeyMinLen = 5
|
accessKeyMinLen = 5
|
||||||
|
|
||||||
|
// Maximum length for Minio access key.
|
||||||
accessKeyMaxLen = 20
|
accessKeyMaxLen = 20
|
||||||
|
|
||||||
|
// Minimum length for Minio secret key for both server and gateway mode.
|
||||||
secretKeyMinLen = 8
|
secretKeyMinLen = 8
|
||||||
secretKeyMaxLenAmazon = 100
|
|
||||||
|
// Maximum secret key length for Minio, this
|
||||||
|
// is used when autogenerating new credentials.
|
||||||
|
secretKeyMaxLenMinio = 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.
|
||||||
alphaNumericTable = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
alphaNumericTable = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
|
// Total length of the alpha numeric table.
|
||||||
alphaNumericTableLen = byte(len(alphaNumericTable))
|
alphaNumericTableLen = byte(len(alphaNumericTable))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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 5 to 20 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 8 to 100 characters in length")
|
||||||
)
|
)
|
||||||
var secretKeyMaxLen = secretKeyMaxLenAmazon
|
|
||||||
|
|
||||||
// isAccessKeyValid - validate access key for right length.
|
// isAccessKeyValid - validate access key for right length.
|
||||||
func isAccessKeyValid(accessKey string) bool {
|
func isAccessKeyValid(accessKey string) bool {
|
||||||
@ -111,10 +127,10 @@ func mustGetNewCredential() credential {
|
|||||||
accessKey := string(keyBytes)
|
accessKey := string(keyBytes)
|
||||||
|
|
||||||
// Generate secret key.
|
// Generate secret key.
|
||||||
keyBytes = make([]byte, secretKeyMaxLen)
|
keyBytes = make([]byte, secretKeyMaxLenMinio)
|
||||||
_, err = rand.Read(keyBytes)
|
_, err = rand.Read(keyBytes)
|
||||||
fatalIf(err, "Unable to generate secret key.")
|
fatalIf(err, "Unable to generate secret key.")
|
||||||
secretKey := string([]byte(base64.StdEncoding.EncodeToString(keyBytes))[:secretKeyMaxLen])
|
secretKey := string([]byte(base64.StdEncoding.EncodeToString(keyBytes))[:secretKeyMaxLenMinio])
|
||||||
|
|
||||||
cred, err := createCredential(accessKey, secretKey)
|
cred, err := createCredential(accessKey, secretKey)
|
||||||
fatalIf(err, "Unable to generate new credential.")
|
fatalIf(err, "Unable to generate new credential.")
|
||||||
|
@ -23,6 +23,9 @@ 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 {
|
||||||
|
t.Fatalf("Invalid length %d of the secretKey credential generated, expected %d", len(cred.SecretKey), secretKeyMaxLenMinio)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateCredential(t *testing.T) {
|
func TestCreateCredential(t *testing.T) {
|
||||||
|
@ -19,11 +19,12 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/minio/cli"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/minio/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gatewayTemplate = `NAME:
|
var gatewayTemplate = `NAME:
|
||||||
|
@ -93,13 +93,6 @@ func (s *TestSuiteCommon) TearDownSuite(c *C) {
|
|||||||
s.testServer.Stop()
|
s.testServer.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TestSuiteCommon) TestAuth(c *C) {
|
|
||||||
cred := mustGetNewCredential()
|
|
||||||
|
|
||||||
c.Assert(len(cred.AccessKey), Equals, accessKeyMaxLen)
|
|
||||||
c.Assert(len(cred.SecretKey), Equals, secretKeyMaxLen)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TestSuiteCommon) TestBucketSQSNotificationWebHook(c *C) {
|
func (s *TestSuiteCommon) TestBucketSQSNotificationWebHook(c *C) {
|
||||||
// Sample bucket notification.
|
// Sample bucket notification.
|
||||||
bucketNotificationBuf := `<NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>images/</Value></FilterRule></S3Key></Filter><Id>1</Id><Queue>arn:minio:sqs:us-east-1:444455556666:webhook</Queue></QueueConfiguration></NotificationConfiguration>`
|
bucketNotificationBuf := `<NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>images/</Value></FilterRule></S3Key></Filter><Id>1</Id><Queue>arn:minio:sqs:us-east-1:444455556666:webhook</Queue></QueueConfiguration></NotificationConfiguration>`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user