我正在尝试通过 ACME 提供程序使用 Terraform 和 Letsencrypt 在 Azure 应用程序网关 v2.0 中创建 azurerm backend_http_settings。
我可以成功创建证书并将 .pfx 导入前端 https 侦听器,acme 和 azurerm 提供程序提供了处理 pkcs12 所需的一切。
不幸的是,后端需要一个 .cer 文件,大概是用 base64 编码的,而不是 DER,无论我尝试什么,我都无法让它工作。我的理解是,letsencrypt .pem 文件对此应该没问题,但是当我尝试使用 acme 提供者的 certificate_pem 作为trusted_root_certificate 时,我收到以下错误:
错误:创建/更新应用程序网关“agw-frontproxy”(资源组“rg-mir”)时出错:network.ApplicationGatewaysClient#CreateOrUpdate:发送请求失败:StatusCode=400 -- 原始错误:Code="ApplicationGatewayTrustedRootCertificateInvalidData" Message="Data对于证书 .../providers/Microsoft.Network/applicationGateways/agw-frontproxy/trustedRootCertificates/vnet-mir-be-cert 无效。” 详细信息=[]
terraform 计划工作正常,上述错误发生在 terraform 应用期间,当 azurerm 提供者对证书数据无效感到愤怒时。我已将证书写入磁盘,它们看起来与我预期的一样。这是带有相关代码的代码片段:
locals {
https_setting_name = "${azurerm_virtual_network.vnet-mir.name}-be-tls-htst"
https_frontend_cert_name = "${azurerm_virtual_network.vnet-mir.name}-fe-cert"
https_backend_cert_name = "${azurerm_virtual_network.vnet-mir.name}-be-cert"
}
provider "azurerm" {
version = "~>2.7"
features {
key_vault {
purge_soft_delete_on_destroy = true
}
}
}
provider "acme" {
server_url = "https://acme-staging-v02.api.letsencrypt.org/directory"
}
resource "acme_certificate" "certificate" {
account_key_pem = acme_registration.reg.account_key_pem
common_name = "cert-test.example.com"
subject_alternative_names = ["cert-test2.example.com", "cert-test3.example.com"]
certificate_p12_password = "<your password here>"
dns_challenge {
provider = "cloudflare"
config = {
CF_API_EMAIL = "<your email here>"
CF_DNS_API_TOKEN = "<your token here>"
CF_ZONE_API_TOKEN = "<your token here>"
}
}
}
resource "azurerm_application_gateway" "agw-frontproxy" {
name = "agw-frontproxy"
location = azurerm_resource_group.rg-mir.location
resource_group_name = azurerm_resource_group.rg-mir.name
sku {
name = "Standard_v2"
tier = "Standard_v2"
capacity = 2
}
trusted_root_certificate {
name = local.https_backend_cert_name
data = acme_certificate.certificate.certificate_pem
}
ssl_certificate {
name = local.https_frontend_cert_name
data = acme_certificate.certificate.certificate_p12
password = "<your password here>"
}
# Create HTTPS listener and backend
backend_http_settings {
name = local.https_setting_name
cookie_based_affinity = "Disabled"
port = 443
protocol = "Https"
request_timeout = 20
trusted_root_certificate_names = [local.https_backend_cert_name]
}
如何让 AzureRM 应用程序网关将 ACME .PEM 证书作为 AGW SSL 端到端配置中的trusted_root_certificates?