CI/CD Integration
Overview
Pensar provides a CLI tool and API for integrating security scanning directly into your CI/CD pipeline. Run automated pentests on every pull request, commit, or deployment to catch vulnerabilities before they reach production.
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 find your Project ID in the project settings page in the Pensar Console. Click the copy button next to the ID to copy it to your clipboard.
CLI Usage
Trigger a Scan
Options:
Examples:
Check Scan Status
Example:
CI/CD Examples
GitHub Actions
On Pull Request
On Push
After Deployment
Scan every pull request before merging:
GitLab CI
Add to your .gitlab-ci.yml:
Bitbucket Pipelines
Add to your bitbucket-pipelines.yml:
Programmatic Usage
Use the CI package programmatically in your Node.js scripts:
Exit Codes
By default, the CLI will exit with code 1 if any security issues are found. Use this to block PRs or deployments when vulnerabilities are detected.
Best Practices
Use Priority Scans for PRs
For faster feedback on pull requests, use priority scans:
Priority scans focus on the most critical vulnerability categories, providing results in minutes rather than hours.
Run Full Scans on Main Branch
Schedule comprehensive scans on your main branch:
- Run full scans after merging to main
- Use scheduled workflows for nightly full scans
- Full scans provide the most thorough coverage
Store Secrets Securely
Never hardcode API keys in your pipeline configuration:
- Use GitHub Secrets, GitLab CI Variables, or Bitbucket Repository Variables
- Rotate API keys regularly
- Use separate API keys for different environments
Handle Scan Results
Integrate scan results into your workflow:
- Block merges when critical issues are found
- Send notifications to Slack or email
- Track issues in your project management tool
- Use the Pensar Console for detailed analysis
API Reference
Dispatch Scan
Headers:
Authorization: Bearer <api_key>orx-api-key: <api_key>Content-Type: application/json
Request Body:
Response:
Get Scan Status
Headers:
Authorization: Bearer <api_key>orx-api-key: <api_key>
Response: