fix: enable user password pattern checking via CRD validation.
This commit is contained in:
3
config/crds/iam.kubesphere.io_users.yaml
generated
3
config/crds/iam.kubesphere.io_users.yaml
generated
@@ -58,6 +58,9 @@ spec:
|
||||
type: string
|
||||
password:
|
||||
description: password will be encrypted by mutating admission webhook
|
||||
maxLength: 64
|
||||
minLength: 6
|
||||
pattern: ^(.*[a-z].*[A-Z].*[0-9].*)$|^(.*[a-z].*[0-9].*[A-Z].*)$|^(.*[A-Z].*[a-z].*[0-9].*)$|^(.*[A-Z].*[0-9].*[a-z].*)$|^(.*[0-9].*[a-z].*[A-Z].*)$|^(.*[0-9].*[A-Z].*[a-z].*)$|^(\$2[ayb]\$.{56})$
|
||||
type: string
|
||||
required:
|
||||
- email
|
||||
|
||||
@@ -124,7 +124,20 @@ type UserSpec struct {
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
// +optional
|
||||
Groups []string `json:"groups,omitempty"`
|
||||
|
||||
// password will be encrypted by mutating admission webhook
|
||||
// +kubebuilder:validation:MinLength=6
|
||||
// +kubebuilder:validation:MaxLength=64
|
||||
// +kubebuilder:validation:Pattern=`^(.*[a-z].*[A-Z].*[0-9].*)$|^(.*[a-z].*[0-9].*[A-Z].*)$|^(.*[A-Z].*[a-z].*[0-9].*)$|^(.*[A-Z].*[0-9].*[a-z].*)$|^(.*[0-9].*[a-z].*[A-Z].*)$|^(.*[0-9].*[A-Z].*[a-z].*)$|^(\$2[ayb]\$.{56})$`
|
||||
// Password pattern is tricky here.
|
||||
// The rule is simple: length between [6,64], at least one uppercase letter, one lowercase letter, one digit.
|
||||
// The regexp in console(javascript) is quite straightforward: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,64}$
|
||||
// But in Go, we don't have ?= (back tracking) capability in regexp (also in CRD validation pattern)
|
||||
// So we adopted an alternative scheme to achieve.
|
||||
// Use 6 different regexp to combine to achieve the same effect.
|
||||
// These six schemes enumerate the arrangement of numbers, uppercase letters, and lowercase letters
|
||||
// that appear for the first time.
|
||||
// Last but not least, the bcrypt string is also included to match the encrypted password. ^(\$2[ayb]\$.{56})$
|
||||
EncryptedPassword string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user