mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
admin: Return exported errors with invalid access secret keys (#12234)
To avoid returning 5xx error from MinIO server and show a better error message, we need to return ErrInvalidAccessKeyLength and ErrInvalidSecretKeyLength when attempting to create a new credentials with invalid access or secret keys. Signed-off-by: Anis Elleuch <anis@min.io> Co-authored-by: Anis Elleuch <anis@min.io>
This commit is contained in:
parent
26f1fcab7d
commit
b4f4cd1d5d
@ -57,8 +57,8 @@ const (
|
||||
|
||||
// Common errors generated for access and secret key validation.
|
||||
var (
|
||||
ErrInvalidAccessKeyLength = fmt.Errorf("access key must be minimum %v or more characters long", accessKeyMinLen)
|
||||
ErrInvalidSecretKeyLength = fmt.Errorf("secret key must be minimum %v or more characters long", secretKeyMinLen)
|
||||
ErrInvalidAccessKeyLength = fmt.Errorf("access key length should be between %d and %d", accessKeyMinLen, accessKeyMaxLen)
|
||||
ErrInvalidSecretKeyLength = fmt.Errorf("secret key length should be between %d and %d", secretKeyMinLen, secretKeyMaxLen)
|
||||
)
|
||||
|
||||
// IsAccessKeyValid - validate access key for right length.
|
||||
@ -230,11 +230,11 @@ func GetNewCredentialsWithMetadata(m map[string]interface{}, tokenSecret string)
|
||||
// and generate a session token if a secret token is provided.
|
||||
func CreateNewCredentialsWithMetadata(accessKey, secretKey string, m map[string]interface{}, tokenSecret string) (cred Credentials, err error) {
|
||||
if len(accessKey) < accessKeyMinLen || len(accessKey) > accessKeyMaxLen {
|
||||
return Credentials{}, fmt.Errorf("access key length should be between %d and %d", accessKeyMinLen, accessKeyMaxLen)
|
||||
return Credentials{}, ErrInvalidAccessKeyLength
|
||||
}
|
||||
|
||||
if len(secretKey) < secretKeyMinLen || len(secretKey) > secretKeyMaxLen {
|
||||
return Credentials{}, fmt.Errorf("secret key length should be between %d and %d", secretKeyMinLen, secretKeyMaxLen)
|
||||
return Credentials{}, ErrInvalidSecretKeyLength
|
||||
}
|
||||
|
||||
cred.AccessKey = accessKey
|
||||
|
Loading…
Reference in New Issue
Block a user