@@ -949,6 +949,8 @@ func (c *Cluster) rotatePasswordInSecret(
949
949
err error
950
950
nextRotationDate time.Time
951
951
nextRotationDateStr string
952
+ expectedUsername string
953
+ rotationModeChanged bool
952
954
updateSecretMsg string
953
955
)
954
956
@@ -969,17 +971,32 @@ func (c *Cluster) rotatePasswordInSecret(
969
971
nextRotationDate = currentRotationDate
970
972
}
971
973
974
+ // set username and check if it differs from current value in secret
975
+ currentUsername := string (secret .Data ["username" ])
976
+ if ! slices .Contains (c .Spec .UsersWithInPlaceSecretRotation , secretUsername ) {
977
+ expectedUsername = fmt .Sprintf ("%s%s" , secretUsername , currentTime .Format (constants .RotationUserDateFormat ))
978
+ } else {
979
+ expectedUsername = secretUsername
980
+ }
981
+
982
+ // when changing to in-place rotation update secret immediatly
983
+ // if currentUsername is longer we know it has a date suffix
984
+ // the other way around we can wait until the next rotation date
985
+ if len (currentUsername ) > len (expectedUsername ) {
986
+ rotationModeChanged = true
987
+ c .logger .Infof ("updating secret %s after switching to in-place rotation mode for username: %s" , secretName , string (secret .Data ["username" ]))
988
+ }
989
+
972
990
// update password and next rotation date if configured interval has passed
973
- if currentTime .After (nextRotationDate ) {
991
+ if currentTime .After (nextRotationDate ) || rotationModeChanged {
974
992
// create rotation user if role is not listed for in-place password update
975
993
if ! slices .Contains (c .Spec .UsersWithInPlaceSecretRotation , secretUsername ) {
976
- rotationUsername := fmt .Sprintf ("%s%s" , secretUsername , currentTime .Format (constants .RotationUserDateFormat ))
977
- secret .Data ["username" ] = []byte (rotationUsername )
978
- c .logger .Infof ("updating username in secret %s and creating rotation user %s in the database" , secretName , rotationUsername )
994
+ secret .Data ["username" ] = []byte (expectedUsername )
995
+ c .logger .Infof ("updating username in secret %s and creating rotation user %s in the database" , secretName , expectedUsername )
979
996
// whenever there is a rotation, check if old rotation users can be deleted
980
997
* retentionUsers = append (* retentionUsers , secretUsername )
981
998
} else {
982
- // when passwords of system users are rotated in place, pods have to be replaced
999
+ // when passwords of system users are rotated in- place, pods have to be replaced
983
1000
if roleOrigin == spec .RoleOriginSystem {
984
1001
pods , err := c .listPods ()
985
1002
if err != nil {
@@ -993,7 +1010,7 @@ func (c *Cluster) rotatePasswordInSecret(
993
1010
}
994
1011
}
995
1012
996
- // when password of connection pooler is rotated in place, pooler pods have to be replaced
1013
+ // when password of connection pooler is rotated in- place, pooler pods have to be replaced
997
1014
if roleOrigin == spec .RoleOriginConnectionPooler {
998
1015
listOptions := metav1.ListOptions {
999
1016
LabelSelector : c .poolerLabelsSet (true ).String (),
@@ -1010,10 +1027,12 @@ func (c *Cluster) rotatePasswordInSecret(
1010
1027
}
1011
1028
}
1012
1029
1013
- // when password of stream user is rotated in place, it should trigger rolling update in FES deployment
1030
+ // when password of stream user is rotated in- place, it should trigger rolling update in FES deployment
1014
1031
if roleOrigin == spec .RoleOriginStream {
1015
1032
c .logger .Warnf ("password in secret of stream user %s changed" , constants .EventStreamSourceSlotPrefix + constants .UserRoleNameSuffix )
1016
1033
}
1034
+
1035
+ secret .Data ["username" ] = []byte (secretUsername )
1017
1036
}
1018
1037
secret .Data ["password" ] = []byte (util .RandomPassword (constants .PasswordLength ))
1019
1038
secret .Data ["nextRotation" ] = []byte (nextRotationDateStr )
0 commit comments