【问题标题】:How to bind a custom TLS/SSL certificate to an Azure App Service app using Python?如何使用 Python 将自定义 TLS/SSL 证书绑定到 Azure App Service 应用程序?
【发布时间】:2022-09-30 04:46:33
【问题描述】:

Microsoft Azure 文档中有一篇文章介绍了如何从门户网站Add a TLS/SSL certificate in Azure App Service。该页面链接到how to do the same thing from using the Azure cli 上的文档。

我的目标是做同样的事情,但使用本机 Python。我一直在查看azure.mgmt.web 包的文档,包括WebSiteManagementClient class 的文档。

问题: 有没有办法使用本机 Python 上传和绑定 PKCS12 私钥证书到 Azure Web 应用程序?我愿意考虑替代方案,例如上传公钥证书或使用 subprocess module 调用 Azure CLI 工具。

这是我到目前为止的代码:

from azure.mgmt.web import WebSiteManagementClient 
from azure.identity import ClientSecretCredential

# Assume client_id, secret, tenant, resource_group, web_app_name are 
# appropriately declared and instatiated

credentials = ClientSecretCredential(client_id=client_id, 
                                     client_secret=secret,
                                     tenant_id=tenant)

with WebSiteManagementClient(credentials, subscription_id) as mng:
    web_app = mng.web_apps.get(resource_group, web_app_name)
    app_config = mng.web_apps.get_configuration(resource_group, web_app_name)

    # TODO: upload Private Key (PKCS12) here

    标签: python azure ssl azure-web-app-service pkcs#12


    【解决方案1】:
    • Azure cli 确实提供了将证书上传到应用服务的命令。 命令是:
    
    az webapp config ssl upload
    
    
    • 现在我们可以使用子进程来执行命令。首先,我们将设置订阅然后我们将执行上传命令
    
    import  subprocess
    
    subprocess.call(' az account set -s <subscription name >', shell=True)
    
    subprocess.call(' az webapp config ssl upload --certificate-file <file path of certificate> --certificate-password {certificate-password} --name <name of app> --resource-group <name of resource group>', shell=True)
    
    

    在 azure cli 命令上参考以下documentation

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 2019-03-26
      • 1970-01-01
      • 2017-01-04
      相关资源
      最近更新 更多