serilog-sinks-elasticsearch
serilog-sinks-elasticsearch copied to clipboard
Configure authentication like api key from appsettings.json
Does this issue relate to a new feature or an existing bug?
- [ ] Bug
- [x] 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"
}
}
}
}
}
Hi,
you can use like this
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "https://.............../;",
"connectionGlobalHeaders": "Authorization=Basic {XXX}",
}
}
where {XXX} is {username}:{password} in base64 format
Thanks for the suggestion. However {username}:{password} is different from an API key.
when is this going to be implemented?
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.
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