Create API key which represent the rights of an built in user

Hello all !

I am following this guide to setup the monitoring (with Metricbeat) of my non prod Elastic cluster.

I edited the modules.d/elasticsearch-xpack.yml file in order to put the needed username and password. It is working as expected with the build in user remote_monitoring_user.

  - module: elasticsearch
    xpack.enabled: true
    period: 10s
    hosts: ["http://localhost:9200"] 
    username: "remote_monitoring_user"
    password: "<secret>"

Is it possible to create an API token on behalf of this user and use it in this .yml configuration file ?
I also tried to create a new role based on the built in roles remote_monitoring_agent and remote_monitoring_collector but I always end up with 403 forbidden error...

Any advice would be very appreciated !

I know I can achieve the same monitoring with Elastic agent also, I will give it a try!