Quickstart: Check your code repository with a security scanner

3 minute read

In this quickstart, use a CloudBees Unify workflow to scan a repository with the SonarQube static application security testing (SAST) scanner, which detects security flaws and provides suggested code fixes. After implementing this action in your workflow, SonarQube report data is collected and displayed in CloudBees Unify analytics dashboards.

If you are already running a centralized SonarQube instance, you have the option to use the Scan with SonarQube action instead of the bundled SonarQube action used in the steps described below. In this case, the data collected from the scans is available in both CloudBees Unify analytics dashboards and in SonarQube reports.

Prerequisites

Add a scanning step

To scan your repository, add a step to the CI job. This step uses the CloudBees Configure SonarQube bundled action to scan your repository for security vulnerabilities.

Use either the code editor or the visual tool to add this step. Workflow updates made in the visual tool display in the code editor, and vice versa.

Add a scanning step using the code editor

To add the SonarQube bundled action using the code editor:

  1. Select the Up/down arrows, and then select a component in an organization.

  2. Select Edit YAML on your workflow.

  3. Enter the following in the code editor, starting just after your Run tests step:

    - name: Scan with SonarQube bundled action uses: https://github.com/cloudbees-io/sonarqube-bundled-sast-scan-code@v1
    SonarQube action
    Figure 1. SonarQube scan step highlighted.

You have added a step using the code editor.

Add a scanning step using the visual tool

To add the SonarQube bundled action using the visual tool:

  1. Select the Up/down arrows, and then select a component in an organization.

  2. Select Edit YAML on your workflow.

  3. Select the 'ci-job` in the visual tool, or select the Vertical ellipsis next to ci-job, and then select Edit.

    Add new step
    Figure 2. The selected job and Add step highlighted.
  4. Select Add step.

  5. Select Select from catalog.

  6. From Container and actions, select one of the following security scanner tools:

    • Hybrid scanner: Built-in scanning tools that run directly in your workflows with minimal configuration. The scan results display in the Summary, Security overview, and Security center tabs.

    • Security Orchestrated (SO): Tools integrated with external security platforms already running in your organization. Results display on the Analytics page in the Security insights dashboard.

  7. Select Apply selected.

  8. (Optional) Select Scan from the options.

  9. Select Save.

You have added a step using the visual tool.

Check to confirm that your YAML script is similar to the following:

Display the complete YAML file for building the sample Go app and scanning the repository.
apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: My automation on: push: branches: - '**' jobs: ci-job: steps: - uses: docker://alpine/git:latest run: | git config --global --add safe.directory /cloudbees/workspace - name: checkout uses: https://github.com/cloudbees-io/checkout@v1 - name: Build Go app uses: docker://golang:1.20 run: | go build -v ./... - name: Run tests uses: docker://golang:1.20 run: | go test -v ./... - name: Scan with SonarQube bundled action uses: https://github.com/cloudbees-io/sonarqube-bundled-sast-scan-code@v1 kind: scan

Regardless of whether you have used the visual tool or the code editor to add the scan step, both the visual tool and the code editor are in sync and display the SonarQube bundled action in a new step of the ci-job job.

Run the updated workflow

Trigger the workflow to run by making a commit to your repository with the new scan step added to your workflow, then display the run details.

To trigger the workflow run and display the run details:

  1. Select Commit.

  2. Enter a Commit message.

  3. Select Commit to current branch.

  4. Select Finish.

  5. Select Components from the left pane, select your component, and then select Runs to display your runs, with the most recent at the top of the list.

  6. Select Display run to the right of your run.

  7. Select the ci-job in the visual tool, and then select the scan step.

    Rerun button
    Figure 3. Run details with Rerun workflow and Go To End highlighted.
  8. (Optional) Scroll through the scan step run details, or select GO TO END to jump to the end of the log.

    Scan results
    Figure 4. Run details displaying scan results
    Manually rerun the workflow by selecting Rerun workflow.

You have run the workflow to build the Go app and scan your repository.

Display the scan summary

To display the scan results and security vulnerabilities for the SonarQube bundled action:

  • Go to Analytics  Security insights.

The Security insights dashboard provides a comprehensive view of scan results for the SonarQube bundled action. For more information, refer to Security insights dashboard.

Scan results dashboard

You have added a scan step to your workflow, using a security scanner action tool, and displayed the collected data in the component where the workflow ran. For more information, refer to Publish an image using your workflow.