The Microsoft Azure documentation has an article on how to Add a TLS/SSL certificate in Azure App Service from the web portal. That page links to the documentation on how to do the same thing from using the Azure cli.
My goal is to do the same thing, but using native Python. I’ve been looking at the documentation for the azure.mgmt.web
package, including the documentation for the WebSiteManagementClient
class.
Question: is there a way to upload and bind a PKCS12 private key certificate to an Azure web app using native Python? I am willing to consider alternatives, like uploading a public key certificate or calling the Azure CLI tool using the subprocess
module.
Here’s the code I have so far:
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
2
Answers
The command is :
Refer the following documentation on azure cli commands
I would suggest using Azure Key Vault to store your certificates if possible.
It has a REST API that you should be able to interface with in Python.
The linking to the domain would be done in the initial creation of the key on the azure portal. But there should be another endpoint for that part as well.
To the post in python would look like this: