Skip to content

Commit 6ed87fc

Browse files
committed
fixes for the role of user admin
1 parent c90a055 commit 6ed87fc

File tree

1 file changed

+8
-1
lines changed
  • pkg/controller/perconaservermongodb

1 file changed

+8
-1
lines changed

pkg/controller/perconaservermongodb/mgo.go

Lines changed: 8 additions & 1 deletion
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) {
@@ -809,6 +809,12 @@ func getRoles(cr *api.PerconaServerMongoDB, role api.SystemUserRole) []mongo.Rol
809809
{DB: "admin", Role: "directShardOperations"},
810810
}
811811
}
812+
case api.RoleUserAdmin:
813+
if cr.CompareVersion("1.22.0") >= 0 {
814+
roles = []mongo.Role{
815+
{DB: "admin", Role: "userAdminAnyDatabase"},
816+
}
817+
}
812818
}
813819
roles = append(roles, mongo.Role{DB: "admin", Role: string(role)})
814820
return roles
@@ -1007,6 +1013,7 @@ func (r *ReconcilePerconaServerMongoDB) createOrUpdateSystemUsers(ctx context.Co
10071013
}
10081014

10091015
users := []api.SystemUserRole{api.RoleClusterAdmin, api.RoleClusterMonitor, api.RoleBackup, api.RoleDatabaseAdmin}
1016+
// When handleReplsetInit is not executed, e.g. when auth is disabled, the UserAdmin role should be created.
10101017
if cr.CompareVersion("1.22.0") >= 0 {
10111018
users = append(users, api.RoleUserAdmin)
10121019
}

0 commit comments

Comments
 (0)