elastic / cloud-on-k8s

Elastic Cloud on Kubernetes
Other
2.58k stars 701 forks source link

ECK Filebeat default user cannot create indicess (403 - unauthorised error) #7002

Open akumar-99 opened 1 year ago

akumar-99 commented 1 year ago

Bug Report

What did you do? I am running ECK on AWS EKS 1.24. My use case is straight I want to scrape the container logs using filebeat and send them to their respective indices based on the container name.

What did you expect to see? Indices should get created and I should see entries. It is able to get the data but not able to create index and send it.

What did you see instead? Under which circumstances? I see and error in the filebeat pods.

{"log.level":"warn","@timestamp":"2023-07-11T07:47:09.824Z","log.logger":"elasticsearch","log.origin":{"file.name":"elasticsearch/client.go","file.line":446},"message":"Cannot index event publisher.Event{Content:beat.Event{--data--}, Flags:0x1, Cache:publisher.EventCache{m:mapstr.M(nil)}} (status=403): {\"type\":\"security_exception\",\"reason\":\"action [indices:data/write/bulk[s]] is unauthorized for user [observability-filebeat-beat-user] with effective roles [beats_admin,eck_beat_es_filebeat_role_v77,ingest_admin,kibana_admin,remote_monitoring_agent] on indices [production-pod-xyz-8.8.2], this action is granted by the index privileges [create_doc,create,delete,index,write,all]\"}, dropping event!","service.name":"filebeat","ecs.version":"1.6.0"}

Environment

clientVersion: buildDate: "2023-06-14T09:53:42Z" compiler: gc gitCommit: 25b4e43193bcda6c7328a6d147b1fb73a33f1598 gitTreeState: clean gitVersion: v1.27.3 goVersion: go1.20.5 major: "1" minor: "27" platform: linux/amd64 kustomizeVersion: v5.0.1 serverVersion: buildDate: "2023-05-22T23:41:27Z" compiler: gc gitCommit: 05d192f0de17608d98e17761ad3cffa9a6407f2f gitTreeState: clean gitVersion: v1.24.14-eks-c12679a goVersion: go1.19.9 major: "1" minor: 24+ platform: linux/amd64

WARNING: version difference between client (1.27) and server (1.24) exceeds the supported minor version skew of +/-1


* Resource definition:

apiVersion: elasticsearch.k8s.elastic.co/v1 kind: Elasticsearch metadata: name: elasticsearch namespace: observability spec: version: 8.8.2 nodeSets:

intermittentnrg commented 4 months ago

Also asked here without answer: https://discuss.elastic.co/t/filebeat-running-on-eck-cannot-create-an-index/316464

Seems a new role is needed as ECK doesn't allow editing the default/system roles https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-users-and-roles.html#k8s_creating_custom_roles

So just create user / roles either through Kibana or link above. Then ECK filebeat - remove elasticsearchRef and add the below:

spec:
  config:
    filebeat:
      output:
        elasticsearch:
          hosts:
            - http://elasticsearch-es-http.elastic.svc:9200
          password: xxxxx
          username: xxxx

custom outputs documented here: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-beat-configuration.html#k8s-beat-set-beat-output

Hope this helps someone I didn't find this simple well documented.