everyone.
I am a beginner on Internet and Azure. I have a question about adding a certificate to a listener of an Azure application gateway with Python. I describe my problem in detail as follows.
1. Background
The Azure environment I use is:
Resource group name: My_ResourceGroup
Subscription ID: sub_id
Tenant ID: tenant_id
Client: my_client
Service principal password: sp_password
2. Top-domain and sub-domain
In resource group My_ResourceGroup
, there are two Azure DNS providers with zones contoso.com
and chen.contoso.com
respectively. The contoso.com
is the top domain while the chen.contoso.com
is the sub-domain.
For chen.contoso.com
, I created an A record with name www
and IP 10.10.10.10
(note that this IP is just used for testing). I also generated a certificate (cert.pfx
file) for this domain in order to use HTTPS.
3. Install cert.pfx
certificate to a listener
I have a off-the-shelf Azure application gateway contoso-appgw
in resource group My_ResourceGroup
. In this gateway, there is a listener contoso-appgw-hl
and there has been a certificate cert0.pfx
in this listener.
What I want to do is appending (or, installing) the cert.pfx
certificate to the listener contoso-appgw-hl
with Azure Python SDK. After this operation, there should be two certificates in listener contoso-appgw-hl
: cert0.pfx
(the old one) and cert.pfx
(the new one).
4. My code and the references
My Python code is as follows:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.network import NetworkManagementClient
# Replace this with your subscription id
subscription_id = 'sub_id'
# Tenant ID for your Azure subscription
TENANT_ID = 'tenant_id'
# Your service principal App ID
CLIENT = 'client'
# Your service principal password
KEY = 'sp_password'
credentials = ServicePrincipalCredentials(
client_id = CLIENT,
secret = KEY,
tenant = TENANT_ID
)
network_client = NetworkManagementClient(credentials, subscription_id)
network_client.application_gateways.create_or_update(
'My_ResourceGroup',
'contoso-appgw',
{
'location': 'East US 2',
'http_listeners': [
{
'name': 'contoso-appgw-hl',
'protocol': 'Https',
'ssl_certificate': {
'data': 'cert.pfx',
'name': 'chenkui',
'password': '123abc'
}
}
]
}
)
I wrote my code based on the following resources:
- Sample code: azure application manage sample code
- Azure document: definition of create_or_update function
Note that the cert.pfx
in my code is a Base-64 format certificate because based on the document a Base-64 format certificate is needed.
5. Error message
The above code is failed. The error message shown in Azure Portal --> contoso-appgw --> Activity log
of the above code is:
Operation name:
Create or Update Application Gateway
Error code:
InvalidRequestFormat
Message:
Cannot parse the request.
Even I use the Azure Portal (i.e. instead of using Python code, use GUI Portal in browser), adding the certificate is also failed. The error message shown in Azure Portal --> contoso-appgw --> Activity log
is:
Operation name:
Create or Update Application Gateway
Error code:
ApplicationGatewaySslCertificateDataMustBeSpecified
Message:
Data must be specified for Certificate /subscriptions/c72b5b1b-771e-4b65-ba34-a7db981c9dcf/resourceGroups/My_ResourceGroup/providers/Microsoft.Network/applicationGateways/contoso-appgw/sslCertificates/chenkui.
6. My question
My questions are given as follows:
- What are the meaning of these error messages?
- Why are these errors given?
- What is the problem of my code and how to solve it?
Thank you very much!