Azure DevOps Integration
The InsightCloudSec Azure DevOps integration helps your security and development teams integrate infrastructure-as-code (IaC) security and compliance scans (serviced using the CLI IaC Scanning Tool mimics) with Azure Pipelines and Boards. Setting up this integration is as simple as copying a YAML file to your code repository!
Prerequisites
- InsightCloudSec Domain Admin permissions
HTML viewer extension recommended
Though it's not required, InsightCloudSec highly recommends including a third-party HTML viewer extension as part of your Azure DevOps organization as it can improve the IaC output and pipeline artifacts viewing experience.
Integrate with Azure Pipelines
To integrate the InsightCloudSec CLI IaC Scanning Tool (mimics
) with Azure Pipelines, you'll need to incorporate one of the example YAML files included in the following sections into your code repository. The file you use depends on how you are currently using mimics
. Currently, InsightCloudSec supports running mimics
as an executable or using Docker. In each example YAML file, we have included the following Azure Pipeline environment variables to keep sensitive data secure and interact with InsightCloudSec and AWS Elastic Container Registry (ECR) if applicable:
BASE_URL
- The web address of your InsightCloudSec environment, which can be found in System Settings.ICS_API_KEY
- An API Key used to access InsightCloudSec data without traditional username-password authentication- We recommend this value remains a secret within Azure DevOps
IAC_TEMPLATE_DIR_PATH
- The file path to the directory that contains your IaC templates (relative to the project root). For example,/path/to/cloudformation
.IAC_CONFIG_NAME
- The name of the IaC Configuration to run the scan against- If your configuration name contains spaces, you will need to wrap the environment variable value in quotation marks. For example,
"Test Configuration"
.
- If your configuration name contains spaces, you will need to wrap the environment variable value in quotation marks. For example,
For more information on Azure Pipelines variables, see Define Variables.
Planning on storing sensitive information within Azure DevOps environment variables?
Azure DevOps environment variables can be stored as secrets to not expose any sensitive information, such as API or access keys. When configuring environment variables for your Azure Pipeline, ensure that sensitive data is not exposed by selecting the Keep this a secret checkbox when inputting variables.
Run as an executable
The CLI IaC Scanning Tool can be run as an executable using Terraform or Amazon Web Services' (AWS) CloudFormation.
Using Terraform
yaml
1trigger:2branches:3include:4- releases/*56pool:7vmImage: "ubuntu-latest" # Define the virtual machine image to use for the pipeline89variables:10terraformVersion: "1.9.2" # Define the Terraform version to ensure consistency across runs11terraformDownloadUrl: "https://releases.hashicorp.com/terraform/$(terraformVersion)/terraform_$(terraformVersion)_linux_amd64.zip" # URL for Terraform download12mimicsDownloadUrl: "https://artifacts.rapid7.com/cloudsec/mimics/latest/mimics_latest_linux_amd64" # URL for Mimics download1314jobs:15- job: Rapid7_IaC_Terraform_Scanner16displayName: "Rapid7 IaC scanner"1718steps:19# Check if Terraform is already installed, and download it if necessary20- script: |21if [ ! -f /usr/local/bin/terraform ]; then22wget $(terraformDownloadUrl)23else24mv /usr/local/bin/terraform /usr/local/bin/terraform.old25wget $(terraformDownloadUrl)26fi2728# Unzip and install Terraform29unzip "terraform_$(terraformVersion)_linux_amd64.zip" -d terraform_temp30chmod +x terraform_temp/terraform31mv terraform_temp/terraform /usr/local/bin/32displayName: "Install Terraform"3334# Initialize Terraform, create a plan, and convert it to JSON35- script: |36terraform init37terraform plan -out=tf.plan38terraform show -json tf.plan > plan.json39displayName: "Initialize Terraform & Generate Terraform plan"40workingDirectory: $(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH)4142# Format plan.json to provide position output of violating resources43- script: |44jq "." ./plan.json > formatted_plan.json45mv formatted_plan.json plan.json46displayName: "Format Terraform Plan to provide accurate output"47workingDirectory: $(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH)4849# Download the IaC Scanning Tool Mimics executable50- script: |51wget $(mimicsDownloadUrl) -O $(Agent.ToolsDirectory)/mimics52chmod +x $(Agent.ToolsDirectory)/mimics53displayName: "Install Mimics-binary" # Downloads and installs the Mimics tool (binary executable) for infrastructure as code (IaC) scanning5455# Use the Mimics executable to scan the plan.json56- script: |57mkdir -p $(System.DefaultWorkingDirectory)/mimics-reports58$(Agent.ToolsDirectory)/mimics scan \59$(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH)/plan.json \60--api-key $(ICS_API_KEY) \61--base-url $(BASE_URL) \62--no-verify \63--ics-config $(IAC_CONFIG_NAME) \64--log-format json \65--report-formats all \66--report-name results-rapid7_iac \67--report-path "$(System.DefaultWorkingDirectory)/mimics-reports" \68--save-report \69--no-fail \70--verbose71displayName: "Scan IaC files with Mimics"7273# Publish additional files (results-rapid7_iac artifacts)74- task: PublishBuildArtifacts@175displayName: "Publish Scan Artifacts"76inputs:77pathtoPublish: "$(System.DefaultWorkingDirectory)/mimics-reports"78artifactName: "results-rapid7_iac" # Publishes the scan reports as build artifacts for later access7980# Publish the HTML report using the PublishHtmlReport task81- task: PublishHtmlReport@182condition: succeededOrFailed()83inputs:84reportDir: $(System.DefaultWorkingDirectory)/mimics-reports/results-rapid7_iac.html85tabName: "R7 IaC Scan Results" # Publishes the HTML scan report to the Azure DevOps build summary for easy access86
Using CloudFormation
yaml
1trigger:2branches:3include:4- releases/*56pool:7vmImage: "ubuntu-latest" # Define the virtual machine image to use for the pipeline89variables:10mimicsDownloadUrl: "https://artifacts.rapid7.com/cloudsec/mimics/latest/mimics_latest_linux_amd64" # URL for Mimics download1112jobs:13- job: Rapid7_IaC_CloudFormation_Scanner14displayName: "Rapid7 IaC scanner"1516steps:17# Download the IaC Scanning Tool Mimics executable18- script: |19wget $(mimicsDownloadUrl) -O $(Agent.ToolsDirectory)/mimics20chmod +x $(Agent.ToolsDirectory)/mimics21displayName: "Install Mimics-binary" # Downloads and installs the Mimics tool (binary executable) for infrastructure as code (IaC) scanning2223# Use the Mimics executable to scan the plan.json24- script: |25mkdir -p $(System.DefaultWorkingDirectory)/mimics-reports26$(Agent.ToolsDirectory)/mimics scan \27$(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH) \28--api-key $(ICS_API_KEY) \29--base-url $(BASE_URL) \30--no-verify \31--ics-config $(IAC_CONFIG_NAME) \32--log-format json \33--report-formats all \34--report-name results-rapid7_iac \35--report-path "$(System.DefaultWorkingDirectory)/mimics-reports" \36--save-report \37--no-fail \38--verbose39displayName: "Scan IaC files with Mimics"4041# Publish additional files (results-rapid7_iac artifacts)42- task: PublishBuildArtifacts@143displayName: "Publish Scan Artifacts"44inputs:45pathtoPublish: "$(System.DefaultWorkingDirectory)/mimics-reports"46artifactName: "results-rapid7_iac" # Publishes the scan reports as build artifacts for later access4748# Publish the HTML report using the PublishHtmlReport task49- task: PublishHtmlReport@150condition: succeededOrFailed()51inputs:52reportDir: $(System.DefaultWorkingDirectory)/mimics-reports/results-rapid7_iac.html53tabName: "R7 IaC Scan Results" # Publishes the HTML scan report to the Azure DevOps build summary for easy access5455
Run using Docker
The CLI IaC Scanning Tool can also be run as a Docker container using Terraform or AWS CloudFormation, but requires additional configuration. To run mimics
in a Docker container, you'll need to provide the following variables to authenticate for the AWS CLI so InsightCloudSec can retrieve the mimics
container image from AWS Elastic Container Registry (ECR):
AWS_ACCESS_KEY_ID
- The ID of the Access Key associated with an IAM User to enable programmatic requestsAWS_SECRET_ACCESS_KEY
- The secret value of the Access Key
To view all publicly-available mimics
container images, visit the Rapid7 ECR Gallery. For more information on AWS Access Keys and long-term credentials, see Managing access keys for IAM users.
AWS authentication should be stored as a secret
Both variables should be stored as secrets within your Azure DevOps Pipeline.
Using Terraform
yaml
1trigger:2branches:3include:4- releases/*56pool:7vmImage: "ubuntu-latest" # Define the virtual machine image to use for the pipeline8910variables:11terraformVersion: "1.9.2" # Define the Terraform version to ensure consistency across runs12terraformDownloadUrl: "https://releases.hashicorp.com/terraform/$(terraformVersion)/terraform_$(terraformVersion)_linux_amd64.zip" # URL for Terraform download1314jobs:15- job: Rapid7_Docker_IaC_CloudFormation_Scanner16displayName: "Rapid7 Docker IaC scanner"17steps:1819# Configure AWS CLI with access key, secret key, and region20- script: |21aws configure set aws_access_key_id $(AWS_ACCESS_KEY_ID)22aws configure set aws_secret_access_key $(AWS_SECRET_ACCESS_KEY)23displayName: "Configuring AWS CLI Credentials"2425# Check if Terraform is already installed, and download it if necessary26- script: |27if [ ! -f /usr/local/bin/terraform ]; then28wget $(terraformDownloadUrl)29else30mv /usr/local/bin/terraform /usr/local/bin/terraform.old31wget $(terraformDownloadUrl)32fi3334# Unzip and install Terraform35unzip terraform_$(terraformVersion)_linux_amd64.zip -d terraform_temp36chmod +x terraform_temp/terraform37mv terraform_temp/terraform /usr/local/bin/38displayName: "Install Terraform"3940# Initialize Terraform, create a plan, and convert it to JSON41- script: |42terraform init43terraform plan -out tf.plan44terraform show -json tf.plan > plan.json45displayName: "Initialize Terraform & Generate Terraform plan"46workingDirectory: $(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH)4748# Format plan.json to provide position output of violating resources49- script: |50jq '.' ./plan.json > formatted_plan.json51mv formatted_plan.json plan.json52displayName: "Format Terraform Plan to provide accurate output"53workingDirectory: $(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH)5455# Scan the provided IaC Template with the IaC mimics image56- script: |57pull(){58mkdir -p $(System.DefaultWorkingDirectory)/data/mimics-reports59docker run \60-v $(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH):/data \61-e MIMICS_BASE_URL=$(BASE_URL) \62-e MIMICS_API_KEY=$(ICS_API_KEY) \63--name iac-mimics-container \64public.ecr.aws/rapid7-insightcloudsec/ics/mimics:latest scan /data/plan.json --no-verify --ics-config $(IAC_CONFIG_NAME) --log-format json --report-formats all --report-name results-rapid7_iac --report-path "/data/mimics-reports" --save-report --no-fail --verbose65}6667echo '1 2 3 5 8 13' | tr ' ' '\n' | while read t; do68pull && break69echo >&2 "docker pull failed; sleeping $t seconds"70sleep $t71done72displayName: "Scan IaC files with Mimics"7374# Copy mimics reports from docker container to host75- script: |76docker cp iac-mimics-container:data/mimics-reports $(System.DefaultWorkingDirectory)/data77displayName: Copy Mimics Reports from Docker Container to Host7879# Publish additional files (results-rapid7_iac artifacts)80- task: PublishBuildArtifacts@181displayName: "Publish Scan Artifacts"82inputs:83pathtoPublish: "$(System.DefaultWorkingDirectory)/data/mimics-reports"84artifactName: "results-rapid7_iac"8586# Publish the HTML report using the PublishHtmlReport task87- task: PublishHtmlReport@188displayName: "Publish HTML Report"89condition: succeededOrFailed()90inputs:91reportDir: $(System.DefaultWorkingDirectory)/data/mimics-reports/results-rapid7_iac.html92tabName: "R7 IaC Scan Results"
Using CloudFormation
yaml
1trigger:2branches:3include:4- releases/*56pool:7vmImage: "ubuntu-latest" # Define the virtual machine image to use for the pipeline89jobs:10- job: Rapid7_Docker_IaC_Terraform_Scanner11displayName: "Rapid7 Docker IaC scanner"12steps:1314# Configure AWS CLI with access key, secret key, and region15- script: |16aws configure set aws_access_key_id $(AWS_ACCESS_KEY_ID)17aws configure set aws_secret_access_key $(AWS_SECRET_ACCESS_KEY)18displayName: "Configuring AWS CLI Credentials"1920# Scan the provided IaC Template with the IaC mimics image21- script: |22pull(){23mkdir -p $(System.DefaultWorkingDirectory)/data/mimics-reports24# Use Docker to run the Mimics tool for scanning25docker run \26-v $(System.DefaultWorkingDirectory)$(IAC_TEMPLATE_DIR_PATH):$(IAC_TEMPLATE_DIR_PATH) \27-e MIMICS_BASE_URL=$(BASE_URL) \28-e MIMICS_API_KEY=$(ICS_API_KEY) \29--name iac-mimics-container \30public.ecr.aws/rapid7-insightcloudsec/ics/mimics:latest scan $(IAC_TEMPLATE_DIR_PATH) --no-verify --ics-config $(IAC_CONFIG_NAME) --log-format json --report-formats all --report-name results-rapid7_iac --report-path "/data/mimics-reports" --save-report --no-fail --verbose31}3233echo '1 2 3 5 8 13' | tr ' ' '\n' | while read t; do34pull && break35echo >&2 "docker pull failed; sleeping $t seconds"36sleep $t37done38displayName: "Scan IaC files with Mimics"3940# Copy mimics reports from docker container to host41- script: |42docker cp iac-mimics-container:data/mimics-reports $(System.DefaultWorkingDirectory)/data43displayName: Copy Mimics Reports from Docker Container to Host4445# Publish additional files (results-rapid7_iac artifacts)46- task: PublishBuildArtifacts@147displayName: "Publish Scan Artifacts"48inputs:49pathtoPublish: "$(System.DefaultWorkingDirectory)/data/mimics-reports"50artifactName: "results-rapid7_iac"5152# Publish the HTML report using the PublishHtmlReport task53- task: PublishHtmlReport@154displayName: "Publish HTML Report"55condition: succeededOrFailed()56inputs:57reportDir: $(System.DefaultWorkingDirectory)/data/mimics-reports/results-rapid7_iac.html58tabName: "R7 IaC Scan Results"
Integrate with Azure Boards (optional)
To integrate the InsightCloudSec CLI IaC Scanning Tool (mimics
) with Azure Boards, you'll need to follow the instructions for integrating Azure Pipelines first and then incorporate the example in this section with the appropriate YAML file for your setup. In the following example YAML section, we have included the following environment variables to assist your new InsightCloudSec Azure Pipelines integration in interacting with Azure Boards:
PAT
- A Personal Access Token (PAT) for your Azure DevOps user, which helps pipelines create work items for each finding produced by the IaC analysis scans.- PATs should be stored as a secret within your Azure DevOps environment variables. For more information on PATs, visit Use Personal Access Tokens.
AZURE_BOARDS_ORGANIZATION
- The Azure DevOps Organization where the Azure Board work items should be placed.AZURE_BOARDS_PROJECT
- The Azure DevOps Project where Azure Board work items should be placed.
Example Azure Board script for Azure Pipeline integration
The following example section needs to be placed in the appropriate section of the example Azure Pipelines YAML file. The location is determined by how you are running mimics
:
- If you are running
mimics
using an executable, copy and paste it after theScan IaC files with Mimics
step - If you are running
mimics
using a Docker container, copy and paste it after theCopy Mimics Reports from Docker Container to Host
step
yaml
1# Create Azure Devops work items for each finding produced by the IaC Mimics scan2- script: |3# Construct the URL for API requests, choosing the correct work item type and API version.4url="https://dev.azure.com/$(AZURE_BOARDS_ORGANIZATION)/$(AZURE_BOARDS_PROJECT)/_apis/wit/workitems/\$Issue?api-version=6.0"56# Specify the path to the SARIF file generated by the previous steps7sarifFile="$(System.DefaultWorkingDirectory)/mimics-reports/results-rapid7_iac.sarif"89# Check for the existence of the SARIF file and process it10if [ -f "$sarifFile" ]; then11echo "Found SARIF file: $sarifFile"1213# Iterate through each result in the SARIF file, extracting relevant details14jq -c '.runs[].results[]' "$sarifFile" | while read -r result; do15ruleId=$(jq -r ".ruleId" <<< $result)16message=$(jq -r ".message.text" <<< $result)17locations=$(jq -r '.locations[]' <<< $result)18title=$(jq -c --arg ruleId "$ruleId" '.runs[].tool.driver.rules[] | select(.id == $ruleId).name' "$sarifFile")1920# Prepare a JSON payload for creating a new work item via the Azure DevOps REST API21json=$(jq --arg ruleId "$ruleId" --arg message "$message" --arg title "$title" --arg project "$(AZURE_BOARDS_PROJECT)" '22[23{"op": "add", "path": "/fields/System.Title", "value": $title},24{"op": "add", "path": "/fields/System.Description", "value": "<div>\($message)</div><pre style=\"white-space: pre-line\">\(.properties.changes)</pre>"},25{"op": "add", "path": "/fields/System.State", "value": "To Do"},26{"op": "add", "path": "/fields/System.AreaPath", "value": $project}27]28' <<< $locations)2930# Make an API call to create a new work item with the prepared payload31curl -X POST -H "Content-Type: application/json-patch+json" -H "Authorization: Basic $(echo -n ":$PAT" | base64)" -d "$json" "$url"32done33else34echo "SARIF file not found: $sarifFile"35fi36displayName: "Process SARIF and Create Azure Board Work Items"37env:38PAT: $(PAT) # Pass the Personal Access Token (PAT) securely as an environment variable
Create a Azure Pipeline
After you have selected the appropriate example YAML file for your project and copied it to the code repository, you are ready to set up the integration in Azure Pipelines.
Something not quite right?
For the most up-to-date information, refer to Microsoft Azure’s documentation on creating an Azure Pipeline.
- Log in to the Azure Console.
- Navigate to Azure Pipelines.
- Click New Pipeline.
- In the Connect section, follow the steps to connect and select the host of your code repository.
- In the Configure section, click Starter Pipeline.
- Copy and paste the example YAML file you selected in the Integrate with Azure Pipelines over the existing YAML on this page.
- Click Variables and provide the applicable environment variables.
- Validate the YAML and update as necessary. For example, setting pipeline triggers and a valid Terraform version.
- Click Run > Save.