forked from noobaa/noobaa-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added complexity check for accessKeys before making RPC call
Signed-off-by: Aayush Chouhan <[email protected]>
- Loading branch information
1 parent
816aedf
commit e62ebc2
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package noobaaaccount | |
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
"time" | ||
|
||
nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1" | ||
|
@@ -411,6 +412,9 @@ func RunCredentials(cmd *cobra.Command, args []string) { | |
log.Fatalf(`❌ access_key and secret_key flags must be provided`) | ||
} | ||
|
||
// validating access_keys complexity | ||
ValidateAccessKeys(accessKeys) | ||
|
||
if !util.KubeCheck(noobaaAccount) && (name != "[email protected]") { | ||
err := UpdateNonCrdAccountKeys(name, accessKeys) | ||
if err != nil { | ||
|
@@ -852,6 +856,59 @@ func UpdateNonCrdAccountKeys(name string, accessKeys nb.S3AccessKeys) error { | |
return nil | ||
} | ||
|
||
// ValidateAccessKeys checks for complexity of credentials | ||
func ValidateAccessKeys(Access_keys nb.S3AccessKeys) { | ||
log := util.Logger() | ||
|
||
// Checking complexity for access_key | ||
if !ValidateComplexity(Access_keys.AccessKey, 20, true, false, true, false) { | ||
log.Fatalf(`❌ Account access key length must be 20, and must contain uppercase and numbers`) | ||
} | ||
|
||
// Checking complexity for secret_key | ||
if !ValidateComplexity(Access_keys.SecretKey, 40, true, true, true, true) { | ||
log.Fatalf(`❌ Account secret length must be 40, and must contain uppercase, lowercase, numbers and symbols`) | ||
} | ||
} | ||
|
||
// ValidateComplexity checks for complexity | ||
func ValidateComplexity(str string, length int, upper bool, lower bool, numbers bool, symbols bool) bool { | ||
|
||
if len(str) < length { | ||
return false | ||
} | ||
|
||
// Check uppercase | ||
if upper { | ||
if matched, _ := regexp.MatchString("[A-Z]", str); !matched { | ||
return false | ||
} | ||
} | ||
|
||
// Check lowercase | ||
if lower { | ||
if matched, _ := regexp.MatchString("[a-z]", str); !matched { | ||
return false | ||
} | ||
} | ||
|
||
// Check numbers | ||
if numbers { | ||
if matched, _ := regexp.MatchString("[0-9]", str); !matched { | ||
return false | ||
} | ||
} | ||
|
||
// Check symbols | ||
if symbols { | ||
if matched, _ := regexp.MatchString(`[^a-zA-Z0-9]`, str); !matched { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
// ResetPassword reset noobaa account password | ||
func ResetPassword(name string, oldPassword string, newPassword string, retypeNewPassword string) error { | ||
sysClient, err := system.Connect(true) | ||
|