# How to grant a plugin permissions for updating indices and index templates

**URL:** https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [May 3, 2022, 6:51pm UTC](https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868 "2022-05-03T18:51:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kved](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@kved](https://discuss.elastic.co/u/kved)
#### Post date: [May 3, 2022, 6:51pm UTC](https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868/1 "2022-05-03T18:51:35Z")

</div>

I created a plugin to manage index templates and index settings, however I'm seeing an error that

```auto
 action [indices:admin/template/get] is unauthorized for user [_system]

```

I tried adding the `superuser` role to the `_system` user, but the error message did not go away. Is there a way to have a plugin run as the `elastic` user or is there a way to grant the `_system` user the correct permissions?

---

<div class="post-metadata">

### Author: ![Yang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yang_wang/32/48857_2.png) [@Yang\_Wang](https://discuss.elastic.co/u/Yang_Wang)
#### Post date: [May 4, 2022, 6:38am UTC](https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868/2 "2022-05-04T06:38:41Z")

</div>

`_system` user is immutable. For most plugins, the `_xpack` user is a better choice for performing internal actions.

---

<div class="post-metadata">

### Author: ![kved](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@kved](https://discuss.elastic.co/u/kved)
#### Post date: [May 4, 2022, 1:30pm UTC](https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868/3 "2022-05-04T13:30:57Z")

</div>

Makes sense! How can we change the plugin to run / perform actions as the `_xpack` user? I couldn't find any samples anywhere.

---

<div class="post-metadata">

### Author: ![Yang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yang_wang/32/48857_2.png) [@Yang\_Wang](https://discuss.elastic.co/u/Yang_Wang)
#### Post date: [May 5, 2022, 1:24am UTC](https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868/4 "2022-05-05T01:24:05Z")

</div>

For now you can use `OriginSettingClient` with `TASKS_ORIGIN` as shown in this piece of code:

> <https://github.com/elastic/elasticsearch/blob/85bdf0f2d91f67a14d702b20e7354fa71dd7369f/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java#L75>

The client will internally issue all requests with the `_xpack` user.

NB: This approach relies on the internals of ES code. There is no backwards compatibility guarantee at this level. The code can change in any future release and possibly break your plugin.

---

<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: [June 2, 2022, 1:24am UTC](https://discuss.elastic.co/t/how-to-grant-a-plugin-permissions-for-updating-indices-and-index-templates/303868/5 "2022-06-02T01:24:40Z")

</div>

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