centos - elasticsearch-create-enrollment-token证书https环境下无法生成口令

 

问题描述:

自行生成的证书,启用了https后,es8无法生成口令

./bin/elasticsearch-create-enrollment-token -s kibana --url "https://172.16.8.8:9200"

提示

ERROR: Unable to create an enrollment token. Elasticsearch node HTTP layer SSL configuration Keystore doesn't contain any PrivateKey entries where the associated certificate is a CA certificate

在其他地方看见也有类似的提问没有找到解决办法。
https://discuss.elastic.co/t/...

请教下如何解决?


 

第 1 个答案:

This Q&A in English:my github pages

错误分析

错误信息中说的是,ES 节点的 HTTP 层 SSL 配置的 Keystore 不包含 PrivateKey 类型的证书,这里你可以用命令去验证一下:

keytool -keystore config/certs/<your_http_pkcs_ca_name.p12> -list

结果大概如下:

ca, Sep 6, 2022, trustedCertEntry,
Certificate fingerprint (SHA-256): 25:27:7D:EE:FE:F6:54:57:47:BE:B5:10:C4:90:DF:28:BF:1B:3B:F9:5E:47:F5:34:5F:03:38:1E:84:0A:23:E7
http, Sep 6, 2022, PrivateKeyEntry,
Certificate fingerprint (SHA-256): D4:EF:60:2C:E5:2D:4C:A8:33:C0:49:44:F4:B5:38:19:92:97:72:CB:5D:85:20:A4:97:9B:90:24:D0:0C:D1:FB

其中的 TrustedCertEntry 是在官方文档 Basic Security plus HTTPS 步骤中生成 HTTP PKCS12 Keystore 时,使用在 Basic Security 步骤生成的 Keystore 作为 CA Cert 自动导入的。

但 ES 需要的是一个证书颁发机构提供的 PrivateKeyEntry,也就是说,你需要的是像下面这样的输出:

http_ca, Sep 6, 2022, PrivateKeyEntry,
Certificate fingerprint (SHA-256): 9E:56:B1:38:F7:49:C7:7D:07:F0:E1:8A:D6:EC:9B:56:DF:86:7D:D6:90:46:86:77:99:6B:D1:9E:9C:4F:F0:03

因此我们把上面 TrustedCertEntry 替换为 PrivateKeyEntry 即可。


解决步骤

Step 1

注意: 这一步一般我们都已经完成了,如果没有后续做什么操作去改变已生成的 Keystore,可以跳过这一步。

按照官方文档 Basic Security 操作会得到一个包含了 CA Cert 的 PKCS12 Keystore,默认文件名是 elastic-stack-ca.p12

通过 Basic Security plus HTTPS 生成 HTTP PKCS12 Keystore,默认会生成一个压缩文件,解压后得到默认文件名是 http.p12 的 Keystore

Step 2

把包含 CA Cert 的 Keystore 作为 PrivateKeyEntry 类型重新导入:

keytool -importkeystore -destkeystore <filename-your-HTTP-PKCS12.p12> -srckeystore <filename-PKCS12-contains-CA-Cert.p12> -srcstoretype PKCS12

会被问是否覆盖:

Importing keystore config/certs/elastic-stack-ca.p12 to config/certs/http.p12...
Enter destination keystore password:
Enter source keystore password:
Existing entry alias ca exists, overwrite? [no]: yes
Entry for alias ca successfully imported.
Import command completed: 1 entries successfully imported, 0 entries failed or cancelled

验证一下:

keytool -keystore <your-ES-HTTP-PKCS-path.p12> -list

如果以上操作没有差错,会出现像下面的结果:

Keystore type: PKCS12
Keystore provider: SUN

Your keystore contains 2 entries
ca, Sep 5, 2022, PrivateKeyEntry,
Certificate fingerprint (SHA-256): 53:F4:9A:9D:56:A9:3A:AF:90:94:41:FA:D7:15:3F:DF:C1:39:AC:BA:FF:12:44:C0:36:4D:15:4C:20:14:1E:3D
http, Sep 5, 2022, PrivateKeyEntry,
Certificate fingerprint (SHA-256): EF:8D:78:EC:F0:C5:97:1B:7B:58:EF:5F:E3:73:A5:D0:7E:1B:FE:B3:75:B0:B4:D9:CB:80:FC:B3:8E:5D:A5:74

此时之前的 TrustedCertEntry 已经变成 PrivateKeyEntry.

此外记得按官方文档,检查/添加 ES 配置中的证书的密码到 ES 的 Keystore 里:

bin/elasticsearch-keystore [show|add] xpack.security.http.ssl.keystore.secure_password

如果有设置 transport 证书,也同样需要添加:

bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password

接下来启动 node 之后就可以使用 bin/elasticsearch-create-enrollment-token 生成 token 了:

bin/elasticsearch-create-enrollment-token -s [kibana|node]

其他

官方已经有一个 issue 来追踪这个问题:issue: Generating enrolment token for Kibana should not require the CA key


vue.js - 在elementUI的 <el-table>的自定义列上滚动鼠标,报错:问题出现的环境elementUI的 <el-table>标签上图中【操作】这一列是我自定义的列,设置了fixed 悬浮在表格右 ...