Add a user to role-mapping

Is there any api to update role mapping user such that it appends to the array of users. till now i can only find a api that would patch the whole array.

https://opendistro.github.io/for-elasticsearch-docs/docs/security-access-control/api/#patch-role-mapping

PATCH _opendistro/_security/api/rolesmapping/<role>
[
  {
    "op": "replace", "path": "/users", "value": ["userA", "userB", "userC"]
  }
]```

so at some point later i need to add userD. i need to get the existing list and add userD. 
i was expecting a idempotent way to add a user to rolemapping such that i do not have to care about the existing list that has the role mapping.
1 Like

Hi,

I am also trying to add mappings, I’ve tried:

PATCH _opendistro/_security/api/rolesmapping/<role>
[
  {
    "op": "add", "path": "/users", "value": ["userD"]
  }
] 

Unfortunately it doesn’t add userD, but replaces the whole mappings with userD

Hello
Actually you can do sth like this:

[

{

    "op": "add",

    "path": "/users/-",

    "value": "userD"

    

}

]

This will add it to the existant map.

1 Like

While running

PATCH _opendistro/_security/api/rolesmapping/
[
{
“op”: “replace”, “path”: “/users”, “value”: [“myuser”]
}
]

the result returned

{“statusCode”:400,“error”:“Bad Request”,“message”:“[request query.method]: Method must be one of, case insensitive [‘HEAD’, ‘GET’, ‘POST’, ‘PUT’, ‘DELETE’]. Received ‘PATCH’.”}

Maybe Patch is not accepted.

Need to know how to update the role without over writing the previous values