Bridgecrew CLI

3.2.511 · active · verified Thu Apr 16

Bridgecrew is an Infrastructure as Code (IaC) static analysis tool that scans cloud configurations and identifies misconfigurations. It serves as a wrapper around the open-source `checkov` library, providing additional features, integrations, and a connection to the Bridgecrew cloud platform. The current version is 3.2.511. It primarily functions as a command-line interface (CLI) tool with continuous releases.

Common errors

Warnings

Install

Imports

Quickstart

The `bridgecrew` library is primarily used as a command-line interface. This quickstart demonstrates how to execute the `bridgecrew` CLI from Python using `subprocess` to scan an Infrastructure as Code file. It highlights the use of the `BC_API_KEY` environment variable for authentication to the Bridgecrew platform.

# Save your Infrastructure as Code (e.g., Terraform, CloudFormation, Kubernetes) to a file named 'my_resource.tf'
# Example content for my_resource.tf:
# resource "aws_s3_bucket" "bad_bucket" {
#   bucket = "my-private-bucket"
#   acl    = "public-read"
# }

import os
import subprocess

# Ensure BC_API_KEY is set in your environment for Bridgecrew platform integration.
# If not set, Bridgecrew will still run checks but won't send results to the platform.
api_key = os.environ.get('BC_API_KEY', 'YOUR_BC_API_KEY_HERE_IF_NEEDED')

# Create a dummy IaC file for scanning
with open('my_resource.tf', 'w') as f:
    f.write('resource "aws_s3_bucket" "bad_bucket" {\n  bucket = "my-private-bucket"\n  acl    = "public-read"\n}\n')

print("Scanning 'my_resource.tf' with Bridgecrew...")
try:
    # Run bridgecrew CLI via subprocess
    # -f specifies the file/directory to scan
    # --skip-framework checkov skips scanning with checkov only (bridgecrew uses checkov)
    # It is recommended to use the bridgecrew CLI which layers on top of checkov
    # Setting BC_API_KEY for the subprocess call
    result = subprocess.run(
        ['bridgecrew', '-f', 'my_resource.tf'],
        capture_output=True,
        text=True,
        check=True,
        env={**os.environ, 'BC_API_KEY': api_key} # Pass current env + BC_API_KEY
    )
    print("Bridgecrew Scan Output:")
    print(result.stdout)
    if result.stderr:
        print("Bridgecrew Scan Errors:")
        print(result.stderr)
except subprocess.CalledProcessError as e:
    print(f"Bridgecrew scan failed with error: {e}")
    print(f"Stdout: {e.stdout}")
    print(f"Stderr: {e.stderr}")
except FileNotFoundError:
    print("Error: 'bridgecrew' command not found. Please ensure Bridgecrew is installed and in your PATH.")

# Clean up the dummy file
os.remove('my_resource.tf')

view raw JSON →