Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Configure authentication like api key from appsettings.json #476

Open
1 of 7 tasks
snebjorn opened this issue Oct 10, 2022 · 5 comments
Open
1 of 7 tasks

Configure authentication like api key from appsettings.json #476

snebjorn opened this issue Oct 10, 2022 · 5 comments

Comments

@snebjorn
Copy link

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

  • Bug
  • New Feature

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package.
serilog.sinks.elasticsearch v8.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

Please describe the current behavior?

Not possible to set api keys from appsettings.json.
Today it has to be done from code

.UseSerilog(
    (context, services, configuration) =>
    {
        configuration.WriteTo.Elasticsearch(
            new ElasticsearchSinkOptions(new Uri("..."))
            {
                ModifyConnectionSettings = (x) =>
                    x.ApiKeyAuthentication(new ApiKeyAuthenticationCredentials("my api key"))
            }
        );
    }
)

Please describe the expected behavior?

It would be handy if we could configure authentication like api keys from appsettings.json

Something like

{
  "Serilog": {
    "Using": ["Serilog.Sinks.Elasticsearch"],
    "WriteTo": {
      "ElasticsearchSink": {
        "Name": "Elasticsearch",
        "Args": {
          "nodeUris": "...",
          "apiKey": "my api key"
        }
      }
    }
  }
}
@ricardodemauro
Copy link

Hi,

you can use like this

{
    "Name": "Elasticsearch",
    "Args": {
        "nodeUris": "https://.............../;",
        "connectionGlobalHeaders": "Authorization=Basic {XXX}",
    }
}

where {XXX} is {username}:{password} in base64 format

@snebjorn
Copy link
Author

Thanks for the suggestion. However {username}:{password} is different from an API key.

@TiemenSET
Copy link

when is this going to be implemented?

@mivano
Copy link
Contributor

mivano commented May 24, 2023

When somebody submits a PR for this functionality. Alternatively, look at the sink Elastic itself offers if this is a better match. You can find a link in the readme.

@eharshosh
Copy link

Thanks for the suggestion. However {username}:{password} is different from an API key.

Didn't test it, but from looking at the official API key documentation, it looks like this might work:

        "connectionGlobalHeaders": "Authorization=ApiKey {XXX}",

Where XXX is the base64 encoded API key.
Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants