# Create a role with dynamic "run\_as" field

**URL:** https://discuss.elastic.co/t/create-a-role-with-dynamic-run-as-field/168047
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [February 12, 2019, 2:19pm UTC](https://discuss.elastic.co/t/create-a-role-with-dynamic-run-as-field/168047 "2019-02-12T14:19:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Uiidoi12](https://avatars.discourse-cdn.com/v4/letter/u/73ab20/32.png) [@Uiidoi12](https://discuss.elastic.co/u/Uiidoi12)
#### Post date: [February 12, 2019, 2:19pm UTC](https://discuss.elastic.co/t/create-a-role-with-dynamic-run-as-field/168047/1 "2019-02-12T14:19:30Z")

</div>

Hi,

I would like to create a role like this:

```auto
POST /_xpack/security/role/my_dynamic_role
{
  "run_as" : [$user],
  ...
}

```

so that, e.g., when a `user1` is assigned to `my_dynamic_role` that role will be rendered as:

```json
{
  "run_as" : [user1]
}

```

but when a `user2` is assigned to `my_dynamic_role` that role will be rendered as:

```json
{
  "run_as" : [user2]
}

```

Is it possible to define a role like that somehow?

Thanks

---

<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 17, 2019, 11:48pm UTC](https://discuss.elastic.co/t/create-a-role-with-dynamic-run-as-field/168047/2 "2019-02-17T23:48:42Z")

</div>

> [@Uiidoi12](#):
>
> Is it possible to define a role like that somehow?

No, it is not possible to do that.  
You can create a custom role provider in Java, but even then each role needs to have a fixed value for `run_as`, so you would need to define a role per user.

---

<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: [March 17, 2019, 11:48pm UTC](https://discuss.elastic.co/t/create-a-role-with-dynamic-run-as-field/168047/3 "2019-03-17T23:48:44Z")

</div>

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