.NET and Azure Resource Manager (ARM) Templates

  • Updated

Agent installation guide

Overview

This guide offers examples for using Contrast Security’s .NET Framework and .NET Core agents with ARM templates. We encourage you to take this guide, make it your own, and distribute it to teams who need to instrument applications this way. 

The main portion of the guide details the most popular methods customers use to instrument .NET Framework and Core applications through automation with ARM templates and Azure.

 

Main steps

  1. Update application ARM template
    • Add the Contrast agent extension
    • Add Contrast agent configuration options in the siteConfig section
  2. Deploy your application with an updated ARM template

Supported technologies

Before you begin, please be sure Contrast supports your preferred tools and environments for the .NET Framework or .NET Core agents:
Supported technologies for .NET Framework
Supported technologies for .NET Core

 

This guide assumes you have:

Known issues

  • You can only configure site extensions either directly through the Azure Portal with an ARM policy or through Azure’s REST API. All methods described in this document use one of these methods. Only REST API and Azure ARM policies allow for automated deployments.
  • You should only configure a Contrast site extension with backend HTTP services and not WebJobs or UI app services.
  • The methods described here do not work if you are deploying an App service using Docker.

Instructions

Begin by updating the application ARM template.

 


1) Add Contrast configuration values

You can download the agent configuration values directly from Contrast. Begin by selecting Add Agent in Contrast and complete the steps indicated to get the values. You must edit the values highlighted in the sample ARM template below. For more details, check Contrast documentation:

Contrast agent for .NET Core

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "sites_name": {
          "defaultValue": "APP_NAME",
          "type": "String"
      }
  },
  "variables": {
  },
  "resources": [
      {
          "type": "Microsoft.Web/sites",
          "apiVersion": "2018-11-01",
          "name": "[parameters('sites_name')]",
          "location": "East US",
          "kind": "app",
          "properties": {
              "siteConfig": {
                  "appSettings": [
                      {
                          "name": "CONTRAST__API__API_KEY",
                          "value": "<CONTRAST__API__API_KEY>",
                          "slotSetting": false
                      },
                      {
                          "name": "CONTRAST__API__SERVICE_KEY",
                          "value": "<CONTRAST__API__SERVICE_KEY>",
                          "slotSetting": false
                      },
                      {
                          "name": "CONTRAST__API__URL",
                          "value": "<CONTRAST__API__URL>",
                          "slotSetting": false
                      },
                      {
                          "name": "CONTRAST__API__USER_NAME",
                          "value": "<CONTRAST__API__USER_NAME>",
                          "slotSetting": false
                      },
                      {
                           "name": "CORECLR_ENABLE_PROFILING",
                          "value": "1",
                          "slotSetting": false
                      },
                      {
                           "name": "CORECLR_PROFILER",
                           "value": "{8B2CE134-0948-48CA-A4B2-80DDAD9F5791}",
                          "slotSetting": false
                      },
                      {
                           "name": "CORECLR_PROFILER_PATH_32",
                           "value": D:\\home\\SiteExtensions\\Contrast.NetCore.Azure.SiteExtension\\ContrastNetCoreAppService\\contrast\\runtimes\\win-x86\\native\\ContrastProfiler.dll",
                          "slotSetting": false
                      },
                      {
                           "name": "CORECLR_PROFILER_PATH_64",
                           "value": D:\\home\\SiteExtensions\\Contrast.NetCore.Azure.SiteExtension\\ContrastNetCoreAppService\\\contrast\\runtimes\\win-x64\\native\\ContrastProfiler.dll",
                          "slotSetting": false
                      }
                  ]
              }
          },
          "resources": [
              {
                  "name": "Contrast.NetCore.Azure.SiteExtension",
                  "type": "siteextensions",
                  "apiVersion": "2018-02-01",
                  "dependsOn": [
                      "[resourceId('Microsoft.Web/Sites', parameters('sites_name'))]"
                  ]
              }
          ]
      }
  ]
}

Contrast agent for .NET Framework

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "sites_name": {
          "defaultValue": "APP_NAME",
          "type": "String"
      }
  },
  "variables": {
  },
  "resources": [
      {
          "type": "Microsoft.Web/sites",
          "apiVersion": "2018-11-01",
          "name": "[parameters('sites_name')]",
          "location": "East US",
          "kind": "app",
          "properties": {
              "siteConfig": {
                  "appSettings": [
                      {
                          "name": "CONTRAST__API__API_KEY",
                          "value": "<CONTRAST__API__API_KEY>",
                          "slotSetting": false
                      },
                      {
                          "name": "CONTRAST__API__SERVICE_KEY",
                          "value": "<CONTRAST__API__SERVICE_KEY>",
                          "slotSetting": false
                      },
                      {
                          "name": "CONTRAST__API__URL",
                          "value": "<CONTRAST__API__URL>",
                          "slotSetting": false
                      },
                      {
                          "name": "CONTRAST__API__USER_NAME",
                          "value": "<CONTRAST__API__USER_NAME>",
                          "slotSetting": false
                      },
                      {
                           "name": "COR_ENABLE_PROFILING",
                          "value": "1",
                          "slotSetting": false
                      },
                      {
                           "name": "COR_PROFILER",
                           "value": "{EFEB8EE0-6D39-4347-A5FE-4D0C88BC5BC1}",
                          "slotSetting": false
                      },
                      {
                           "name": "COR_PROFILER_PATH_32",
                           "value": "D:\\home\\SiteExtensions\\Contrast.NET.Azure.SiteExtension\\ContrastAppService\\ContrastProfiler-32.dll",
                          "slotSetting": false
                      },
                      {
                           "name": "COR_PROFILER_PATH_64",
                           "value": "D:\\home\\SiteExtensions\\Contrast.NET.Azure.SiteExtension\\ContrastAppService\\ContrastProfiler-64.dll",
                          "slotSetting": false
                      }
                  ]
              }
          },
          "resources": [
              {
                   "name": "Contrast.NET.Azure.SiteExtension",
                  "type": "siteextensions",
                  "apiVersion": "2018-02-01",
                  "dependsOn": [
                      "[resourceId('Microsoft.Web/Sites', parameters('sites_name'))]"
                  ]
              }
          ]
      }
  ]
}

 

Contrast API access configuration

To automate your ARM templates more fully, you need access to Contrast API credentials, either from the contrast_security.yml file and agent you can download from Contrast (as described above) or from Organization Settings on the API page.

 

You will need to note the values below, either from the Contrast UI or from your contrast_security.yaml file:

Configuration setting name                     Contrast label



CONTRAST__API__API_KEY                API Key



CONTRAST__API__URL Contrast     URL



CONTRAST__API__USER_NAME            Agent Username



CONTRAST__API__SERVICE_KEY       Agent Service Key


 


2) Deploy your application using an ARM template.

You can deploy your application from the ARM template in the following methods from the Azure documentation:

Begin by adding authentication details to configuration for the Contrast agent.

 

FAQ

1. Where can I find logs if I don’t see my application in Contrast after I deploy my template?

There can be multiple reason application is not listed:

  • Contrast is failing to attach to the application process or communicate to the team server. You can find the logs using Kudu services in this location:
    D:\home\LogFiles\Contrast
  • You don’t have permission to the group you configured in application configuration. For this, reach out to your Contrast administrator.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request