# When creating an api key does run-as override the other settings?

**URL:** https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [January 31, 2023, 12:28am UTC](https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280 "2023-01-31T00:28:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Russell\_Fulton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/russell_fulton/32/62888_2.png) [@Russell\_Fulton](https://discuss.elastic.co/u/Russell_Fulton)
#### Post date: [January 31, 2023, 12:28am UTC](https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280/1 "2023-01-31T00:28:11Z")

</div>

I created an API key and left the other settings apart from `run-as` as default (i.e. wide open) and set run as to a user with a role that has the desired priviliges.

Will this key have the restriction of the assigned role?

I would hope yes! : )

---

<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: [January 31, 2023, 4:14am UTC](https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280/2 "2023-01-31T04:14:35Z")

</div>

Did you create the API key with something like the following

```auto
POST _security/api_key
{
  "name": "k1",
  "role_descriptors": {
    "x": {
      "run_as": [
        "foo"
      ]
    }
  }
}

```

If yes, the API key will only have the privilege to run-as user `foo` and nothing else.

---

<div class="post-metadata">

### Author: ![Russell\_Fulton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/russell_fulton/32/62888_2.png) [@Russell\_Fulton](https://discuss.elastic.co/u/Russell_Fulton)
#### Post date: [February 1, 2023, 6:22pm UTC](https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280/3 "2023-02-01T18:22:20Z")

</div>

Thanks!

Ah! I should have been more explicit. I generated the key in kibana. So should cut everything except the run-as entry?

 ![Screenshot 2023-02-02 at 7.18.15 AM](https://us1.discourse-cdn.com/elastic/original/3X/e/c/ece5c4befa3931f2e5dad1d9e1c23dac431e3424.png)

My reasoning was that if the key ran as a particular user then that would define the actual access.

---

<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: [February 2, 2023, 3:12am UTC](https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280/4 "2023-02-02T03:12:29Z")

</div>

> [@Russell\_Fulton](#):
>
> So should cut everything except the run-as entry?

That's correct

---

<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 2, 2023, 3:12am UTC](https://discuss.elastic.co/t/when-creating-an-api-key-does-run-as-override-the-other-settings/324280/5 "2023-03-02T03:12:42Z")

</div>

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