Add an SSL Certificate to API running on Virtual Machine

Bobby Roy 5 Reputation points
2023-03-01T20:17:25.6233333+00:00

I have a client who has a web application, an API, and a database in their Azure account. I have successfully updated the web application to use an SSL certificate...a certificate that is stored in the Key Vault. However, when users go to the website, and attempt certain actions, an error is raised because the certificate, associated with the API/virtual machine is expired.

How do I go about making changes so that the virtual machine/API will use the certificate in the Key Vault?

NOTE: I have never worked with virtual machines, in Azure, before.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,103 questions
{count} votes

3 answers

Sort by: Most helpful
  1. shaikh siddique 1 Reputation point
    2023-03-02T11:01:02.1566667+00:00

    Follow the steps in this article to secure a web server on a Windows virtual machine in Azure with TLS/SSL certificates stored in Key Vault.

    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-secure-web-server

    0 comments No comments

  2. shaikh siddique 1 Reputation point
    2023-03-02T11:35:56.23+00:00

    Follow the steps in the below article to secure a web server on a Windows virtual machine in Azure with TLS/SSL certificates stored in Key Vault:

    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-secure-web-server

    0 comments No comments

  3. vipullag-MSFT 24,026 Reputation points Microsoft Employee
    2023-03-27T04:28:56.5866667+00:00

    Hello Bobby Roy

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    Based on the details shared, you already have an SSL cert created and stored in Key Vault.

    -To make the necessary changes so that the virtual machine/API will use the certificate in the Key Vault, follow the below steps and see if these help:

    -In Azure portal locate the Key Vault containing the SSL certificate, Click on Access Policies and add a new policy that grants access to the virtual machine's identity.

    -Use PowerShell cmdlets to retrieve the SSL certificate from the Key Vault. Save the certificate in a location on the virtual machine that your API can access.

    Retrieve the certificate from the Key Vault:

    Get-AzKeyVaultSecret -VaultName "your-key-vault-name" -Name "your-certificate-name" | Select-Object -ExpandProperty SecretValueText | Out-File -Encoding ASCII -FilePath "C:\path\to\your\certificate.cer"

    In the above command, replace "your-key-vault-name" with the name of your Key Vault, "your-certificate-name" with the name of your SSL certificate, and "C:\path\to\your\certificate.cer" with the path where you want to save the certificate on the virtual machine.

    -Open your API configuration file (e.g., web.config for ASP.NET applications) and locate the section that configures HTTPS settings. Update the certificate configuration to reference the certificate you just retrieved from the Key Vault. Save the configuration file.

    -Restart your API to ensure that the new certificate is being used. Test your API to ensure that it is functioning correctly.

    Hope this helps.

    0 comments No comments