Security Tests Policy Samples
The Harness Policy Library includes the following policy samples that make it easy to create security test policies and enforce them against your scan results.
Warn or Block vulnerabilities by severity
Apply a policy to a scan step to warn or block on any vulnerabilities with the specified severity.
You must copy the entire sample code from the OPA policy library, as described in Create a new Security Tests OPA policy.
Here is a sample policy that you can evaluate using the On Step event for a scan step.
Warn or Block vulnerabilities by reference ID
Apply a policy to a scan step to warn or block on any vulnerabilities in a specific list of CVEs or CWEs.
You must copy the entire sample code from the OPA policy library, as described in Create a new Security Tests OPA policy.
Here is a sample policy that you can evaluate using the On Step event for a scan step.
Warn or Block vulnerabilities by title
Apply a policy to a scan step to warn or block on any vulnerabilities in a specific list of issue titles.
You must copy the entire sample code from the OPA policy library, as described in Create a new Security Tests OPA policy.
You can use the ~ operator to find titles based on Python regular expressions.
Here is a sample policy that you can evaluate using the On Step event for a scan step.
Warn or Block vulnerabilities by number of occurrences
Apply a policy to a scan step to warn or block vulnerabilities based on a set of titles and the maximum allowed number of occurrences for each vulnerability.
You must copy the entire sample code from the OPA policy library, as described in Create a new Security Tests OPA policy.
You can use the ~ operator to find titles based on Python regular expressions.
Here is a sample policy that you can evaluate using the On Step event for a scan step.
Warn or Block vulnerabilities by CVE age
Apply a policy to a scan step to warn or block vulnerabilities based on CVEs by severity and age.
You must copy the entire sample code from the OPA policy library, as described in Create a new Security Tests OPA policy.
Here is a sample policy that you can evaluate using the On Step event for a scan step.
Warn or Block vulnerabilities using STO output variables
You can create policies based on the output variables generated by an STO scan step.
For example, suppose you want a policy to warn or block if a scan step finds any new vulnerabilities with severities of Critical or High. In this case, you can create a policy with the following OPA code:
Warn or Block the pipeline based on the code coverage results
Apply a policy to the scan step to either warn or block the pipeline based on the code coverage value. You can use the sample policy Security Test - Code Coverage. Below is a sample policy for reference:
Warn or Block the pipeline based on external policy failures
Apply a policy to the scan step to either warn or block the pipeline based on the external policy failures. You can use the sample policy Security Tests - External Policy Failures. Below is a sample policy for reference:
Warn or Block vulnerabilities from application layers of your container image
Apply a policy to the scan step to either warn or block the pipeline based on the vulnerabilities found in the application layers of your container image. You can use the following sample policy:
Warn or Block vulnerabilities from base image of your container image
Apply a policy to the scan step to either warn or block the pipeline based on vulnerabilities found in the base image of your container image.
The following sample policy works as follows:
Verifies whether the base image of your container image is approved.
If the base image is approved, no further checks are performed and the policy passes.
If the base image is not approved, it checks for vulnerabilities in the base image and warns or blocks the pipeline based on the severity count of the vulnerabilities.
Warn or Block vulnerabilities based on the EPSS score
Apply a policy to the scan step to either warn or block the pipeline based on the code coverage value. You can use the sample policy Security Test - EPSS score found in issues. Below is a sample policy for reference:
Warn or Block vulnerabilities based on CISA KEV count
Apply a policy to the scan step to warn or block the pipeline when the number of issues on the CISA Known Exploited Vulnerabilities (KEV) catalog exceeds your threshold. You can use the sample policy Security Tests – CISA Known Exploited Vulnerabilities. Below is a sample policy for reference:
Warn or Block Reachable or Exploitable Vulnerabilities reported by the Harness Scanner
Apply a policy to the Harness scan step to either warn or block the pipeline based on the reachability or exploitable vulnerabilities reported by the Harness Scanner.
You can use the sample policy Security Tests - Static Reachability of an Issue. Below is a sample policy for reference:
Last updated
Was this helpful?