Use this action to analyze the source code for security vulnerabilities and quality defects using the Perforce Klocwork Static Application Security Testing (SAST) scanner. The action output can be used as a quality gate in subsequent GitHub Actions steps or jobs.
This action is available on the GitHub marketplace.
Klocwork is a Static Application Security Testing (SAST) solution that helps organizations identify security vulnerabilities and quality issues in source code through deep static analysis.
Add a Klocwork scan to your workflows in CloudBees platform to:
-
Detect security vulnerabilities and quality defects in source code.
-
Identify potential security flaws early in the development lifecycle.
-
Gain insight into code quality risks and how to fix issues.
-
Ensure compliance with industry standards such as OWASP, CWE, CERT, and MISRA.
CloudBees platform enables you to run a Klocwork scan either implicitly or explicitly.
Explicit and implicit scan types
An implicit scan is automatically triggered, and an explicit scan is one you configure to be invoked in a step of your workflow. To learn more about the differences between explicit and implicit scans, refer to Security scan actions.
To set up implicit scanning, refer to Code and binary security analysis .
Prerequisites
Set up the CloudBees platform and GHA to work together, providing key features of the platform to GHA workflows. Refer to Getting started with GHA integration for more information.
How the scanner works
The Klocwork SAST scanner architectural components are:
-
Client-side: The Klocwork analysis engine and command-line tools (
kwbuildproject,kwciagent). -
Server-side: The Klocwork Server for centralized analysis results management.
-
Analysis engine: Proprietary static analysis engine with deep dataflow and control flow analysis capabilities.
The scanning process is as follows:
-
The Klocwork build specification is created to capture the build configuration of your project.
-
Source code is analyzed on the client side using the Klocwork analysis engine.
-
The analysis results are uploaded to the Klocwork Server (if configured).
-
Security vulnerabilities and quality defects are identified based on enabled checkers and taxonomies.
-
Results are reported with severity levels, detailed descriptions, and remediation guidance.
-
The scan results are made available as actionable outputs for quality gates and downstream workflow steps.
| For more information about the Perforce Klocwork SAST scanner, refer to the Perforce Klocwork documentation. |
Inputs
| Input name | Data type | Required? | Description |
|---|---|---|---|
|
String |
Yes |
The Klocwork server URL. |
|
String |
Yes |
Klocwork username. |
|
String |
No |
Klocwork password. |
|
String |
No |
Klocwork application token. |
|
String |
Yes |
Klocwork build tool [make / cmake / python/ maven / dotnet]. |
|
String |
No |
Klocwork build directory [default is root folder /]. |
|
String |
Yes |
Specify the ref to be checked out and scanned. |
|
String |
No |
Klocwork build name. |
|
String |
No |
Klocwork scan build options [e.g., make <target-name> -j4]. |
|
String |
No |
Klocwork build specification file path [e.g., /tmp/kwinject.out]. |
|
Boolean |
No |
Enable Klocwork Agent Scan [default is full scan]. |
|
String |
No |
Klocwork license server hostname [default is server hostname]. |
|
String |
No |
Klocwork license server port [default is 27000]. |
|
String |
No |
Klocwork project name. |
|
String |
No |
Klocwork scan waiting time in seconds [e.g., 3600]. |
|
String |
No |
Klocwork scan tables directory [e.g., /tmp/tables]. |
|
Boolean |
No |
Enable Klocwork Local Scan [performs analysis locally on the agent only and does not push results to the Klocwork Server]. |
|
String |
No |
Klocwork |
|
String |
No |
Klocwork |
|
String |
No |
The file path of the code to be scanned. |
For C/C++/.NET projects, since kwinject is used for building the specification file, the build-options parameter is mandatory. You must pass the appropriate build command with options. For example, if make is the build tool, the build-options should be specified like make targetName -j14 or similar build commands specific to your project configuration.
|
Outputs
| Output name | Data type | Description |
|---|---|---|
|
String |
The number of Critical severity issues discovered during the scan. |
|
String |
The number of High severity issues discovered during the scan. |
|
String |
The number of Medium severity issues discovered during the scan. |
|
String |
The number of Low severity issues discovered during the scan. |
|
String |
The total number of issues discovered during the scan. |
This action uses GitHub OIDC authentication to securely communicate with CloudBees platform.
Be sure to set permissions to id-token: write in your workflow.
|
Usage examples
The following is a basic example of using this action:
In the following example, the Klocwork
command reference provides detailed guidance on specifying build-options according to the build-tool used.
For instance, if the build-tool is make, the build-options should include the build command and relevant flags,
such as make targetName -j14, to ensure that kwinject can correctly generate the build specification file.
permissions: id-token: write contents: read steps: - name: Scan with Perforce Klocwork SAST scanner uses: cloudbees-io-gha/perforce-klocwork-sast-publish@v1 with: url: ${{ vars.KLOCWORK_URL }} token: ${{ secrets.KLOCWORK_APP_TOKEN }} license-host: ${{ vars.KLOCWORK_LICENSE }} username: ${{ vars.KLOCWORK_USERNAME }} project-name: test-c-project build-directory: / build-tool: make build-options: make clean <target-name> --ignore-errors enable-agent-scan: false enable-local-scan: false
Using the action output
You can use the output values from this action in downstream steps and jobs. The following example uses the action output in a downstream step of the same job:
The following example uses the action output in a downstream job:
Full workflow and run example
The following GHA workflow example scans a repository with Perforce Klocwork SAST scanner.
Example GHA workflow YAML file
After the GHA run has completed, the security findings are collected and displayed in the Security center and the Security overview for the component containing the workflow.
When the respective artifact is deployed to an application environment, Klocwork findings are also displayed in the Security center and the Security overview for the application.