如何让 AzureRM 应用网关将 ACME .PEM 证书作为 AGW SSL 端到端配置中的 trusted_root_certificates?

问题描述 投票:0回答:1

我试图通过 ACME 提供商使用 Terraform 和 Letsencrypt 在 Azure Application Gateway v2.0 中创建 azurerm backend_http_settings。

我可以成功地创建一个证书,并将.pfx导入到前端https监听器中,acme和azurerm提供商提供了处理pkcs12所需的一切。

不幸的是,后端想要一个.cer文件,大概是base64编码的,而不是DER,无论我怎么尝试,都无法让它工作。我的理解是,一个Letencrypt .pem文件应该是没有问题的,但是当我试图使用acme提供商的certificate_pem作为trusted_root_certificate时,我得到了以下错误。

错误: Error CreatingUpdating Application Gateway "agw-frontproxy" (Resource Group "rg-mir"): network.ApplicationGatewaysClient#CreateOrUpdate: 发送请求失败。StatusCode=400 -- 原始错误。Code="ApplicationGatewayTrustedRootCertificateInvalidData" Message="Data for certificate...providerMicrosoft.NetworkapplicationGatewaysagw-frontproxytrustedRootCertificatesvnet-mir-be-cert is invalid." 。详情=[]

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?

azure terraform x509certificate acme
1个回答
0
投票

对我来说,唯一有效的是使用紧密耦合的Windows工具。如果你遵循下面的文档,它将工作。花2天时间来解决同样的问题:)

微软文档


0
投票

如果您没有指定 任何 这消除了证书的冗余安装,一个在 Web 服务器(在这种情况下是 Traefik 边缘路由器),一个在 AGW 后台。

这就解决了如何正确格式化证书的问题。 不幸的是,我一直无法安装证书,即使是微软支持工程师在电话中也无法安装。 他当时说:"是啊,看起来不错,应该能用,不知道为什么不能用,你能不能用v2网关,完全不在后台安装证书来避免呢?"

v2网关需要静态公网IP和 "Standard_v2 "sku类型和层级才能工作,如上图。

© www.soinside.com 2019 - 2024. All rights reserved.