YOUR DEPLOYMENT JOURNEY
- You have gained the necessary resource access and permissions required for deployment.
- You have created a Semgrep account and organization.
- You have connected your source code manager.
- Optionally, you have set up SSO.
- You have successfully added a Semgrep job to your CI workflow with diff-aware scanning.
Conditions for PR comment creation
PR comments appear for the following types of scans under these conditions:Set up PR comments
1
Ensure that you meet the prerequisites
Semgrep currently supports repositories hosted by Azure DevOps Cloud.In addition to finishing the previous steps in your deployment journey, it is recommended to have completed a full scan on your default branch for the repository in which you want to receive comments.
2
Confirm your Semgrep account's connection
PR comments are enabled by default for users who have connected their Azure DevOps project to Semgrep AppSec Platform. Confirm that you have the correct connection and access:You can also allow developers to triage Semgrep findings without leaving Azure DevOps by responding to the PR comments authored by Semgrep. To turn this feature on, you must update your source code manager (SCM) connection to use a personal access token that meets the following requirements, because Semgrep requires webhooks for the triage through PR comments feature:Once you have PR comments fully configured, you can update the token provided to Semgrep to a more restrictive one. The scopes you must assign to the token include:
1
In your Semgrep AppSec Platform account, click Settings > Source code managers.
2
Check that an entry for your Azure DevOps project exists and is correct.
- Has the role set to Owner or Project Collection Admin
- Has the Scopes set to grant Full access.
1
Log in to Azure DevOps using an account assigned either the Owner or Project Collection Administrator role for your organization.
2
Create an access token. When selecting the Scopes for the token, ensure that you select Full access.
3
Return to Semgrep and sign in.
4
Go to Settings > Source code managers, and find your Azure DevOps connection.
5
Click Update access token.
6
In the Update access token dialog that appears, provide the token you created. Click Update to save and proceed.
7
Toggle the Incoming webhooks setting on.
Project and Team (Read & write)Pull Request Threads (Read & write)
3
Set up the configuration file
The logic to determine whether Semgrep runs a full scan or a diff-aware scan on a pull request is defined in the
azure-pipelines.yaml file.For PR comments and accurate diff-aware scan analysis to work, you must set two environment variables: SEMGREP_PR_ID, which identifies the pull request, and SEMGREP_BASELINE_REF, which defines the repository’s default branch used as the comparison baseline, such as main or master. Specifying the default branch helps Semgrep understand the differences between the current branch and the main line of development and to generate meaningful results and PR comments.Click to see a sample workflow file
Click to see a sample workflow file
4
Configure pull request comments
Once you have set up the connection between Semgrep and Azure DevOps, you can create a remediation policy that lets you define the conditions under which Semgrep leaves a pull request comment. This customization enables you to:
- Manage the amount of PR comments your developers receive.
- Ensure that only rules that meet your criteria, such as high severity or high confidence rules, produce comments visible to developers, reducing noise.
Note: If you are using Azure Pipelines to run Semgrep, set
SEMGREP_PR_ID and SEMGREP_BASELINE_REF in your pipeline as described in Set up the configuration file.Optional features
Customize PR comments
You can customize the comments Semgrep leaves on your PR. Custom comments allow you to direct your teams to the resources they need to handle the vulnerabilities Semgrep identifies in their code. To provide custom PR comments:1
Sign in to Semgrep AppSec Platform.
2
Navigate to Settings > General > Global.
3
Go to the Custom PR/MR comments footers section.
4
Provide a custom comment for each Semgrep product whose findings you want to generate a PR comment. Semgrep supports HTML, Markdown, and plaintext links in your message.
5
Click Save changes.
Enable Rule-defined fix in Azure repositories
Autofix is a Semgrep feature in which rules contain suggested fixes to resolve findings. To enable Rule-defined fix for all projects in your Semgrep AppSec Platform organization, follow these steps:1
In Semgrep AppSec Platform, go to Settings > General > Code.
2
Click the Autofix toggle to enable this feature.
Next steps
You’ve finished setting up a core deployment of Semgrep 🎉.- Explore recommended tasks after deployment in Beyond core deployment.