elastic / xk6-output-elasticsearch

Apache License 2.0
20 stars 10 forks source link

[indices:admin/create] is unauthorized for user #27

Closed mujamil90 closed 8 months ago

mujamil90 commented 8 months ago

Hi,

I am using this extension to integrate K6 tests with our organization's Elastic search's instance. I have already integrated with locally hosted ES as per the README.md file. I am getting below error when creating index in ES after test execution.

Error_ES_Index

I have provided details like K6_ELASTICSEARCH_URL, K6_ELASTICSEARCH_USER and K6_ELASTICSEARCH_PASSWORD inside K6 service in docker-compose.yml file. You can see it below:

k6: build: . ports:

  • "6565:6565" environment:
  • K6_OUT=output-elasticsearch
  • K6_ELASTICSEARCH_URL=my_org_es_url
  • K6_ELASTICSEARCH_USER=performance_test
  • K6_ELASTICSEARCH_PASSWORD=xyz
  • K6_ELASTICSEARCH_INDEX_NAME=filebeat-k6-metrics
  • K6_ELASTICSEARCH_INSECURE_SKIP_VERIFY=true

Note: User already has permission to create index.

danielmitterdorfer commented 8 months ago

Can you please run the following command and paste the output here?

curl -s -k -u $K6_ELASTICSEARCH_USER:$K6_ELASTICSEARCH_PASSWORD -X POST "$K6_ELASTICSEARCH_URL/_security/user/_has_privileges?pretty" -H 'Content-Type: application/json' -d' 
{
  "index": [
    {
      "names": [
        "filebeat-k6-metrics"
      ],
      "privileges": [
        "write", "create_index"
      ]
    }
  ]
}'

I'm assuming here that K6_ELASTICSEARCH_URL looks something like "https://my-host-name:9200". Please modify the example above accordingly.

The output should similar to:

{
  "username" : "elastic-admin",
  "has_all_requested" : true,
  "cluster" : { },
  "index" : {
    "filebeat-k6-metrics" : {
      "create_index" : true,
      "write" : true
    }
  },
  "application" : { }
}

Specifically has_all_requested must be true otherwise that user does not have sufficient permissions.

mujamil90 commented 8 months ago

I have have sent curl request with port and without port _has_allrequested is false in both case. After checking with responsible person I found that User has rights but pattern for Index is started with "performancetest-*". Now I can see _has_allrequested is true curl_check_user_access

And I am not getting any error. Thank you for quick reply.

danielmitterdorfer commented 8 months ago

Great it works now and thanks for the follow-up! Closing now as your issue is resolved.