Enable HTTPS communication in Azure Cloud Services (extended support)
Article
Communication with Microsoft Azure Cloud Services (extended support) is done by using the Hypertext Transfer Protocol Secure (HTTPS) protocol. This article discusses how to enable HTTPS communication for Cloud Services (extended support).
The general steps to deploy a Cloud Services (extended support) project into Azure are as follows:
Prepare your certificate.
Configure your project.
Package the project file into the service definition (.csdef), service configuration (.cscfg), and service package (.cspkg) files of your cloud service.
Change the configuration of the Cloud Services (extended support) resource, if necessary. For example, you could make any of the following modifications:
Update the package URL.
Configure the URL setting.
Update the operating system secrets setting.
Deploy and update the new project into Azure.
Note
The project can be deployed through several different methods, such as by using the following tools:
A continuous integration and continuous delivery (CI/CD) tool, such as Azure DevOps
Regardless of the deployment method, the general deployment steps are the same.
The first two of these steps are necessary for all deployment methods. These steps are discussed in the Code changes section. The remaining steps are also important, but they don't always require manual user intervention. For example, the steps might be done automatically by a tool such as Visual Studio. The last three of these steps are discussed in the Configuration changes section.
Code changes
To make the code changes to prepare your certificate and configure your project, take the following steps:
Write down the thumbprint of the certificate (a 40-digit hexadecimal string).
In the service configuration (.cscfg) file of your project, add the certificate thumbprint to the role in which you want to use the certificate. For example, if you want to use the certificate as the SSL certificate to communicate with a WebRole, you might add XML code that resembles the following snippet for WebRole1 as the first child of the root ServiceConfiguration element:
The Certificates element has to be added directly after the closing Endpoints tag. It doesn't contain any attributes. It contains only child Certificate elements.
For example, your service definition file might resemble the following XML code:
In this example, the service definition file is modified to bind an input endpoint of HttpsIn for the HTTPS protocol on port 443. It uses the Certificate1 certificate for a store that has a name of My and a location of LocalMachine for just a limited or elevated permission level. The certificate names in the InputEndpoint and Certificate elements match each other. They also match the certificate name that was used in the service configuration (.cscfg) file from the previous step.
Configuration changes
Instructions for changing your cloud service configuration differ according to how your cloud service was deployed. These instructions are shown on the following tabs. Each tab represents a different method of deployment.
Upload the generated service package (<project-name>.cspkg) and cloud service configuration (ServiceConfiguration.Cloud.cscfg) files into a storage account container for your cloud service.
Note
You'll also have to upload the service definition (ServiceDefinition.csdef) file by using the same process that's described for the other two files.
Generate a shared access signature (SAS) URL for each of the uploaded files.
In the Azure portal, return to the Overview page of your cloud service, and then select Update.
On the Update cloud service page, make the following changes on the Basics tab:
In the Package/configuration/service definition location field, select From blob.
In the Upload a package (.cspkg, .zip) field, follow these steps:
Select the Browse link.
Select the storage account and container to which you uploaded files.
In the container page, select the corresponding file (in this case, <project-name>.cspkg), and then select the Select button.
For the Upload a configuration (.cscfg) field (and ServiceConfiguration.Cloud.cscfg file), repeat the subprocedure that's outlined in the previous step.
For the Upload a service definition (.csdef) field (and ServiceDefinition.csdef file), repeat the subprocedure again.
Select the Configuration tab.
In the Key vault field, select the key vault in which you uploaded the certificate (earlier in the Code changes section). After the certificate is found in the selected key vault, the listed certificate displays a Status of Found.
To deploy the newly configured project, select the Update button.
Upload the generated service package (<project-name>.cspkg) file into a storage account container for your cloud service.
Note
Despite what's stated in the instructions, you don't have to upload the cloud service configuration (ServiceConfiguration.Cloud.cscfg) file. Only the service package file has to be uploaded here.
Generate a shared access signature (SAS) URL for the uploaded service package file.
In the following PowerShell script, replace the placeholders at the beginning of the script with the actual values for each variable, and then run the script to update your cloud service:
Upload the generated service package (<project-name>.cspkg) and cloud service configuration (ServiceConfiguration.Cloud.cscfg) files into a storage account container for your cloud service.
Generate a shared access signature (SAS) URL for each of the uploaded files.
Get the following values from the key vault certificate page in the Azure portal:
Key vault certificate URL
Subscription ID
Name of the resource group in which the key vault is deployed
Service name for the key vault
In your original ARM template for the cloud service, find the osProfile property. If the original cloud service project supports only HTTP communication, the osProfile property is empty ("osProfile": {}). To enable the cloud service to retrieve the correct certificate from the correct key vault, specify which key vault you want to use within the ARM template. You can use a parameter to represent this value. Or, you can hardcode the value into the ARM template, as shown in the following example:
In the JSON text of the ARM template, the id value in the sourceVault parameter is part of the URL of the Key Vault page in the Azure portal. The certificateUrl value is the key vault certificate URL that you found earlier. The text formats for these values are shown in the following table.
Deploy your updated ARM template containing new parameters, such as the package SAS token, configuration SAS token, and more. To see how to declare and specify these parameters, you can review an example ARM template file and an example ARM template parameters file. Then, wait for the deployment to finish.
Note
If you receive an error message that states that the public IP address is being used, remove the public IP address from the service configuration (.cscfg) file and the ARM template parameters file. Don't remove the public IP address declaration from the ARM template file itself.
This section describes how to use the Azure SDK and C# to make the correct configuration changes. To successfully use the SDK to deploy the cloud service project and modify the related configuration, you should register an application in Microsoft Entra ID. To do the registration, see the Use the portal to create a Microsoft Entra application and service principal that can access resources article. The following table outlines the specific steps to take and the corresponding subsection to read in that article.
Step
Subsection link
Assign your subscription the owner role for your application
Upload the generated service package (<project-name>.cspkg) file into a storage account container for your cloud service.
Note
Despite what's stated in the instructions, you don't have to upload the cloud service configuration (ServiceConfiguration.Cloud.cscfg) file. Only the service package file has to be uploaded here.
Generate a shared access signature (SAS) URL for the uploaded service package file.
Get the following values from the key vault certificate page in the Azure portal:
Key vault certificate URL
Subscription ID
Name of the resource group in which the key vault is deployed
Service name for the key vault
Download the example project (a compressed archive file), and extract its contents.
Open the SDKSample\CreateCloudService\CreateCloudService\LoginHelper.cs file in a text editor. In the InitializeServiceClient method, overwrite the values of the tenantId, clientId, and clientCredentials string variables with the values for the tenant ID, application ID, and application secret, respectively. These values are the ones that you copied when you registered your application.
Open the SDKSample\CreateCloudService\CreateCloudService\Program.cs file in a text editor. In the Main method, overwrite some of the initialized values of the variables declared at the beginning of the method. The following table shows the variable names and the values that you have to use for them.
Variable name
New value
m_subId
The ID of the subscription that contains the cloud service
csrgName
The name of the resource group that contains the cloud service
csName
The cloud service resource name
kvrgName
The name of the resource group that contains the key vault resource
kvName
The key vault resource name
kvsubid
The ID of the subscription that contains the key vault (this might differ from the cloud service subscription ID)
secretidentifier
The key vault certificate URL
filename
The local path to your service configuration file (ServiceConfiguration.Cloud.cscfg)
packageurl
The SAS URL for the service package file (<project-name>.cspkg)
In the Visual Studio Solution Explorer pane, right-click the project node, and then select Manage NuGet Packages. On the Browse tab, search for, select, and install the following packages:
Microsoft.Azure.Management.ResourceManager
Microsoft.Azure.Management.Compute
Microsoft.Azure.Management.Storage
Azure.Identity
Microsoft.Rest.ClientRuntime.Azure.Authentication
Run the project, and then wait for messages to appear in the Output pane. If the pane displays "exit with code 0," the update and deployment should be working successfully. If it displays "exit with code 1," you might have to check for error messages to review any issues.
In Visual Studio, you have to make two configuration changes. You set up your service configuration so that the local context is aligned with the cloud context, and then you specify where your key vault is located.
For the service configuration, copy the contents of the cloud context (the ServiceConfiguration.Cloud.cscfg file), and paste them into the local context (the ServiceConfiguration.Local.cscfg file). Do you have a different configuration, or do you still need the local configuration file for other uses? If either condition is true, preserve the certificate elements from the existing local context.
In the Visual Studio Solution Explorer pane, right-click the project node, and then select Publish. Proceed through the Publish Azure Application wizard until you reach the Settings tab. On that tab, set the Key vault field to the location in which your key vault is saved. Finally, select the Publish button, and then wait for the deployment to finish.
After you make the configuration changes, customers will be able to communicate with your cloud services website by using the HTTPS protocol. If your certificate is self-signed, the browser might report a warning that the certificate isn't secure, but the browser won't block the connection.