Add Prisma Cloud Code Security Scanner as a Pre-Commit Hook
Install Prisma Cloud Application Security scanner (Prisma Cloud scanner) as a pre-commit hook into your workflows to automate the scanning of your code for Infrastructure-as-Code (IaC) misconfigurations, Software Composition Analysis (SCA) issues and Secrets vulnerabilities before a commit is created locally. Pre-commit hooks are local hooks that are triggered on the local machine before a commit is created or on other supported Git actions, such as file staging. These hooks enable you to enforce checks or actions before accepting any changes into the VCS.
Install Prisma Cloud Scanner as a Pre-Commit Hook on a Local Machine
Prerequisites
Before starting, ensure the following dependencies are installed:
Ensure the Prisma Cloud user has one of the following roles or equivalent permissions:
Developer, Systems Admin, or AppSec Admin role
Alternatively, for GRBAC, provide the following permissions in a Permission Group.
Policies: Policies - 'View' permissions
Application Security: Projects - 'View' permissions
Settings: Providers - ('View' and 'Create') OR ('View' and 'Update') permissions
For information about roles and permissions on Prisma Cloud, refer to Prisma Cloud Administrator Permissions.
Installation
Set your Prisma Cloud credentials as environment variables. NOTE: This is the recommended security practice. Do not hardcode credentials in your pre-commit hook due to security risks.
Mac/Linux
Windows
Create a file named
.pre-commit-config.yamlin the root directory of your repository.
To configure Prisma Cloud code scanning as a pre-commit hook, you have several options. This section details the most basic configuration, which scans the entire repository whenever a Terraform file is modified. For alternative configurations, see Alternative configuration options below. Recommended: To avoid redundant results uploads, append the --skip-results-upload flag to your pre-commit hook configuration.
Optional: add additional configuration settings to the args section of your .pre-commit-config.yaml file, such as --framework and --skip-check . For a complete list of configuration options, refer to the Checkov CLI Command Reference.
Install the hook: Run:
Test pre-commit functionality: Modify a file that is tracked by Git, and execute the git commit command. . Confirm that the pre-commit hook is triggered and that it either allows the commit or blocks it based on the results of its checks.
Alternative configuration options
Pre-commit hooks offer multiple configuration options. Some examples are provided below.
Secrets scanning only
Prevent secrets from being exposed in pull requests by identifying and blocking them before they are committed.
Scan modified files only
This configuration scans only modified files. Cross-file checks should be disabled due to potential limitations.
Complete override
You can fully override the entrypoint to customize configuration options.
Last updated
Was this helpful?

