Skip to main content

Add a Bitbucket repository to Semgrep Managed Scans

Add Bitbucket repositories to your Semgrep organization in bulk without adding or changing your existing CI workflows through Managed Scans.

Prerequisites and permissions

Semgrep Managed Scanning requires one of the following plans:

  • Bitbucket Cloud Premium
  • Bitbucket Data Center (v8.8 or above for diff-aware scans)

Bitbucket Cloud

You must provide a Bitbucket workspace access token to Semgrep, which can be created by a user with the Product Admin role. Once you have Managed Scanning fully configured, you can update the token provided to Semgrep to one that's more restrictive. The scopes you must assign to the token include:

  • webhook (read and write)
  • repository (read and write)
  • pullrequest (read and write)
  • project (admin)
  • account (read)

Bitbucket Data Center

You must provide a Bitbucket HTTP access token to Semgrep, which can be created by a user with the Product Admin role. This access token must be created with with PROJECT_ADMIN permissions.

Project-level webhooks are required to support diff-aware scans.

Enable Managed Scanning and scan your first repository

  1. In Semgrep AppSec Platform, click Projects.
  2. Click Scan new project > Semgrep Managed Scan.
  3. Click Manage Connections and then + Connect more.
  4. Select Bitbucket.
  5. In the Set up Managed Scans page that appears, provide the information needed by Semgrep to connect to your Bitbucket project:
    1. Select Bitbucket or Bitbucket Data Center.
    2. Provide your Access token.
    3. Provide the name of your Bitbucket workspace.
    4. For Bitbucket Data Center users only: provide the Bitbucket Data Center URL.
    5. Click Connect.
  6. Repeat the steps above for each additional Bitbucket workspace you'd like added to Semgrep.

You have finished setting up a Semgrep managed scan.

  • After enabling Managed Scans, Semgrep performs a full scan in batches on all the repositories in the workspace.
  • Once a repository has been added to Semgrep AppSec Platform, it becomes a project. A project in Semgrep AppSec Platform includes all the findings, history, and scan metadata of that repository.
  • 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.

Add additional Bitbucket projects

You can enable managed scanning for additional repositories after onboarding using the following steps:

  1. In Semgrep AppSec Platform, click Projects.
  2. Click Scan new project > Semgrep Managed Scan.
  3. In the Enable Managed Scans for repos page, select the repositories you want to add to Semgrep Managed Scans.
    1. Optional: If you don't see the repository you want to add, click Can't find your project? and follow the troubleshooting steps provided.
  4. Select the repositories you want to scan from the list.
  5. Click Enable Managed Scans. The Enable Managed Scans dialog appears. By default, Semgrep runs both full and diff-aware scans.
  6. Optional: Disable PR or MR diff-aware scans by turning off the Enable PR/MR scans toggle. Enable Managed Scans dialog
  7. Click Enable.

If the page doesn't display any repositories

  1. Ensure that you've connected your Bitbucket account by following the steps in Connect a source code manager and confirm the workspace access token is created with the required scopes listed above with the Product Admin role.
  2. In Semgrep AppSec Platform, click Projects.
  3. If the page doesn't display the repository you want to add, click Can't find your project? > Sync projects.
  4. If the page doesn't display any repositories, click Sync projects.
  5. Optional: Perform a hard refresh (Ctrl+F5 or Cmd+Shift+R).

Convert or migrate an existing Semgrep CI job

You can immediately add any existing project to Managed Scans.

  1. Follow the steps in Enable managed scanning.
  2. Delete the bitbucket-pipelines.yml file in your Bitbucket repository if appropriate.

If you plan to continue running some scans in Bitbucket CI/CD Pipelines (for example, using Managed Scans to run weekly full scans but Bitbucket CI/CD Pipelines for diff-aware scans) you can leave the workflow file in place, and edit it to reflect your desired configuration.

tip

Semgrep preserves your findings, scans, and triage history.

Scan management and configuration

Manually run a full scan

  1. In Semgrep AppSec Platform, click Projects.
  2. Search for your repository's name.
  3. Click the gear icon to access the settings page for that repository.
  4. Click Run a new scan.

Disable diff-aware scans on PRs

  1. In Semgrep AppSec Platform, click Projects.
  2. Search for your repository's name.
  3. Click the window icon under Details to access the settings page for that repository.
  4. Click the toggle for diff-aware scans.

Delete a project

  1. In Semgrep AppSec Platform, click Projects.
  2. Search for your repository's name.
  3. Click the window icon under Details to access the settings page for that repository.
  4. Click the dropdown at the header and click Delete project.

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. Figure. Sample pull request showing the status of a diff-aware scan.

How fail open works

  1. 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.

Configure fail open

By default, fail open is enabled. However, you can disable this feature and adjust the timeout value:

  1. Sign in to Semgrep AppSec Platform.
  2. Go to Settings > General > Managed Scans.
  3. Click the Fail open toggle to turn off this feature.
  4. Set the Timeout value in minutes. The default value is 10 minutes, the minimum value is 1 minute, and the maximum value is 60 minutes. Semgrep AppSec Platform settings page with fail open configuration options. Figure. Semgrep AppSec Platform settings page with fail open configuration options.

Disable webhooks

Managed scanning of Bitbucket projects requires webhooks. The webhooks are enabled by default when you add Bitbucket as a source code manager when setting up Managed Scanning. You can disable webhooks at any time by following these steps:

  1. In Semgrep AppSec Platform, go to Settings > Source code managers.
  2. Find your Bitbucket connection, and click the toggle to disable Incoming webhooks.

Revoke Semgrep's access to your repositories

The following steps revoke the code access you previously granted Semgrep for all repositories you selected.

  1. In Semgrep AppSec Platform, click Settings > Source Code Managers.
  2. On the entry of the SCM you want to remove, click Remove app.
  3. Click Remove to confirm.

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. Semgrep AppSec Platform toggles to turn off managed scans of repositories

Appendices

Scan logs

Most recent scan

You can view logs for your most recent scan by clicking Projects > the project's latest scan time under Scan status.

Click the project's latest scan to view the log Figure. The Projects page. Click the project's latest scan (underlined) to view the log.

info

It can take a few minutes for your latest scan's logs to appear. However, if the logs do not update 15 minutes after the scan, there may be issues with the scan itself.

All scans

  1. Click the project's Details page > Scans tab.
  2. Click the scroll icon under Logs to view the log for the particular entry.

Scan statistics

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.


Not finding what you need in this doc? Ask questions in our Community Slack group, or see Support for other ways to get help.