【发布时间】:2019-01-26 05:04:49
【问题描述】:
我的最终目标是在 Python 脚本中自动执行此过程,因此我首先要熟悉 Azure 门户中所需的工作流。
第 1 步是创建应用服务证书。在代码中,我的调用是: https://management.azure.com/subscriptions/aaaa-bbbb-cccc-dddd/resourceGroups/my-rg/providers/Microsoft.CertificateRegistration/certificateOrders/my-cert-order?api-version=2015-08-01
有效载荷为:
{
"location": "global",
"properties": {
"productType": "StandardDomainValidatedSsl",
"autoRenew": true,
"distinguishedName":"CN=mydomain.com"
}
}
第 2 步是将其与特定的密钥库相关联。同样,在代码中调用是: https://management.azure.com/subscriptions/aaaa-bbbb-cccc-dddd/resourceGroups/my-rg/providers/Microsoft.CertificateRegistration/certificateOrders/my-cert-order/certificates/my-cert?api-version=2015-08-01
有效载荷为
{
"location":"global",
"properties": {
"keyVaultId":"/subscriptions/aaaa-bbbb-cccc-dddd/resourceGroups/my-rg/providers/Microsoft.KeyVault/vaults/my-keyvault",
"keyVaultSecretName":"my-secret-name"
}
}
第 3 步是验证与刚刚创建的证书关联的域。门户中的说明说使用提供的域验证令牌在我的域的根目录中创建一个 TXT 条目。我已经这样做了,但 Azure 不喜欢某些东西,因为它从不报告证书已被验证,即使在几个小时后也是如此。我尝试手动查找我创建的 TXT 记录,它现在肯定可用,所以我认为这不是 Azure 所抱怨的。
我知道门户使用的 REST 调用是验证域所有权,如此处所述:
我尝试在代码中显式进行此调用,我可以看到它返回了 400 错误以及以下 JSON blob:
{
"Code": "CertificateResellerWebService_NOT_FOUND_TOKEN",
"Message": "All remaining domain control tokens were not found",
"Target": null,
"Details": [
{
"Message": "All remaining domain control tokens were not found"
},
{
"Code": "CertificateResellerWebService_NOT_FOUND_TOKEN"
},
{
"ErrorEntity": null
}
],
"Innererror": null
}
它在这里抱怨的域控制令牌是否与域验证令牌相同?无论如何,调用总是失败并出现同样的错误。我不清楚是什么导致了这个问题。任何建议将不胜感激。
更新:这是我用于该过程的主要算法:
token = get_auth_token()
# First, put in a certificate request
cert_order = create_cert_order(token, CERT_NAME)
while cert_order.status_code == 201:
cert_order = get_cert_order(token, CERT_NAME)
cert_order = cert_order.json()
# Then assign it to a specific key vault
cert = update_cert(token, CERT_NAME, KEY_VAULT_ID, KEY_VAULT_SECRET_NAME)
while cert.status_code == 201:
cert = get_cert(token, CERT_NAME)
# Next, create a TXT entry in the root domain matching the
# domain verification token and wait for that record to be
# discoverable by nslookup.
domain_verification_token = cert_order["properties"]["domainVerificationToken"]
create_txt_record(domain_verification_token)
waitfor_txt_record(domain_verification_token)
# Finally, ask to have to domain ownersip verified.
response = verify_domain_ownership(token, CERT_NAME)
if response.status_code != 204:
print("Domain ownership verification failed")
这里引用的函数 create_cert_order、update_cert 和 verify_domain_ownership 代表我上面提到的 REST 调用。我很确定这个工作流程是正确的,但我不知道最终调用失败的原因。
【问题讨论】:
-
为了它的价值,我已经发布了我在这个过程中遵循的主要工作流程。如果有人对完整代码感兴趣,我可以提供。
标签: azure ssl-certificate