Azure已将证书导入到Key Vault:主题和SAN为空白/空

kmbjn2e3  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(156)

我正在使用Terraform从Certbot为Azure中的网站应用程序网关部署新证书。在过去,以前用新证书替换证书工作正常。这次我从Terraform得到了这个错误:
│错误:keyvault.BaseClient#RecoverDeletedCertificate:未能响应请求:404 --原始错误:autorest/azure:服务返回错误。状态=404代码=“CertificateNotFound”消息=“在此密钥保管库中未找到(名称/ID)为prod-cert-2023-03-002的证书。如果您最近删除了此证书,则可以使用正确的恢复命令恢复它。有关解决此问题的帮助,请参阅https://go.microsoft.com/fwlink/?linkid=2125182" │ │ with azurerm_key_vault_certificate.cert,│ onwww. example www.example.com :│ 135:resource“azurerm_key_vault_certificate”“cert”

原来certbot现在默认返回ECDSA证书:https://community.letsencrypt.org/t/ecdsa-certificates-by-default-and-other-upcoming-changes-in-certbot-2-0/177013

所以,很明显,我可以特别要求Certbot给予我一个RSA证书,但升级到现代系统似乎是个好主意。
Azure希望在pkcs 12中导入证书:

openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out certificate.pfx -certfile chain.pem

这是我在terraform的钥匙库

resource "azurerm_key_vault_certificate" "cert" {
  name         = var.key_vault_newcert_name
  key_vault_id = azurerm_key_vault.vmss.id

  certificate {
    contents = filebase64("certificate.pfx")
    password = ""
  }

  certificate_policy {
    issuer_parameters {
      name = "Unknown"
    }

    key_properties {
      curve      = "P-256"
      exportable = true
      key_size   = 256
      key_type   = "EC"
      reuse_key  = true
    }

    secret_properties {
      content_type = "application/x-pkcs12"
    }
  }

}

terraform apply成功,并且,通过Web门户,我发现新证书在那里,但主题和SAN字段为空/空白。
如果我读取.pfx文件:

openssl pkcs12 -in certificate.pfx -info -nodes

主题看起来是正确的:

subject=/CN=correctdomain.com

怎么回事?

3zwjbxry

3zwjbxry1#

terraform apply成功,并且,通过Web门户,我发现新证书在那里,但主题和SAN字段为空/空白。
我尝试了下面的代码将证书从我的本地机器导入到Azure密钥库,CN和SAN如下所示:

  • 在导入证书时,请确保在terraform代码中添加subjectsubject_alternative_names,如下所示:-*
x509_certificate_properties {

subject  =  "CN=silicon.com, SAN=silicon.com"

subject_alternative_names {

dns_names  =  [

"silicon.com"

]

}

key_usage  =  [

"digitalSignature"

]

validity_in_months  =  12

}

}

完整编码:-

terraform {

required_providers {

azurerm  =  {

source = "hashicorp/azurerm"

version = "3.10.0"

}

}

}

  

provider  "azurerm" {

features {

key_vault {

purge_soft_delete_on_destroy  =  true

recover_soft_deleted_key_vaults  =  true

}

}

}

  

resource  "azurerm_key_vault"  "example" {

name  =  "siliconkeyvault098765"

location  =  "Australia East"

resource_group_name  =  "siliconrg98"

sku_name  =  "standard"

tenant_id  =  "<tenant-id>"

}

  

resource  "azurerm_key_vault_certificate"  "example" {

name  =  "silicon"

key_vault_id  =  azurerm_key_vault.example.id

  

certificate {

contents  =  filebase64("C:/silicon.pfx")

password  =  "siliconuser"

}

  

certificate_policy {

issuer_parameters {

name  =  "Self"

}

  

key_properties {

exportable  =  true

key_size  =  2048

key_type  =  "RSA"

reuse_key  =  false

}

  

secret_properties {

content_type  =  "application/x-pkcs12"

}

  

x509_certificate_properties {

subject  =  "CN=silicon.com, SAN=silicon.com"

subject_alternative_names {

dns_names  =  [

"silicon.com"

]

}

key_usage  =  [

"digitalSignature"

]

validity_in_months  =  12

}

}

}

输出:-

Portal CN和SAN可见:-

我在pfx中导出了我本地机器中的证书,密码如下:-
转到certmgr〉Certificates - Current User〉Personal〉certificates〉单击您导入的证书〉All Tasks〉Export〉选择Yes Export the private key〉Personal Information Exchange〉在安全选项中选择并键入您的密码〉将证书导出到本地所需的位置在我的方案中,我将其导出到C盘中。

参考:-

Terraform - How to attach SSL certificate stored in Azure KeyVault to an Application Gateway - Stack Overflow按分析员余额

相关问题