CI/CD Integration
CI/CD Integration
Overview
Pensar provides a CLI tool and API for integrating automated pentesting directly into your CI/CD pipeline. Run pentests on every commit or deployment to catch vulnerabilities before they reach production.
CI-triggered pentests consume credits from your workspace balance. See Billing & Usage for details on credit management and usage tracking.
Installation
Install the Pensar CI package globally:
Or add it as a dev dependency:
View the source code and additional examples on GitHub.
Configuration
Required Environment Variables
Optional Environment Variables
You can configure CI/CD integration directly from the Pensar Console. Navigate to Settings → Automation → CI/CD in your workspace for guided setup and one-click workflow creation.
CLI Usage
Run a Pentest
Options:
Examples:
Run Only on Labelled Changes
When only some changes are worth pentesting, label the pull request and gate the workflow on that label. This is done in the workflow, not in the CLI.
On a pull-request-triggered workflow the labels are in the event payload, so a job-level condition is all you need and nothing extra runs:
On a push or a post-deploy run there is no pull request in the payload, so the pull request the commit came from has to be looked up. Add a small job that does the lookup and make the pentest job depend on it:
Because the pentest job depends on the gate, an unlabelled change never starts it: no runner, no checkout, no install.
Keep the label in LABEL rather than inlining it into the command. A label is
free text, so an apostrophe would break the quoting and a . or * would make
grep match a different label; -F compares it literally.
After a deploy, use ${{ github.event.workflow_run.head_sha }} rather than
${{ github.sha }}. On a workflow_run event github.sha is the tip of the
default branch, not the commit that was deployed, so the gate would check
whichever change landed most recently.
The Console generates both of these for you: enter a label under Settings → CI/CD and the workflow snippets on that page include the gate, with the right SHA for each trigger.
Check Scan Status
Example:
CI/CD Examples
GitHub Actions
On Push
After Deployment
Run a pentest when commits are pushed to main branches:
GitLab CI
Add to your .gitlab-ci.yml:
Bitbucket Pipelines
Add to your bitbucket-pipelines.yml:
Exit Codes
By default, the CLI will exit with code 1 if any security issues are found. Use this to block deployments when vulnerabilities are detected.
API Reference
Dispatch Scan
Headers:
Authorization: Bearer <api_key>orx-api-key: <api_key>Content-Type: application/json
Request Body:
Provide a repository so the pentest is scoped to that repository’s
applications. Supply either repoId (GitHub’s numeric repository id — the
CLI auto-detects this from GITHUB_REPOSITORY_ID) or repositoryId (the
internal repository UUID). When neither is supplied the scan covers every
application in the workspace.
The repository must already be connected to the workspace. If it isn’t found,
the API responds 404; if it belongs to another workspace, 403; if it has
no discovered applications yet (run reconnaissance first), 422.
Response:
Get Scan Status
Headers:
Authorization: Bearer <api_key>orx-api-key: <api_key>
Response: