# How to create API key with built-in role ? Filebeat to Elastic configuration

**URL:** https://discuss.elastic.co/t/how-to-create-api-key-with-built-in-role-filebeat-to-elastic-configuration/344884
**Category:** Beats
**Tags:** elastic-stack-security, filebeat
**Created:** [October 12, 2023, 8:29am UTC](https://discuss.elastic.co/t/how-to-create-api-key-with-built-in-role-filebeat-to-elastic-configuration/344884 "2023-10-12T08:29:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gaetan\_Verdin-Pol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gaetan_verdin-pol/32/126254_2.png) [@Gaetan\_Verdin-Pol](https://discuss.elastic.co/u/Gaetan_Verdin-Pol)
#### Post date: [October 12, 2023, 8:29am UTC](https://discuss.elastic.co/t/how-to-create-api-key-with-built-in-role-filebeat-to-elastic-configuration/344884/1 "2023-10-12T08:29:29Z")

</div>

Hello all !

I am currently following the nginx filebeat integration from Filebeat to Elastic and I want to **use api\_key instead of username/password** to authenticate to my Elastic instance and setup the filebeat module.

Based on that [Grant privileges and roles needed for setup doc](https://www.elastic.co/guide/en/beats/filebeat/8.10/privileges-to-setup-beats.html), I need to give some priviledge to the user or api\_key, but also assign two built-in role `kibana_admin` and `ingest_admin`.

I have read the [Grant access using API keys](https://www.elastic.co/guide/en/beats/filebeat/8.10/beats-api-keys.html) but I do not know how to add built-in role to the api\_token I am creating... is it possible ?

For now am I using this block to create my API key :

```auto
POST /_security/api_key
{
  "name": "filebeat_host001", 
  "role_descriptors": {
    "filebeat_setup": { 
      "cluster": ["monitor", "manage_ilm"],
      "index": [
        {
          "names": ["filebeat-*"],
          "privileges": ["manage"]
        }
      ]
    }
  }
}

```

As expected I have error message like this when runninng filebeat with the created API key :  
`Error importing directory /opt/filebeat-8.10.3-linux-x86_64/kibana: failed to import Kibana index pattern: 1 error: error loading index pattern: returned 403 to import file: Unable to bulk_create index-pattern.`

Thanks for you help !

---

<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: [November 9, 2023, 10:29am UTC](https://discuss.elastic.co/t/how-to-create-api-key-with-built-in-role-filebeat-to-elastic-configuration/344884/2 "2023-11-09T10:29:41Z")

</div>

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