diff --git a/pkg/auth/credentials.go b/pkg/auth/credentials.go index 5e4b5c867..bba029fe6 100644 --- a/pkg/auth/credentials.go +++ b/pkg/auth/credentials.go @@ -61,8 +61,8 @@ func IsAccessKeyValid(accessKey string) bool { return len(accessKey) >= accessKeyMinLen } -// isSecretKeyValid - validate secret key for right length. -func isSecretKeyValid(secretKey string) bool { +// IsSecretKeyValid - validate secret key for right length. +func IsSecretKeyValid(secretKey string) bool { return len(secretKey) >= secretKeyMinLen } @@ -88,7 +88,7 @@ func (cred Credentials) IsExpired() bool { func (cred Credentials) IsValid() bool { // Verify credentials if its enabled or not set. if cred.Status == "enabled" || cred.Status == "" { - return IsAccessKeyValid(cred.AccessKey) && isSecretKeyValid(cred.SecretKey) && !cred.IsExpired() + return IsAccessKeyValid(cred.AccessKey) && IsSecretKeyValid(cred.SecretKey) && !cred.IsExpired() } return false } @@ -164,7 +164,7 @@ func CreateCredentials(accessKey, secretKey string) (cred Credentials, err error if !IsAccessKeyValid(accessKey) { return cred, ErrInvalidAccessKeyLength } - if !isSecretKeyValid(secretKey) { + if !IsSecretKeyValid(secretKey) { return cred, ErrInvalidSecretKeyLength } cred.AccessKey = accessKey diff --git a/pkg/auth/credentials_test.go b/pkg/auth/credentials_test.go index ce542ce65..e96160472 100644 --- a/pkg/auth/credentials_test.go +++ b/pkg/auth/credentials_test.go @@ -47,7 +47,7 @@ func TestIsSecretKeyValid(t *testing.T) { } for i, testCase := range testCases { - result := isSecretKeyValid(testCase.secretKey) + result := IsSecretKeyValid(testCase.secretKey) if result != testCase.expectedResult { t.Fatalf("test %v: expected: %v, got: %v", i+1, testCase.expectedResult, result) } diff --git a/pkg/madmin/user-commands.go b/pkg/madmin/user-commands.go index a413f7d69..336e905ff 100644 --- a/pkg/madmin/user-commands.go +++ b/pkg/madmin/user-commands.go @@ -21,6 +21,8 @@ import ( "encoding/json" "net/http" "net/url" + + "github.com/minio/minio/pkg/auth" ) // AccountStatus - account status. @@ -97,6 +99,15 @@ func (adm *AdminClient) ListUsers() (map[string]UserInfo, error) { // SetUser - sets a user info. func (adm *AdminClient) SetUser(accessKey, secretKey string, status AccountStatus) error { + + if !auth.IsAccessKeyValid(accessKey) { + return auth.ErrInvalidAccessKeyLength + } + + if !auth.IsSecretKeyValid(secretKey) { + return auth.ErrInvalidSecretKeyLength + } + data, err := json.Marshal(UserInfo{ SecretKey: secretKey, Status: status,