Ensure your API contracts are secure by adding 42Crunch to your pipeline

This post is written by Kristin Davis from 42Crunch.

The transition to cloud-native, microservice-based, and serverless architectures has led to the proliferation of APIs. Applications now have components talking to each other via hundreds of APIs over the network. And as applications evolve, developers keep changing APIs and spinning up new ones each time a new component gets added to the system.

APIs have become the new application attack surface and the one that is extremely hard to control considering its constant change.

With the ever-rising privacy and cybersecurity requirements and the potential catastrophic consequences of a breach, companies are turning to DevSecOps approaches to enable automated static analysis and security testing as part of their CI/CD pipelines.

The new 42Crunch extension for Bitbucket Pipelines enables developers to add REST API static security testing (SAST) right into their CI/CD pipeline.

Getting Started with the 42Crunch integration for Bitbucket Pipelines

Step 1: Register with 42Crunch

Make sure you have a 42Crunch API Security Platform account. You can register here: https://platform.42crunch.com/register

Step 2: Generate an API token

42Crunch and Bitbucket Pipelines
  1. Log in to 42Crunch Platform, and click your profile.
  2. Click Settings > API Tokens, and click Create New Token.
  3. Enter a unique and descriptive name for the token, such as CI_CD token.
  4. Under token access rights, select API Contract Security Audit, List Resources, and Delete Resources.
  5. Click Generate Token.
  6. Copy the token value, you will need it when you configure the task on the pipeline.

STEP 3: Add a Bitbucket variable for the API token

Before you add the pipe to your Bitbucket pipeline, you must add the API token you created as a secured repository variable.

  1. Log in to your Bitbucket account, and go to your repository.
  2. Click ⚙ > Repository settings > Repository variables.
  3. Enter the following:
    • Value: The value of the API token you created
  4. Make sure Secured is selected, and click Add.

You have now created the variable that your pipeline can use to authenticate to Security Audit.

Step 4: Add the pipe to your Bitbucket pipeline

To run the pipe, you must add it to your Bitbucket pipeline.

  1. Log in to your Bitbucket account and go to the pipeline you want.
  2. Open the pipeline configuration file bitbucket-pipelines.yml for editing
  3. Under script, add the following line where you want to add the pipe: 
    • – pipe: 42crunch/bitbucket-api-security-audit-pipe:1.0.5
  4. Enter the minimum API score that the audited OpenAPI definitions must get from the audit for the pipe to succeed. If any API definitions scores lower than the minimum score you set, the pipe will fail. The default is 75.
  5. Click commit!

Step 5: REST API Static Security Audit

The pipe will either succeed or fail depending on the minimum score. The summary of the run in the pipeline reports provides you further details on how the job went. 

The pipe uploads all discovered OpenAPI definitions to the specified API collection in 42Crunch Platform. 

The report of the run includes a link to each discovered API. You can click on the link to view the detailed audit report of the corresponding API in 42Crunch Platform.

Get started with 42Crunch:

Want to learn more? Join 42Crunch on a live webinar demonstration on June 25th, 2020: https://42crunch.com/webinar-lets-shift-api-security-left/