如何更新Dotnet Serilog Logging Config以处理新的Elasticsearch 8安全性(https,用户名,密码,tls证书)?

eqqqjvef  于 11个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(110)

我已经从7.x升级到了Elastic 8.x。现在我的弹性端点需要使用https连接,并提供用户名、密码和tls证书。
参见示例here
如果我在我的kubernetes集群中使用这种方法只是为了测试连接性,我可以从我的应用程序的容器中 curl Elastic服务。首先,我必须导出tls cert并将cert复制到我的容器中。然后我可以 curl 服务(根据上面的链接):
curl --cacert tls.crt -u elastic:https://elasticsearch-cluster-es-http.eck:9200

{
  "name" : "elasticsearch-cluster-es-default-1",
  "cluster_name" : "elasticsearch-cluster",
  "cluster_uuid" : "YqYl-gTpRd-URcoDhW5t1w",
  "version" : {
    "number" : "8.11.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "76013fa76dcbf144c886990c6290715f5dc2ae20",
    "build_date" : "2023-12-05T10:03:47.729926671Z",
    "build_snapshot" : false,
    "lucene_version" : "9.8.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

字符串
我现在如何更新我的dotnet logger配置来处理新的https、username:password和tls cert要求?我尝试了以下方法但没有成功(也尝试了指纹):

var elasticOptions = new ElasticsearchSinkOptions(new Uri($"https://{elasticServer}"))
            {
                AutoRegisterTemplate = true,
                IndexDecider = (@event, offset) =>
                    string.Format("{0}-{1}-{2:yyyy.MM.dd}", k8sNamespace, appName, offset),
                ModifyConnectionSettings = (settings) =>
                {
                    settings.EnableApiVersioningHeader();
                    settings.ClientCertificate(new X509Certificate2(crtBytes));
                    settings.BasicAuthentication("elastic", "<password>");
                    settings.DeadTimeout(TimeSpan.FromSeconds(300));
                    return settings;
                }
            };


我在应用程序中看到以下错误:

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot


dotnet 8 serilog. sink.elasticsearch:9.0.3 elasticsearch eck:8.11.2

bqjvbblv

bqjvbblv1#

我通过从Kubernetes中抓取Elastic CA secret(name-es-http-ca-internal)并将其添加到我的应用程序docker文件中的ca-certificates.crt文件来解决这个问题:

# add ca cert
COPY docker/ca-certs/elastic.crt /app/elastic.crt
RUN cat /app/elastic.crt >> /etc/ssl/certs/ca-certificates.crt

字符串
以上crt是从公共crt机密值(name-es-http-certs-public)中获得的

byte[] crtBytes = Encoding.ASCII.GetBytes("-----BEGIN CERTIFICATE-----\nMIIEqDCCA5CgA.....");


但是,我想我会采取禁用tls的方法,这样我就不必管理这些证书了。
https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-tls-certificates.html#k8s-disable-tls

相关问题