# How to bulk migrate users and roles with native realms authentication

**URL:** <https://discuss.elastic.co/t/how-to-bulk-migrate-users-and-roles-with-native-realms-authentication/350476>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [January 5, 2024, 4:23pm UTC](https://discuss.elastic.co/t/how-to-bulk-migrate-users-and-roles-with-native-realms-authentication/350476 "2024-01-05T16:23:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fim/32/90645_2.png) [@fim](https://discuss.elastic.co/u/fim)\
**Post date:** [January 5, 2024, 4:23pm UTC](https://discuss.elastic.co/t/how-to-bulk-migrate-users-and-roles-with-native-realms-authentication/350476/1 "2024-01-05T16:23:17Z")

</div>

I'm looking for an advice how to migrate users (if possible including passwords) and roles from an old cluster to a new cluster. (Elasticsearch v8.x)

I wanna perform this with Kibana DevTools.

I populate users and roles from the old cluster with:

```auto
GET /_security/role/
GET /_security/users/

```

I tried to insert on the new cluster without success:

```auto
POST /_security/role
{
{
  "user1" : {
    "username" : "user1",
    "roles" : [
      "superuser"
    ]
  },
  "user2" : {
    "username" : "user2",
    "roles" : [
      "kibana_system"
    ]
  },
  "user3" : {
    "username" : "user3",
    "roles" : [
      "kibana_system"
    ],
  "user4" : {
    "username" : "user4",
    "roles" : [
      "kibana_system"
    ],
...
}

```

Is there a way to bulk insert a list of users?

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [February 1, 2024, 6:31am UTC](https://discuss.elastic.co/t/how-to-bulk-migrate-users-and-roles-with-native-realms-authentication/350476/2 "2024-02-01T06:31:08Z")

</div>

There is not an API for bulk creation of users or roles.

We've looked at it, but decided it doesn't really help for a few reasons

- It's not needed for performance (see below)
- Bulk APIs have tricky semantics around reporting success/failure
- Having multiple APIs for the same end result can be confusing.

What you need to do is split the response up per-role and sent that to the `PUT /_security/role` API.  
You can improve performance by passing `refresh=false` as an HTTP parameter. Without that ES Security will force each user/role to be refreshed individually which is unnecessary if you're trying to load a bunch of them.

**Note** : We don't have a simple way to migrate passwords for users. You _can_ do it by directly querying the `.security` index to get the password hash, but I'd recommend that the simplest path is for you to give each user a new password and then ask them to change it afterwards.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 29, 2024, 6:31am UTC](https://discuss.elastic.co/t/how-to-bulk-migrate-users-and-roles-with-native-realms-authentication/350476/3 "2024-02-29T06:31:22Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
