Bulk import role mappings from one cluster to another via API

I am attempting to dump all role mappings out of one cluster into another by using the Role Mapping API. I use the generic:

GET /_security/role_mapping

to dump all the mappings but cannot find a way to easily bulk import as the create/update api seems to require a name like

PUT /_security/role_mapping/<namegoeshere>

I tried simply not putting the name in and adding the output to the input by doing:

PUT /_security/role_mapping
{
  "Example User 1": {
    "enabled": true,
    "roles": [
      "superuser"
    ],
    "rules": {
      "all": [
        {
          "field": {
            "username": "example.user1"
          }
        },
        {
          "field": {
            "realm.name": "realmnamehere"
          }
        }
      ]
    },
    "metadata": {}
  },
  "Example User 2": {
    "enabled": true,
    "roles": [
      "superuser"
    ],
    "rules": {
      "all": [
        {
          "field": {
            "realm.name": "realmnamehere"
          }
        },
        {
          "field": {
            "username": "example.user2"
          }
        }
      ]
    },
    "metadata": {}
  }
}

but that failed with:

{
  "error": "Incorrect HTTP method for uri [/_security/role_mapping?pretty=true] and method [PUT], allowed: [GET]",
  "status": 405
}

Am I missing some easy way to do this or is the only way to load this one at a time?

The name of the role mapping is required, so you will need to load one at a time or build a custom script to automate this.

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