Skip to content

Commit 539e164

Browse files
committed
fixes for the role of user admin
1 parent c90a055 commit 539e164

File tree

1 file changed

+3
-2
lines changed
  • pkg/controller/perconaservermongodb

1 file changed

+3
-2
lines changed

pkg/controller/perconaservermongodb/mgo.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ func (r *ReconcilePerconaServerMongoDB) handleRsAddToShard(ctx context.Context,
647647
}
648648

649649
// handleReplsetInit initializes the replset within the first running pod's mongod container.
650-
// This must be ran from within the running container to utilize the MongoDB Localhost Exception.
650+
// This must be run from within the running container to utilize the MongoDB Localhost Exception.
651651
//
652652
// See: https://www.mongodb.com/docs/manual/core/localhost-exception/
653653
func (r *ReconcilePerconaServerMongoDB) handleReplsetInit(ctx context.Context, cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec, pods []corev1.Pod) (*corev1.Pod, *api.ReplsetMemberStatus, error) {
@@ -1007,6 +1007,7 @@ func (r *ReconcilePerconaServerMongoDB) createOrUpdateSystemUsers(ctx context.Co
10071007
}
10081008

10091009
users := []api.SystemUserRole{api.RoleClusterAdmin, api.RoleClusterMonitor, api.RoleBackup, api.RoleDatabaseAdmin}
1010+
// When handleReplsetInit is not executed, e.g. when auth is disabled, the UserAdmin role should be created.
10101011
if cr.CompareVersion("1.22.0") >= 0 {
10111012
users = append(users, api.RoleUserAdmin)
10121013
}
@@ -1029,7 +1030,7 @@ func (r *ReconcilePerconaServerMongoDB) createOrUpdateSystemUsers(ctx context.Co
10291030
}
10301031
continue
10311032
}
1032-
if !compareRoles(user.Roles, getRoles(cr, role)) {
1033+
if !compareRoles(user.Roles, getRoles(cr, role)) && role != api.RoleUserAdmin {
10331034
log.Info("Updating user roles", "database", "admin", "user", creds.Username, "currentRoles", user.Roles, "newRoles", getRoles(cr, role))
10341035
err = cli.UpdateUserRoles(ctx, "admin", creds.Username, getRoles(cr, role))
10351036
if err != nil {

0 commit comments

Comments
 (0)