BitBucket CI

nctl integrates and works with the BitBucket CI and allows scanning against security team-defined policies which ensures addressing of misconfigurations in the pipeline alongside other tests and vulnerability scanning. The nctl scan step will trigger the scan. In case of a failure, the entire build can be configured to fail. This means that the test pipeline will fail, and the users will get quick feedback for their changes. The results of the pipeline are published to the NPM for viewing.

NPM provides insights to platform administrators on overall compliance of different code repositories in their organization. Learn more about BitBucket CI pipelines and their configuration from this official documentation.

Understanding the BitBucket CI Workflow

To see pipeline scanning with BitBucket CI in action:

Install nctl in the BitBucket pipeline

Add the install nctl build to the bitbucket-pipelines.yml file in the repository. The build installs the nctl CLI and is stored as an artifact for future builds. The following code does that:

      - step:
          name: 'install nctl'
            - echo "Installing nctl.."
            - echo "Downloading and Installing NCTL 4.0.2"
            - download_url=""
            - curl -L -o $download_url
            - unzip -o
            - echo "Verify Installation.."
            - chmod 755 ./nctl
            - ./nctl version
            - nctl

Scan Repository files for misconfiguration

The nctl-scan-repo build scans the configuration files available in the repository for any misconfigurations. The --policies argument points to the directory containing security policies.

Note: The policies can also be stored in a different BitBucket repository. Refer to the sample list of policies here.

After the execution of this build, the pipeline will fail if there are misconfigurations which will force the developer to debug and fix the issue at the source.

      - step:                  # This build scans config files for misconfigurations.
          name: 'nctl-scan-repo' # It only starts when the build in the install stage completes successfully.
            - echo "Running nctl scan.."
            - git remote set-url origin
            - git checkout main    # Checkout the branch of choice or use pipeline variables to specify the branch.
            - ./nctl login --url --userid <USER_ID> --token <API_TOKEN>
            - ./nctl scan repository --policies Update

Note: Replace <USER_ID> and <API_TOKEN> with the NPM ID and token respectively.

This pipeline runs in two stages: install-nctl and scan. Both can be visualized in the BitBucket UI. The image below represents the same.