danieleteti / loggerpro

An modern and pluggable logging framework for Delphi
Apache License 2.0
357 stars 91 forks source link

Authentication on TElasticSearchAppender #82

Open Basti-Fantasti opened 1 year ago

Basti-Fantasti commented 1 year ago

I've installed an ELK stack using docker on a local VM to play around with ElasticSearch.

The services seem to be up and running and listening on the default ports. When calling the URL like it is found in the LoggerProConfig unit for the elastic search demo (demo 120)

_RESTAppender := TLoggerProElasticSearchAppender.Create('http://localhost', 9200, 'loggerpro');

There seem to be no option for authentication. When calling any request from the supplied demo program, this error is thrown:

ExceptionMessage="{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/loggerpro/_doc]","header":{"WWW-Authenticate":["Basic realm=\"security\" charset=\"UTF-8\"","ApiKey"]}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/loggerpro/_doc]","header":{"WWW-Authenticate":["Basic realm=\"security\" charset=\"UTF-8\"","ApiKey"]}},"status":401}"

When calling the URL directly in a browser or using a rest client like postman an authentication has to be send together with the request. After a successful authentication, a valid json object is shown:

{
  "name" : "elasticsearch",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "Jt7XTXq6Q4q9ydcDFgDrdg",
  "version" : {
    "number" : "8.10.4",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "b4a62ac808e886ff032700c391f45f1408b2538c",
    "build_date" : "2023-10-11T22:04:35.506990650Z",
    "build_snapshot" : false,
    "lucene_version" : "9.7.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

So it there already a way on how to pass the credentials? Or does the authentification module need to be added?

Best regards Bastian

Basti-Fantasti commented 1 year ago

I saw, that the ElasticSearch Logger is a child object of the Restful Logger which is missing the authentication modes as well. Maybe it would be a good idea to implement the standard authentication modes in the base class (Basic auth, Bearer Token, Generic API Key, etc)