我正在尝试在 Elasticsearch 集群上为客户端设置 HTTPS。当我通过以下命令使用 certbot 从集群生成 SSL 证书时,它工作正常:
certbot certonly --standalone
我的 Elasticsearch 集群配置如下:
# elasticsearch.yml
cluster.initial_master_nodes: 10.132.0.3
cluster.name: elasticsearch
discovery.seed_hosts: 10.132.0.3:9200
network.host: 10.132.0.3
node.name: node-1
xpack.security.http.ssl.certificate: /etc/elasticsearch/ssl/my-subdomain.XXXX.com/fullchain.pem
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.key: /etc/elasticsearch/ssl/my-subdomain.XXXX.com/privkey.pem
xpack.security.http.ssl.verification_mode: certificate
xpack.security.transport.ssl.enabled: true
因此,我设法使用我的登录名和密码在我的 elasticsearch 上通过以下命令在 HTTPS 中进行身份验证:
curl https://my-subdomain.XXXX.com:9200 -u username:password
我的问题是我现在想做同样的操作,但是通过 Terraform 使用ACME 提供程序生成 SSL 证书 ,更准确地说是使用资源 "acme_certificate"。这是我的 Terraform 代码:
resource "acme_certificate" "elastic" {
account_key_pem = acme_registration.account_registration.account_key_pem
common_name = "${local.subdomain}.${var.domain_name}"
dns_challenge {
provider = "ovh"
config = {
OVH_ENDPOINT = var.ovh_endpoint
OVH_APPLICATION_KEY = var.ovh_application_key
OVH_APPLICATION_SECRET = var.ovh_application_secret
OVH_CONSUMER_KEY = var.ovh_consumer_key
}
}
}
从 Terraform 资源“acme_certificate”我得到以下输出:
- “certificate_pem”将成为我的“cert.pem”文件(但我没有在我的 Elasticsearch 设置中使用它)
- “发行人_pem”
- “private_key_pem”将成为我的“privkey.pem”文件
因此,我错过了通过将“certificate_pem”和“issuer_pem”关联起来构建的“fullchain.pem”文件,如下所示(我的错误可能在那里):
resource "local_file" "fullchain" {
content = "${acme_certificate.elastic.certificate_pem}${acme_certificate.elastic.issuer_pem}"
filename = "/my/local/path/fullchain.pem"
}
我的“fullchain.pem”文件如下所示:
-----BEGIN CERTIFICATE-----
MIIFQjCCBCqgAwIBAgISBBxb+NtLDbApY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VuG
WCLKTVXkcGdtwlfFRjlBz4pYg1htmf5X6DYO8A4jqv2Il9DjXA6USbW1FzXSLr9O
he8Y4IWS6wY7bCkjCWDcRQJMEhg76fsO3txE+FiYruq9RUWhiF1myv4Q6W+CyBFC
Dfvp7OOGAN6dEOM4+qR9sdjoSYKEBpsr6GtPAQw4dy753ec5
-----END CERTIFICATE-----
以与使用相同的方式cerbot
,我使用 Terraform 将我的证书注入 Elasticsearch 并验证 Elastic 用户是否具有正确的权限(使用chmod
andchown
命令) elasticsearch 服务重新启动正常,但是当我尝试连接时它给了我以下错误:
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
我不明白问题是什么,我的印象是 Terraform 返回的证书不正确。但是当我用 cerbot 测试它们的有效性时,一切似乎都很好:
openssl x509 -enddate -noout -in cert.pem # notAfter=Nov 16 13:55:54 2021 GMT
openssl x509 -enddate -noout -in fullchain.pem # notAfter=Nov 16 13:55:54 2021 GMT
谢谢你的帮助 !