diff --git a/pkg/dbclient/client.go b/pkg/dbclient/client.go index b2a6fd2a..9bc41257 100644 --- a/pkg/dbclient/client.go +++ b/pkg/dbclient/client.go @@ -549,7 +549,7 @@ func (pc *client) CreateReadOnlyRole(dbName, rolename, schema string) (bool, err func (pc *client) AssignRoleToUser(username, rolename string) error { db := pc.DB - if _, err := db.Exec(fmt.Sprintf("GRANT %s TO %s", pq.QuoteIdentifier(rolename), pq.QuoteIdentifier(username))); err != nil { + if _, err := db.Exec(fmt.Sprintf("ALTER ROLE %s SET ROLE TO %s;GRANT %s TO %s;", pq.QuoteIdentifier(username), pq.QuoteIdentifier(rolename), pq.QuoteIdentifier(rolename), pq.QuoteIdentifier(username))); err != nil { return err } diff --git a/pkg/roleclaim/roleclaim_test.go b/pkg/roleclaim/roleclaim_test.go index 1e5b4261..2db682c3 100644 --- a/pkg/roleclaim/roleclaim_test.go +++ b/pkg/roleclaim/roleclaim_test.go @@ -259,6 +259,11 @@ func TestDBRoleClaimController_RevokeRolesAndAssignNew(t *testing.T) { defer close() viperObj.Set("passwordconfig::passwordRotationPeriod", 60) + viperObj.Set("defaultMasterUsername", "root") + viperObj.Set("defaultMasterPort", "5432") + viperObj.Set("defaultSslMode", "require") + viperObj.Set("defaultMinStorageGB", "10") + viperObj.Set("defaultSslMode", "disable") test := struct { rec reconciler