Discover misconfigurations in Infrastructure as Code (IaC)
Once you have set up the Microsoft Security DevOps GitHub action or Azure DevOps extension, you can configure the YAML configuration file to run a single tool or multiple tools. For example, you can set up the action or extension to run Infrastructure as Code (IaC) scanning tools only. This can help reduce pipeline run time.
Prerequisites
- Configure Microsoft Security DevOps for GitHub and/or Azure DevOps based on your source code management system:
- Ensure you have an IaC template in your repository.
Configure IaC scanning and view the results in GitHub
Sign in to GitHub.
Navigate to
your repository's home page
> .github/workflows > msdevopssec.yml that was created in the prerequisites.Select Edit file.
Under the Run Analyzers section, add:
with: categories: 'IaC'
Note
Categories are case sensitive.
Select Start Commit
Select Commit changes.
(Optional) Add an IaC template to your repository. Skip if you already have an IaC template in your repository.
For example, commit an IaC template to deploy a basic Linux web application to your repository.
Select
azuredeploy.json
.Select Raw
Copy all the information in the file.
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "webAppName": { "type": "string", "defaultValue": "AzureLinuxApp", "metadata": { "description": "Base name of the resource such as web app name and app service plan " }, "minLength": 2 }, "sku": { "type": "string", "defaultValue": "S1", "metadata": { "description": "The SKU of App Service Plan " } }, "linuxFxVersion": { "type": "string", "defaultValue": "php|7.4", "metadata": { "description": "The Runtime stack of current web app" } }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Location for all resources." } } }, "variables": { "webAppPortalName": "[concat(parameters('webAppName'), '-webapp')]", "appServicePlanName": "[concat('AppServicePlan-', parameters('webAppName'))]" }, "resources": [ { "type": "Microsoft.Web/serverfarms", "apiVersion": "2020-06-01", "name": "[variables('appServicePlanName')]", "location": "[parameters('location')]", "sku": { "name": "[parameters('sku')]" }, "kind": "linux", "properties": { "reserved": true } }, { "type": "Microsoft.Web/sites", "apiVersion": "2020-06-01", "name": "[variables('webAppPortalName')]", "location": "[parameters('location')]", "kind": "app", "dependsOn": [ "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]" ], "properties": { "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]", "siteConfig": { "linuxFxVersion": "[parameters('linuxFxVersion')]" } } } ] }
On GitHub, navigate to your repository.
Select Add file > Create new file.
Enter a name for the file.
Paste the copied information into the file.
Select Commit new file.
The file is now added to your repository.
Confirm the Microsoft Security DevOps scan completed:
- Select Actions.
- Select the workflow to see the results.
Navigate to Security > Code scanning alerts to view the results of the scan (filter by tool as needed to see just the IaC findings).
Configure IaC scanning and view the results in Azure DevOps
To view the results of the IaC scan in Azure DevOps
Sign in to Azure DevOps.
Select the desired project
Select Pipeline.
Select the pipeline where the Microsoft Security DevOps Azure DevOps Extension is configured.
Edit the pipeline configuration YAML file adding the following lines:
Add the following lines to the YAML file
inputs: categories: 'IaC'
Select Save.
(Optional) Add an IaC template to your repository. Skip if you already have an IaC template in your repository.
Select Save to commit directly to the main branch or Create a new branch for this commit.
Select Pipeline >
Your created pipeline
to view the results of the IaC scan.Select any result to see the details.
View details and remediation information on IaC rules included with Microsoft Security DevOps
The IaC scanning tools that are included with Microsoft Security DevOps, are Template Analyzer (which contains PSRule) and Terrascan.
Template Analyzer runs rules on ARM and Bicep templates. You can learn more about Template Analyzer's rules and remediation details.
Terrascan runs rules on ARM, CloudFormation, Docker, Helm, Kubernetes, Kustomize, and Terraform templates. You can learn more about the Terrascan rules.
Learn more
- Learn more about Template Analyzer.
- Learn more about PSRule.
- Learn more about Terrascan.
In this tutorial you learned how to configure the Microsoft Security DevOps GitHub Action and Azure DevOps Extension to scan for Infrastructure as Code (IaC) security misconfigurations and how to view the results.
Next steps
Learn more about Defender for DevOps.
Learn how to connect your GitHub to Defender for Cloud.
Learn how to connect your Azure DevOps to Defender for Cloud.
Feedback
Submit and view feedback for