无法使用指定的节点进行身份验证- ElasticSearch

qzlgjiam  于 2023-03-29  发布在  ElasticSearch
关注(0)|答案(3)|浏览(225)

使用nest client 7.2.1连接到azure中的elastic db内部负载均衡器。
异常:无法为报警事件创建数据库索引。从HEAD上的不成功(401)低级调用生成的无效NEST响应:/ #该API调用的审计跟踪:- [1] BadResponse:节点:http://192.168.0.4:9200/PipelineException Took:00:00:00.0506796 # OriginalException:搜索引擎异常:无法使用指定的节点进行身份验证。请尝试验证您的凭据或检查您的Shield配置。调用:状态代码401来自:HEAD / ---〉Elasticsearch.Net.PipelineException:无法使用指定的节点进行身份验证。请尝试验证您的凭据或检查您的Shield配置。at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails详细信息,IElasticsearchResponse响应)at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)at Elasticsearch.Net.Transport 1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters) --- End of inner exception stack trace --- # Audit exception in step 1 BadResponse: Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration. at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response) at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData) at Elasticsearch.Net.Transport 1.Request[TResponse](HttpMethod method method,String path,PostData data,请求参数请求参数)#请求:#响应:PUT上的不成功(401)低级调用:/asx-sleepquality #本次API调用的审计线索:- [1] BadResponse:节点:http://192.168.0.4:9200/PipelineException Took:00:00:00.4294201 # OriginalException:搜索引擎异常:无法使用指定的节点进行身份验证。请尝试验证您的凭据或检查您的Shield配置。调用:状态代码401来自:PUT /asx-sleepquality. ServerError:类型:security_exception原因:“缺少REST请求的身份验证凭据[/asx-sleepquality]”---〉Elasticsearch.Net.PipelineException:无法使用指定的节点进行身份验证。请尝试验证您的凭据或检查您的Shield配置。at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails详细信息,IElasticsearchResponse响应)at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)at Elasticsearch.Net.Transport 1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters) --- End of inner exception stack trace --- # Audit exception in step 1 BadResponse: Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration. at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response) at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData) at Elasticsearch.Net.Transport 1.Request[TResponse](HttpMethod method method,String path,PostData data,请求参数请求参数)#请求:#响应:

const string Url = "http://192.168.0.4:9200"; 
            var settings = new ConnectionSettings(new Uri(Url));
            ElasticSearchClient = new ElasticClient(settings);

            var indexes = GetAsxIndexes();

            var response = ElasticSearchClient.Ping().DebugInformation;
vecaoik1

vecaoik11#

下面的代码解决了我的问题

//Reading the configuration from appsettings.json
var elasticConfig = hostContext.Configuration.GetSection("ElasticSearch");

// 1. Register NEST ElasticClient
var settings = new ConnectionSettings(new Uri(elasticConfig["Uri"]))
                    .BasicAuthentication(elasticConfig["UserName"], elasticConfig["Password"])
                    .DefaultIndex(elasticConfig["DefaultIndex"]);

settings.PrettyJson();

var client = new ElasticClient(settings);
gcxthw6b

gcxthw6b2#

您正在尝试根据错误消息向启用了安全性的Elasticsearch集群发出请求
无法使用指定的节点进行身份验证。请尝试验证您的凭据或检查您的Shield配置。调用:状态代码401来自:头部/
您需要在ConnectionSettings中提供身份验证凭据以供客户机使用

var pool = new SingleNodeConnectionPool(new Uri("http://192.168.0.4:9200"));

var settings = new ConnectionSettings(pool)
    // configure the client with authentication credentials
    .BasicAuthentication("user", "password");

var client = new ElasticClient(settings);
kgsdhlau

kgsdhlau3#

当我启用细粒度访问控制时,我遇到了错误401。使用AwsSigV4HttpConnection对请求进行签名对我有效。参考:https://opensearch.org/blog/aws-sigv4-support-for-clients/

using OpenSearch.Client;
using OpenSearch.Net.Auth.AwsSigV4;

namespace Application
{
    class Program
    {
        static void Main(string[] args)
        {
            var endpoint = new Uri("https://search-xxx.region.es.amazonaws.com");
            var connection = new AwsSigV4HttpConnection();
            var config = new ConnectionSettings(endpoint, connection);
            var client = new OpenSearchClient(config);

            Console.WriteLine($"{client.RootNodeInfo().Version.Distribution}: {client.RootNodeInfo().Version.Number}");
        }
    }
}

相关问题