Skip to content

Commit a0fb7a1

Browse files
committed
fix creating secrets for rotation users
1 parent c8063eb commit a0fb7a1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

e2e/tests/test_e2e.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1752,9 +1752,13 @@ def test_password_rotation(self):
17521752
Test password rotation and removal of users due to retention policy
17531753
'''
17541754
k8s = self.k8s
1755+
cluster_label = 'application=spilo,cluster-name=acid-minimal-cluster'
17551756
leader = k8s.get_cluster_leader_pod()
17561757
today = date.today()
17571758

1759+
# remember number of secrets to make sure it stays the same
1760+
secret_count = k8s.count_secrets_with_label(cluster_label)
1761+
17581762
# enable password rotation for owner of foo database
17591763
pg_patch_rotation_single_users = {
17601764
"spec": {
@@ -1859,10 +1863,24 @@ def test_password_rotation(self):
18591863
# check if rotation has been ignored for user from test_cross_namespace_secrets test
18601864
db_user_secret = k8s.get_secret(username="test.db_user", namespace="test")
18611865
secret_username = str(base64.b64decode(db_user_secret.data["username"]), 'utf-8')
1862-
18631866
self.assertEqual("test.db_user", secret_username,
18641867
"Unexpected username in secret of test.db_user: expected {}, got {}".format("test.db_user", secret_username))
18651868

1869+
# do a cluster update which syncs secrets but not not init users
1870+
pg_annotation_patch = {
1871+
"metadata": {
1872+
"annotations": {
1873+
"deployment-time": "2020-04-01 12:00:00",
1874+
}
1875+
}
1876+
}
1877+
k8s.api.custom_objects_api.patch_namespaced_custom_object(
1878+
"acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", pg_annotation_patch)
1879+
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")
1880+
1881+
time.sleep(10)
1882+
self.eventuallyEqual(lambda: k8s.count_secrets_with_label(cluster_label), secret_count, "Unexpected number of secrets")
1883+
18661884
# disable password rotation for all other users (foo_user)
18671885
# and pick smaller intervals to see if the third fake rotation user is dropped
18681886
enable_password_rotation = {

pkg/cluster/k8sres.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,12 @@ func (c *Cluster) generateUserSecrets() map[string]*v1.Secret {
19001900
}
19011901

19021902
func (c *Cluster) generateSingleUserSecret(pgUser spec.PgUser) *v1.Secret {
1903-
//Skip users with no password i.e. human users (they'll be authenticated using pam)
1903+
// skip rotation users (not now to check if e2e test fails)
1904+
//if pgUser.Rotated {
1905+
// return nil
1906+
//}
1907+
1908+
// skip users with no password i.e. human users (they'll be authenticated using pam)
19041909
if pgUser.Password == "" {
19051910
if pgUser.Origin != spec.RoleOriginTeamsAPI {
19061911
c.logger.Warningf("could not generate secret for a non-teamsAPI role %q: role has no password",
@@ -1909,7 +1914,7 @@ func (c *Cluster) generateSingleUserSecret(pgUser spec.PgUser) *v1.Secret {
19091914
return nil
19101915
}
19111916

1912-
//skip NOLOGIN users
1917+
// skip NOLOGIN users
19131918
for _, flag := range pgUser.Flags {
19141919
if flag == constants.RoleFlagNoLogin {
19151920
return nil

0 commit comments

Comments
 (0)