Skip to content

Commit 5abbf84

Browse files
authored
feat: specify allowed symbols in password generation (#9489)
1 parent e83ff2e commit 5abbf84

15 files changed

Lines changed: 106 additions & 13 deletions

apis/apps/v1alpha1/clusterdefinition_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ type PasswordConfig struct {
257257
// +optional
258258
NumSymbols int32 `json:"numSymbols,omitempty"`
259259

260+
// The set of symbols allowed when generating password. If empty, kubeblocks will
261+
// use a default symbol set, which is "!@#&*".
262+
//
263+
// +optional
264+
SymbolCharacters string `json:"symbolCharacters,omitempty"`
265+
260266
// The case of the letters in the password.
261267
//
262268
// +kubebuilder:default=MixedCases

config/crd/bases/apps.kubeblocks.io_clusterdefinitions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9535,6 +9535,11 @@ spec:
95359535
Seed to generate the account's password.
95369536
Cannot be updated.
95379537
type: string
9538+
symbolCharacters:
9539+
description: |-
9540+
The set of symbols allowed when generating password. If empty, kubeblocks will
9541+
use a default symbol set, which is "!@#&*".
9542+
type: string
95389543
type: object
95399544
required:
95409545
- accounts

config/crd/bases/apps.kubeblocks.io_clusters.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,6 +5273,11 @@ spec:
52735273
Seed to generate the account's password.
52745274
Cannot be updated.
52755275
type: string
5276+
symbolCharacters:
5277+
description: |-
5278+
The set of symbols allowed when generating password. If empty, kubeblocks will
5279+
use a default symbol set, which is "!@#&*".
5280+
type: string
52765281
type: object
52775282
secretRef:
52785283
description: |-
@@ -13941,6 +13946,11 @@ spec:
1394113946
Seed to generate the account's password.
1394213947
Cannot be updated.
1394313948
type: string
13949+
symbolCharacters:
13950+
description: |-
13951+
The set of symbols allowed when generating password. If empty, kubeblocks will
13952+
use a default symbol set, which is "!@#&*".
13953+
type: string
1394413954
type: object
1394513955
secretRef:
1394613956
description: |-

config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13942,6 +13942,11 @@ spec:
1394213942
Seed to generate the account's password.
1394313943
Cannot be updated.
1394413944
type: string
13945+
symbolCharacters:
13946+
description: |-
13947+
The set of symbols allowed when generating password. If empty, kubeblocks will
13948+
use a default symbol set, which is "!@#&*".
13949+
type: string
1394513950
type: object
1394613951
secretRef:
1394713952
description: |-

config/crd/bases/apps.kubeblocks.io_components.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5433,6 +5433,11 @@ spec:
54335433
Seed to generate the account's password.
54345434
Cannot be updated.
54355435
type: string
5436+
symbolCharacters:
5437+
description: |-
5438+
The set of symbols allowed when generating password. If empty, kubeblocks will
5439+
use a default symbol set, which is "!@#&*".
5440+
type: string
54365441
type: object
54375442
secretRef:
54385443
description: |-

controllers/apps/transformer_cluster_shared_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (t *clusterSharedAccountTransformer) buildAccountSecret(transCtx *clusterTr
158158

159159
func (t *clusterSharedAccountTransformer) generatePassword(account appsv1alpha1.ComponentSystemAccount) []byte {
160160
config := account.PasswordConfig
161-
passwd, _ := common.GeneratePassword((int)(config.Length), (int)(config.NumDigits), (int)(config.NumSymbols), config.Seed)
161+
passwd, _ := common.GeneratePassword((int)(config.Length), (int)(config.NumDigits), (int)(config.NumSymbols), config.Seed, config.SymbolCharacters)
162162
switch config.LetterCase {
163163
case appsv1alpha1.UpperCases:
164164
passwd = strings.ToUpper(passwd)

controllers/apps/transformer_component_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (t *componentAccountTransformer) buildPassword(ctx *componentTransformConte
154154

155155
func (t *componentAccountTransformer) generatePassword(account appsv1alpha1.SystemAccount) []byte {
156156
config := account.PasswordGenerationPolicy
157-
passwd, _ := common.GeneratePassword((int)(config.Length), (int)(config.NumDigits), (int)(config.NumSymbols), config.Seed)
157+
passwd, _ := common.GeneratePassword((int)(config.Length), (int)(config.NumDigits), (int)(config.NumSymbols), config.Seed, config.SymbolCharacters)
158158
switch config.LetterCase {
159159
case appsv1alpha1.UpperCases:
160160
passwd = strings.ToUpper(passwd)

deploy/helm/crds/apps.kubeblocks.io_clusterdefinitions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9535,6 +9535,11 @@ spec:
95359535
Seed to generate the account's password.
95369536
Cannot be updated.
95379537
type: string
9538+
symbolCharacters:
9539+
description: |-
9540+
The set of symbols allowed when generating password. If empty, kubeblocks will
9541+
use a default symbol set, which is "!@#&*".
9542+
type: string
95389543
type: object
95399544
required:
95409545
- accounts

deploy/helm/crds/apps.kubeblocks.io_clusters.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,6 +5273,11 @@ spec:
52735273
Seed to generate the account's password.
52745274
Cannot be updated.
52755275
type: string
5276+
symbolCharacters:
5277+
description: |-
5278+
The set of symbols allowed when generating password. If empty, kubeblocks will
5279+
use a default symbol set, which is "!@#&*".
5280+
type: string
52765281
type: object
52775282
secretRef:
52785283
description: |-
@@ -13941,6 +13946,11 @@ spec:
1394113946
Seed to generate the account's password.
1394213947
Cannot be updated.
1394313948
type: string
13949+
symbolCharacters:
13950+
description: |-
13951+
The set of symbols allowed when generating password. If empty, kubeblocks will
13952+
use a default symbol set, which is "!@#&*".
13953+
type: string
1394413954
type: object
1394513955
secretRef:
1394613956
description: |-

deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13942,6 +13942,11 @@ spec:
1394213942
Seed to generate the account's password.
1394313943
Cannot be updated.
1394413944
type: string
13945+
symbolCharacters:
13946+
description: |-
13947+
The set of symbols allowed when generating password. If empty, kubeblocks will
13948+
use a default symbol set, which is "!@#&*".
13949+
type: string
1394513950
type: object
1394613951
secretRef:
1394713952
description: |-

0 commit comments

Comments
 (0)