Semgrep Managed Scans require repositories hosted by Azure DevOps Services. Azure DevOps Server is not supported.
Semgrep recommends setting up and configuring Semgrep Managed Scans with an Azure DevOps service account, not a personal account. Regardless of whether you use a personal or service account, the account must be assigned the Owner or Project Collection Administrator role for the organization.
During setup and configuration, you must provide a personal access token generated by the account. This token must be authorized with Full access.
Once you have Managed Scans fully configured, you can add restrictions to the token provided to Semgrep. The scopes you must assign to the token include:
Enable Managed Scans and scan your first repository
1
In Semgrep AppSec Platform, click Projects.
2
Click Scan new project > Semgrep Managed Scan.
3
Select Azure Devops as your source code manager.
4
On the Add to Azure DevOps Pipeline page, provide the following information:
i. Your Access token. See User personal access tokens for token generation information. Ensure you set the Azure DevOps SCM name to organization_name/project_name.
ii. The name of your Azure DevOps Project.
5
Click Connect to proceed.
You have finished setting up a Semgrep managed scan. Click Back to Managed Scans to see your projects.
After enabling Managed Scans, Semgrep performs a full scan on all the repositories in batches.
Once a repository has been added to Semgrep AppSec Platform, it becomes a project. A Semgrep AppSec Platform project includes all the repository’s findings, history, and scan metadata.
Projects with a Managed Scan configuration are tagged with managed-scan, regardless of whether the project is actively being scanned by Semgrep Managed Scans or not. The Projects list also contains pending scans and scans that never started.
Delete the existing pipeline configuration file in your repository if appropriate.
If you plan to continue running some scans in Azure DevOps Pipelines (for example, using Managed Scans to run weekly full scans but Pipelines for diff-aware scans) you can leave the workflow file in place, and edit it to reflect your desired configuration.
TIPSemgrep preserves your findings, scans, and triage history.
Configure fail open to prevent diff-aware scans from blocking pull requests and merge requests
By default, diff-aware managed scans are set to fail open if a scan errors out or takes too long. This means that diff-aware scans are marked as successful on the pull request (PR) or merge request (MR), even if they haven’t completed after the specified timeout, allowing you to make the Semgrep status check required in your source code manager (SCM) while not blocking someone from merging a PR or MR if the check encounters an unexpected issue or takes too long.
Sample pull request showing the status of a diff-aware scan.
If enabled, the fail open feature is triggered whenever you open a PR or MR.
2
Initially, Semgrep sends an update to mark the PR or MR as pending.
3
Once the diff-aware scan begins, the PR or MR is updated to a status of running.
4
The diff-aware scan completes, and the PR or MR is updated to a status of succeeded or failed.
5
If the diff-aware scan is in pending or running status longer than the configured timeout, then the fail open process updates the PR or MR to display a status of succeeded. This prevents the Semgrep scan from blocking the developer from merging their changes.
If Semgrep marks a PR or MR as succeeded, you can merge the PR or MR without waiting for the diff-aware scan to complete. However, if the PR or MR is still open and the scan completes after the fail open timeout is reached, Semgrep can still report the findings and mark the status as failed.
Managed Scans of Azure DevOps projects require webhooks. The webhooks are enabled by default when you add Azure DevOps as a source code manager when setting up Managed Scans. Webhooks are required for diff-aware scans and triaging by PR or MR comments.You can turn off webhooks at any time by following these steps:
Turn off Managed Scans for specific repositories in Semgrep AppSec Platform
1
Sign in to Semgrep AppSec Platform.
2
Go to Projects and find the project you no longer want scanned with Semgrep Managed Scanning. Click the project’s Details page > Settings tab.
3
Toggle the switch for Managed diff scans to turn off scans of new pull requests and merge requests and Managed full scans to turn off full scans of the base branch.
To protect branches whose repositories are automatically scanned by Semgrep, enable Azure DevOps status checks:
1
Sign in to Azure DevOps and navigate to the Azure DevOps project you’ve connected to Semgrep.
2
Go to Repos > Branches.
3
Find the branch to which the status check should be applied, and click the three vertical dots to open up the More options dialog.
4
Select Branch policies.
5
Ensure that the branch to which you want the status check applied is selected. Navigate to Status Checks, and click the Add + button to proceed.
Configure status checks for a branch in Azure DevOps.
6
In the dialog that appears:
i. Leave the Status to check box blank, since this value is auto-populated as you provide values in subsequent steps.
ii. Select the Enter genre/name separately box. Provide the following values:
a. Genre: security
b. Name: semgrep-cloud-platform/scanOnce you provide the Genre and Name, Azure DevOps auto-populates Status to check.
iii. Choose whether the status check needs to succeed or not to complete pull requests. Selecting Required means that a status of succeeded is necessary to complete pull requests. Selecting Optional means that a status of failed will not block the completion of pull requests.
Add status policy dialog in Azure DevOps.
7
Click Save to proceed.
At this point, all subsequent pull requests opened against this branch are subject to the status check you created.
If you currently scan Azure DevOps repositories in your CI pipeline, you may see findings assigned to two separate projects once you enable Semgrep Managed Scans. For example, findings from Managed Scans go to the semgrep/frontend/webpage project, while findings from CI scans go to the frontend/webpage project. If this is the case, Semgrep AppSec Platform flags these findings with Possible duplicate. Please contact support for addition assistance.
To view your scan logs in Semgrep AppSec Platform, go to Projects, then click on the project name. The projects in the list are sorted by scan date, with the most recent scans listed first.
INFOIt can take a few minutes for your latest scan logs to appear. However, if the logs do not update 15 minutes after the scan, there may be issues with the scan itself.
Scan statistics, such as how many of your repositories are being scanned, the scan success rate, and so on, can be provided once a week upon request. Contact your Semgrep account manager to request scan statistics.