无法使用API Key和NLog.Targets.ElasticSearch进行身份验证

jslywgbw  于 5个月前  发布在  ElasticSearch
关注(0)|答案(2)|浏览(47)

我无法让NLog.Targets.ElasticSearch使用APIKey连接到本地ElasticSearch示例。
我的nlog.config有以下功能:

<target xsi:type="BufferingWrapper" name="elasticSearch" flushTimeout ="5000">
      <target xsi:type="ElasticSearch" uri="https://dev.myinstance.com:9200" 
              includeAllProperties="true" 
              apiKey="MUhUUG1ZQUJFWE5GNDlPT3J5S3c123456783JRQS1CM1JtQVJzUWppdw=="
              apiKeyId="1HTPmYABEXNF49OOryKw"
              documentType=""
              index="test-${date:format=yyyy.MM.dd}"
              name="test">
      </target>
    </target>

字符串
API密钥已使用curl验证:

curl --insecure -H "Authorization: ApiKey MUhUUG1ZQUJFWE5GNDlPT3J5S3c123456783JRQS1CM1JtQVJzUWppdw==" https://dev.myinstance.com:9200/_security/api_key?pretty
{
  "api_keys" : [
    {
      "id" : "1HTPmYABEXNF49OOryKw",
      "name" : "test_import",
      "creation" : 1651847966642,
      "invalidated" : false,
      "username" : "elastic",
      "realm" : "reserved",
      "metadata" : { }
    }
  ]
}


然而,nlog不能auth:

Exception: Elasticsearch.Net.ElasticsearchClientException: Failed to ping the specified node. Call: Status code 401 from: HEAD
---> Elasticsearch.Net.PipelineException: Failed to ping the specified node. 
---> Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration. 
---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.


我试着把requireAuth加到nlog.config上,但没有成功。

cmssoen2

cmssoen21#

这取决于版本4中的NLog版本,我可以使用此配置连接并添加日志,我认为您应该使用用户名和密码而不是Apikey

includeAllProperties="true"
   documentType=""
   requireAuth ="true"
   username ="xxxxxx"
   password ="xxxxxxxxxx"

字符串

jecbmhm3

jecbmhm32#

我在这方面也遇到了一些问题。
在我的情况下,这个问题与授权头的格式不正确有关。
我使用的是Serilog.Settings.Configuration,因此我的所有配置都位于appsettings.json
docs头被格式化:
Authorization: ApiKey ...
但如果你使用Serilog.Settings.Configuration分隔符号是=
Authorization=ApiKey ...

相关问题