fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

[aws signv4] ES output plugin not works with AWS Elasticsearch.

Open mak-1-sim opened this issue 6 years ago • 12 comments

Bug Report

Describe the bug Error while "Fluent-Bit" tries to send logs to AWS Elasticsearch. Tested with "Fluent-Bit" v1.0.6, v1.2.2, v1.3.2, v1.3.3. AWS Elasticsearch 6.5 & 7.1. Curl to AWS Elasticsearch endpoint successfully creating an index and put data in it. FluentD (deployed to same cluster and nodes) Elasticsearch Output plugin successfully works with the same AWS Elasticsearch. To Reproduce Use ES Ouput plugin with AWS Elasticsearch

[2019/12/12 09:53:33] [debug] [in_tail] file=/var/log/containers/metrics-server-7fcf9cc98b-dnvpc_kube-system_metrics-server-8efc965a98d05ad7e1a45b9c459d25e9b3843c0fa83b37aceed59f96efddde1d.log read=32728 lines=118
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e487c0 id=35 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48700 id=36 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48640 id=37 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48880 id=38 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48940 id=39 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48a00 id=40 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48ac0 id=41 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48b80 id=42 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48c40 id=43 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48d00 id=44 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48dc0 id=45 OK
[2019/12/12 09:53:33] [debug] [task] created task=0x7f1025e48e80 id=46 OK
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:33] [debug] [retry] new retry created for task_id=0 attemps=1
[2019/12/12 09:53:33] [debug] [sched] retry=0x7f1025e0a0f0 0 in 9 seconds
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [retry] new retry created for task_id=1 attemps=1
[2019/12/12 09:53:34] [debug] [sched] retry=0x7f1025e0a118 1 in 7 seconds
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [out_es] HTTP Status=400 URI=/_bulk
[2019/12/12 09:53:34] [debug] [retry] new retry created for task_id=3 attemps=1
[2019/12/12 09:53:34] [debug] [sched] retry=0x7f1025e0a140 3 in 3 seconds

  • Steps to reproduce the problem: Up EKS cluster, Up AWS Elasticsearch Domain, Deploy to EKS cluster Fluent-Bit with ES Output to AWS Elasticsearch

Config

  fluent-bit-filter.conf: |
    [FILTER]
        Name                kubernetes
        Match               kube.*
        Kube_Tag_Prefix     kube.var.log.containers.
        Kube_URL            https://kubernetes.default.svc:443
        Kube_CA_File        /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        Kube_Token_File     /var/run/secrets/kubernetes.io/serviceaccount/token
        Merge_Log           Off
        K8S-Logging.Parser  On
        K8S-Logging.Exclude On
  fluent-bit-input.conf: |
    [INPUT]
        Name                tail
        Path                /var/log/containers/*.log
        Parser              docker
        Tag                 kube.*
        Refresh_Interval    10
        Mem_Buf_Limit       1MB
        Skip_Long_Lines     On
        Ignore_Older        2h
        DB                  /var/log/flb_kube.db
  fluent-bit-output.conf: |
    [OUTPUT]
        Name                es
        Match               *
        Host                vpc-<hided>.us-west-2.es.amazonaws.com
        Port                443
        Logstash_Format     On
        Logstash_Prefix     env-1
        Retry_Limit         False
        Replace_Dots        On
  fluent-bit-service.conf: |
    [SERVICE]
        Flush               1
        Daemon              Off
        Log_Level           debug
        Parsers_File        parsers.conf
        HTTP_Server         On
        HTTP_Listen         0.0.0.0
        HTTP_Port           2020
  fluent-bit.conf: |
    @INCLUDE fluent-bit-service.conf
    @INCLUDE fluent-bit-input.conf
    @INCLUDE fluent-bit-filter.conf
    @INCLUDE fluent-bit-output.conf
  parsers.conf: ""

Your Environment EKS v1.14 EKS-nodes v1.14.7-eks-1861c5 CoreDNS v1.3.1 AWS Elasticsearch 6.5 & 7.1

mak-1-sim avatar Dec 12 '19 10:12 mak-1-sim

@hardcorexcat thanks for raising this issue.

Fluent Bit HTTP error you are seeing is 400, which means Forbidden, the HTTP request could not be processed by the server due to security restriction.

Looking at the AWS Elasticsearch documentation, we can see that AWS Elasticsearch has an extra security mechanism where the HTTP request must be signed with AWS SIgnv4:

https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html

The bad and the good news... the bad is that currently, we don't support that mechanism as part of Fluent Bit, the good news is that I've just implemented Signv4 in our development branch without the need of extra dependencies:

https://github.com/fluent/fluent-bit/blob/master/src/flb_signv4.c

We are working on full AWS services integrations and AWS Elasticsearch should be supported by the end of January.

@PettitWesley : are you aware about any workaround for @hardcorexcat ?

edsiper avatar Dec 12 '19 12:12 edsiper

The workaround described by #1804 here:

https://github.com/abutaha/aws-es-proxy

edsiper avatar Dec 12 '19 12:12 edsiper

@edsiper Ok. Now I fully understand the root cause of that issue. Thanks for your time to answer me :)

We are working on full AWS services integrations and AWS Elasticsearch should be supported by the end of January.

I think I will wait until the end of January and use a stable version. And thanks again for your work. Fluent-Bit "perfectly balanced as all things should be" one of my loved tools <3

mak-1-sim avatar Dec 12 '19 13:12 mak-1-sim

thanks for your kind words, happy to hear that project's feedback :)

FYI: I've documented this current restriction here:

https://docs.fluentbit.io/manual/output/elasticsearch#fluent-bit-aws-elasticsearch

edsiper avatar Dec 12 '19 16:12 edsiper

The easier approach would be to disable signing in your VPC-enabled domain's policy by removing the Principal:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "es:*",
            "Resource": "arn:aws:es:us-east-1:666666666666:domain/es-domain-name/*"
        }
    ]
}

And then change your Fluentbit output to something like this:

            [OUTPUT]
                Name  es
                Match *
                Host vpc-<hided>.us-east-2.es.amazonaws.com
                Port  443
                Index k8s-index
                Type  my_type
                tls    On
                tls.verify Off

Note the presence of these 2: tls On tls.verify Off

This is unnecessary for non-VPC domains though.

hlosukwakha avatar Dec 18 '19 06:12 hlosukwakha

Implemented through #1920

FYI: On 1.4 release this feature is considered experimental.

edsiper avatar Feb 23 '20 16:02 edsiper

search-somewords-huh444mcj5znmfcnlkzcckmqw4.us-east-2.es.amazonaws.com:443 timed out after 10 seconds

output-elasticsearch.conf: | [OUTPUT] Name es Match * Host search-somewords-huh444mcj5znmfcnlkzcckmqw4.us-east-2.es.amazonaws.com Port 443 AWS_Region us-east-2 Logstash_Format On Replace_Dots On Retry_Limit False Logstash_Prefix my-logs

any idea how can i fix it (running on aws eks tryne knock on aws es

azizonick avatar May 18 '21 23:05 azizonick

i ve disabled tls now i got

[2021/05/18 23:08:14] [error] [output:es:es.0] HTTP status=400 URI=/_bulk, response:

400 The plain HTTP request was sent to HTTPS port

400 Bad Request

The plain HTTP request was sent to HTTPS port

[2021/05/18 23:08:14] [ warn] [engine] failed to flush chunk '1-1621379259.282896988.flb', retry in 528 seconds: task_id=314, input=tail.0 > out put=es.0 (out_id=0)

azizonick avatar May 18 '21 23:05 azizonick

@azizonick Make sure you have TLS on. I see you config seems to be missing a key for AWS_Auth On.

This is a good config example to work off of: https://github.com/aws/aws-for-fluent-bit/blob/mainline/ecs/amazon-es.conf

PettitWesley avatar May 18 '21 23:05 PettitWesley

output-elasticsearch.conf: | [OUTPUT] Namees Match* Hostsearch-elk-dev-huh444mcj5znmfcnlkzcckmqw4.us-east-2.es.amazonaws.com Port443 AWS_Regionus-east-2 Logstash_Format On Replace_Dots On Retry_Limit False Logstash_Prefix my-logs AWS_Auth On tls On

2.

env:

  • name: FLUENT_ELASTICSEARCH_HOST value: ${FLUENT_ELASTICSEARCH_HOST}
  • name: FLUENT_ELASTICSEARCH_PORT value: ${FLUENT_ELASTICSEARCH_PORT}

[2021/05/19 14:04:57] [ warn] [engine] failed to flush chunk '1-1621433089.282691405.flb', retry in 87 seconds: task_id=5, input=tail.0 > output =es.0 (out_id=0) [2021/05/19 14:04:59] [error] [output:es:es.0] HTTP status=403 URI=/_bulk, response: {"error":{"root_cause":[{"type":"security_exception","reason":"no permissions for [indices:data/write/bulk] and User [name=arn:aws:iam::83736106 6829:role/NodeInstanceRole, backend_roles=[arn:aws:iam::837361066829:role/NodeInstanceRole], requestedTenant=null]"}],"type":"security_exception ","reason":"no permissions for [indices:data/write/bulk] and User [name=arn:aws:iam::837361066829:role/NodeInstanceRole, backend_roles=[arn:aws: iam::837361066829:role/NodeInstanceRole], requestedTenant=null]"},"status":403}

i ve created master usr for aws es

what should i do?

azizonick avatar May 19 '21 14:05 azizonick

@azizonick The error output is very clear. The problem is that the IAM user which Fluent Bit is using does not have permissions to write to your cluster. You need to read about IAM permissions and ES permissions. And give this IAM identity permission to the cluster.

This is not a fluent bit issue.

https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-ac.html#es-ac-types-identity

PettitWesley avatar May 19 '21 18:05 PettitWesley

"type":"security_exception","reason":"no permissions for [indices:data/write/bulk] For anybody facing this and other similar security errors, in my case they were caused by the OpenSearch domain being configured with Fine-grained access control. With such configuration, you need to give the proper permissions to the IAM role being used by fluent-bit in the OpenSearch admin console:

Screenshot from 2024-03-25 16-43-53

dbaltor avatar Mar 25 '24 16:03 dbaltor