本文介绍了如何在Nest Elastic Client中使用X509证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在从Elastic Search 1.7升级到5.2.我知道没有升级路径,这很好.我们最初遇到的一个问题是Nest和ElastiSearch.Net,因为它只能使用基本身份验证,所以无法附加X509证书.为了解决这个问题,我们制作了现有github存储库的副本,并直接修改了代码以允许它.最终,正是由于我们现在有了自定义代码,我们才不能仅仅使用nuget软件包,这最终使我们无法升级.

I am currently upgrading from Elastic Search 1.7 to 5.2. I know there is no upgrade path, which is fine. One problem we had originally is with Nest and ElastiSearch.Net there was no way to attach an X509 certificate as it only had the ability to use Basic Authentication. To get around that we made copies of the existing github repos and modified the code directly to allow it. This ultimately is what kept us from upgrading for so long since we couldn't just use the nuget packages, because we now had custom code.

现在我们正在升级,我正在尝试找出是否已纠正.或者,至少有任何钩子可以用来获取ElasticClient(在Nest中)或ElasticLowLevelClient(在ElasticSearch.Net中)以获取证书并在进行呼叫时将其传递.

Now that we are upgrading I'm trying to find out if this was ever remedied. Or, at the very least are there any hooks that we can use to get the ElasticClient(in Nest) or the ElasticLowLevelClient (in ElasticSearch.Net) to take in a certificate and pass it on when making the call.

另一个选择是使用PUT请求在初始创建时创建索引,这是我们需要证书的地方.我们存在的问题是,由于我们在模型中添加了一些自定义属性,因此我们需要使用AutoMap方法,并且需要这些属性来进行索引创建.我不确定是否有一种方法可以将给定模型的AutoMap结果生成为JSON,而仅使用webclient附加证书即可.

Another option, is to use a PUT request to create the Index on initial creation, which is where we are needing the certificate. The issue we have there is we require the use of the AutoMap method since we have some custom attributes added on our models, and need those to go in on Index creation. I'm not sure if there is a way to generate that result of AutoMap for a given model to JSON, and just use a webclient to attach the certificate.

如果您需要更多详细信息,请告诉我.

Let me know if you need anymore details.

推荐答案

可以自定义NEST和Elasticsearch.Net一直使用到1.x的连接.这是通过为传递给ElasticClient构造函数的ConnectionSettings实例提供您自己的IConnection实现来实现的.

It's possible to customise the connections that both NEST and Elasticsearch.Net use all the way back to 1.x. This is done by providing your own implementation of IConnection to the ConnectionSettings instance that is passed to the ElasticClient constructor.

首先创建您的自定义IConnection;最容易从HttpConnection

First create your custom IConnection; it's easiest to derive from HttpConnection

public class HttpConnectionWithClientCertificate : HttpConnection
{
    protected override HttpWebRequest CreateHttpWebRequest(RequestData requestData)
    {
        var request = base.CreateHttpWebRequest(requestData);
        // add the certificate to the request
        request.ClientCertificates.Add(new X509Certificate("path_to_cert"));
        return request;
    }
}

然后将其传递给ConnectionSettings

var node = new Uri("http://localhost:9200");
var connectionPool = new SingleNodeConnectionPool(node);
var connection = new HttpConnectionWithClientCertificate();
var settings = new ConnectionSettings(connectionPool, connection);
var client = new ElasticClient(config);

这篇关于如何在Nest Elastic Client中使用X509证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:47