To set up an SSL certificate on Azure, you'll need to create a certificate request and then upload it to the Azure portal.
You can create a certificate request using the Azure Key Vault or a third-party tool.
To create a certificate request in Azure Key Vault, you'll need to select the key vault, choose a certificate name, and then select the certificate type.
Azure supports several certificate types, including standard and extended validation certificates.
The standard certificate is suitable for most websites, while the extended validation certificate provides additional security features.
Once you've created the certificate request, you'll need to upload it to the Azure portal.
Prerequisites
Before you start setting up an SSL certificate on Azure, you'll need to meet a few prerequisites.
First, you'll need to create an App Service app. Make sure its App Service plan is in the Basic, Standard, Premium, or Isolated tier.
You can update the tier by following the instructions in the "Scale up an app" documentation.
If you're using a private certificate, ensure it meets all the requirements outlined by Azure App Service.
A free certificate is also an option, but keep in mind that it has specific requirements.
Here's a quick rundown of the App Service plan tiers you'll need to choose from:
- Basic
- Standard
- Premium
- Isolated
Create an SSL Certificate
To create an SSL certificate, you can use a free managed certificate in Azure App Service. This type of certificate is fully managed by Azure and is automatically renewed every six months.
Azure's free managed certificate is issued by DigiCert, but for some domains, you need to explicitly allow DigiCert as a certificate issuer by creating a CAA domain record.
Make sure to meet the prerequisites for your app before creating a free managed certificate. This includes having an A record pointing to your web app's IP address and being on apps that are publicly accessible.
Only custom domains of length up to 64 characters are supported, and the domain name can only contain alphanumeric characters, dashes, and periods. You can create only one managed certificate for each supported custom domain.
Here are the steps to create a free managed certificate:
- In the Azure portal, select App Services and then your app.
- Select Certificates and then Add certificate.
- Select the custom domain for the free certificate and then Validate.
- When validation completes, select Add.
Alternatively, you can obtain a SSL certificate from a trusted Certificate Authority (CA) like DigiCert, GoDaddy, or Cloudflare. This certificate can be uploaded to Azure in the SSL settings of the resource where you want to install it.
Azure Setup
To set up your Azure SSL certificate, start by importing the certificate into your App Service. You can do this by selecting App Services from the left menu, then choosing your app, and navigating to Certificates > Bring your own certificates (.pfx) > Add certificate.
From there, select Import App Service Certificate, and choose the certificate you created. Give the certificate a friendly name, and select Validate. When validation succeeds, select Add. The certificate will then appear in the Bring your own certificates list.
Alternatively, you can import a certificate from your vault to your app. In the Azure portal, select App Services, then your app, and navigate to Certificates > Bring your own certificates (.pfx) > Add certificate. Select Import from Key Vault, then choose the key vault and certificate you want to import. Select Select, Validate, and then Add to complete the import.
If you're using Container Apps, you'll need to upload the SSL certificate to Azure. Navigate to the SSL settings and upload the certificate files, then validate the certificate.
VM Preparation
To create a secure VM, you need to create a resource group with az group create. This will help you organize your Azure resources.
Create a Key Vault with a unique name, all in lowercase, using az keyvault create. This will store your certificate data securely.
Next, create a VM with az vm create, injecting the certificate data from Key Vault with the --secrets parameter. You'll also pass in the cloud-init config with the --custom-data parameter.
It takes a few minutes for the VM to be created, but when it's ready, take note of the publicIpAddress displayed by the Azure CLI. This address will be used to access your site in a web browser.
To allow secure web traffic to reach your VM, open port 443 from the Internet with az vm open-port.
Secure VM
To secure a VM, you'll want to create a secure connection between the VM and the internet. This involves obtaining a certificate, which can be done using Azure Key Vault. To prepare a certificate for use with a VM, you can use the `az keyvault secret list-versions` command to obtain the ID of your certificate.
You'll need to obtain the certificate ID and convert the certificate with `az vm secret format`. This command will assign the output to variables, making it easier to use in the next steps. The certificate data is then injected into the VM using the `--secrets` parameter.
To create a secure VM, you'll use the `az vm create` command, passing in the cloud-init config with the `--custom-data` parameter. This will take a few minutes, after which you can access your site in a web browser using the publicIpAddress displayed by the Azure CLI.
You'll need to open port 443 from the internet using `az vm open-port` to allow secure web traffic to reach your VM. This will ensure that your VM is accessible and secure.
Here are the steps to create a secure VM:
- Obtain the certificate ID using `az keyvault secret list-versions`
- Convert the certificate with `az vm secret format`
- Create a VM using `az vm create` with the `--secrets` and `--custom-data` parameters
- Open port 443 using `az vm open-port`
Making Outbound Calls from My App
You can make outbound calls using a private CA client certificate from your app, but this is only supported for Windows container apps in multi-tenant App Service.
In App Service Environment version 3, you can also make outbound calls using a private CA client certificate with both code-based and container-based apps.
For multi-tenant vs. single-tenant App Service, see App Service Environment v3 and App Service public multitenant comparison.
Importing and Managing Certificates
To import and manage certificates in Azure, you can create a free managed certificate, import an App Service certificate, or import a certificate from Key Vault. You can also upload a private certificate or a public certificate to App Service.
You can create a free managed certificate, which is a turn-key solution for securing your custom DNS name in App Service. This certificate is fully managed by App Service and is automatically renewed every six months, 45 days before expiration.
To import an App Service certificate, you can use the Azure portal and select the "Bring your own certificates (.pfx)" option. You can also import a certificate from Key Vault by selecting the "Import from Key Vault" option.
You can upload a private certificate to App Service by following the steps in the "Upload a private certificate" section, and you can upload a public certificate by following the steps in the "Upload a public certificate" section.
Here are the steps to upload a public certificate:
- Select your .cer file.
- Enter the certificate friendly name.
- When you're done, select Add.
- After the certificate is uploaded, copy the certificate thumbprint, and then review Make the certificate accessible.
Generate and Store
For production use, you should import a valid certificate signed by a trusted provider. To generate and store a certificate, you can use the Azure CLI or PowerShell.
You can generate a self-signed certificate using the az keyvault certificate create command. This command uses the default certificate policy, which is suitable for development purposes.
To store the certificate, you can use Azure Key Vault. This is a secure and managed service that allows you to store and manage sensitive information, such as certificates.
Here are the steps to generate and store a certificate using Azure Key Vault:
- Generate a self-signed certificate using the az keyvault certificate create command.
- Store the certificate in Azure Key Vault using the az keyvault certificate import command.
Note that for production use, you should import a valid certificate signed by a trusted provider.
Import
Importing certificates to Azure App Service can be done in several ways. You can import a certificate from a .pfx file, which is a file that contains a private key and a certificate.
To import a certificate from a .pfx file, you'll need to select the certificate in the Azure portal and then click "Add certificate". You can then select the .pfx file and enter the password to import the certificate.
If you're using Azure Key Vault to manage your certificates, you can import a PKCS12 certificate into App Service from Key Vault. This is a great option if you're already using Key Vault to manage your certificates.
To import a certificate from Key Vault, you'll need to select the subscription associated with the key vault, select the key vault that has the certificate you want to import, and then select the certificate from the list of available certificates.
You can also import a certificate from Key Vault using the Azure CLI or Azure PowerShell. This can be a convenient option if you're already using one of these tools to manage your Azure resources.
Here are the steps to import a certificate from Key Vault using the Azure CLI:
- Select the subscription associated with the key vault
- Select the key vault that has the certificate you want to import
- Select the certificate from the list of available certificates
- Use the `az webapp config ssl upload` command to upload the certificate to App Service
Note that you'll need to have the Azure CLI installed and configured on your machine in order to use this command.
In addition to importing certificates from .pfx files and Key Vault, you can also generate a certificate and store it in Key Vault using the `az keyvault certificate create` command. This can be a convenient option if you need to generate a certificate for a specific use case.
Here are the steps to generate a certificate and store it in Key Vault:
- Use the `az keyvault certificate create` command to generate a certificate
- Use the `az keyvault certificate import` command to import the certificate into Key Vault
- Use the `az webapp config ssl upload` command to upload the certificate to App Service
Note that you'll need to have the Azure CLI installed and configured on your machine in order to use these commands.
Overall, importing certificates to Azure App Service can be done in a variety of ways, and the best approach will depend on your specific needs and requirements. By following the steps outlined above, you should be able to import your certificates and secure your App Service with ease.
Frequently Asked Questions
How to add SSL certificate to Azure VM?
To add an SSL certificate to an Azure VM, start by obtaining a trusted SSL certificate from a Certificate Authority and then upload it to the Azure Portal. Follow the subsequent steps to update DNS settings and test HTTPS enforcement.
What is SNI SSL in Azure?
SNI SSL in Azure allows multiple domains to share the same IP address, secured with different TLS/SSL certificates. This feature is supported by most modern browsers, enabling secure hosting of multiple websites on a single IP.
Sources
- https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-secure-web-server
- https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate
- https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code
- https://www.geeksforgeeks.org/how-to-install-an-ssl-certificate-on-azure/
- https://sslguides.com/2024/01/28/how-to-install-an-ssl-certificate-on-azure/
Featured Images: pexels.com