serilog-sinks-elasticsearch icon indicating copy to clipboard operation
serilog-sinks-elasticsearch copied to clipboard

Using appsetting.json: "connectionGlobalHeaders": "Authorization=Basic cause error: illegal_argument_exception Reason: "Illegal base64 character

Open pczabans opened this issue 3 years ago • 2 comments

A few questions before you begin:

Is this an issue related to the Serilog core project or one of the sinks or community projects.
This issue list is intended for Serilog Elasticsearch Sink issues. If this issue relates to another sink or to the code project, please log on the related repository. Please use Gitter chat and Stack Overflow for discussions and questions.

Does this issue relate to a new feature or an existing bug?

  • [x ] Bug
  • [ ] New Feature

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package.

8.4.1

What is the target framework and operating system? See target frameworks & net standard matrix.

  • [ ] netCore 2.0
  • [ ] netCore 1.0
  • [ ] 4.7
  • [ ] 4.6.x
  • [ ] 4.5.x
  • [ X] 5.0

Please describe the current behavior? Selflog: 2021-09-15T14:06:35.3773884Z Caught exception while preforming bulk operation to Elasticsearch: Elasticsearch.Net.ElasticsearchClientException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration.. Call: Status code 401 from: POST /_bulk. ServerError: Type: security_exception Reason: "invalid basic authentication header encoding" CausedBy: "Type: illegal_argument_exception Reason: "Illegal base64 character 2d""

Please describe the expected behavior? No errors in selflog

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem

Configuration in application Using appsetting.json: "connectionGlobalHeaders": "Authorization=Basic " again ES with auth.

pczabans avatar Sep 16 '21 11:09 pczabans

@pczabans have you tried with

"connectionGlobalHeaders": "Authorization=Basic YWRtaW46YWRtaW4="

YWRtaW46YWRtaW4= this is a base64 string with credential like username:password

AntoCanza avatar Nov 18 '21 10:11 AntoCanza

Hello @AntoCanza, this is a bit late but thanks, it works, you can configure basic auth using appsettings.json.

  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Elasticsearch" ],
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Warning",
        "System": "Error"
      }
    },
    "WriteTo": [
      { "Name": "Console" },
      {
        "Name": "Elasticsearch",
        "Args": {
          "nodeUris": "http://elasticsearch-url:9200",
          "indexFormat": "myapi-logs-{0:yyyy.MM}",
          "autoRegisterTemplate": true,
          "connectionGlobalHeaders": "Authorization=Basic dXNlcm5hbWU6cGFzc3dvcmQ=" // dXNlcm5hbWU6cGFzc3dvcmQ= is username:password encoded in base64
        }
      }
    ],
    "Enrich": [ "FromLogContext" ],
    "Properties": {
      "Application": "YourApplicationName"
    }
  },
  "AllowedHosts": "*"
}

MehdiRifi avatar Nov 10 '23 15:11 MehdiRifi