Enable Static Code Analysis
This runbook describes how to use the new static code analysis workflow which scans repositories using multiple tools:
- Trivy for vulnerabilities and misconfigurations
- Terraform checks including
tflint,terraform validate, andterraform fmtfor Terraform-specific repositories
This document is informational only and does not embed or define any CI configuration files.
Creating the workflow
- Create a job that uses the reusable workflow from the NVVS DevOps GitHub Actions repository (in
.github/workflows/static-code-analysis.yml). - Configure the job to:
- Accept a path to a Trivy ignore file
- Optionally set the
REPO_TYPEvariable to'non-tf'to disable Terraform-specific checks
- Save the workflow file.
The workflow will now run as its own CI job alongside any other static analysis jobs.
jobs:
static-code-analysis:
name: static-code-analysis
uses: ministryofjustice/nvvs-devops-github-actions/.github/workflows/terraform-trivy.yml@v1
permissions:
actions: read
contents: read
pull-requests: write
security-events: write
with:
TRIVY_IGNORES: '.trivyignore.yaml'
REPO_TYPE: 'tf' # or 'non-tf' to skip Terraform-specific checks
How CI merge blocking works
- Enable branch protection rules on the target branch:
- The following status check is added in the branch protection rule and required to pass before merging
Static Code Analysis / Scan Status
- The following status check is added in the branch protection rule and required to pass before merging
- Open a pull request.
- GitHub Actions automatically runs all configured checks (trivy, and tflint, validate fmt checks for tf repos).
- The workflow evaluates Terraform code for vulnerabilities and misconfigurations.
- If Trivy reports high or critical findings:
- The Trivy job fails.
- The pull request cannot be merged.
- The pull request becomes mergeable only after:
- The issue is fixed in code, or
- A reviewed Trivy exception is added.
How to add safe exceptions
Trivy supports ignore files to document approved security exceptions.
- Create a Trivy ignore file in the root of the repository (must be .trivyignore.yaml) and pass as a parameter to the reusable workflow.
- Use the ignore file to suppress:
- Specific vulnerability IDs
- Specific Terraform misconfiguration checks and for specific paths example.
- Where supported, prefer resource-level exclusions (for example, inline Terraform annotations) to limit the scope of exceptions and avoid impacting the entire repository/path.
- Every exception must:
- Be intentional
- Be reviewed during pull request review
- Have a clear justification
- Be removed once remediation is complete
Exceptions are evaluated every time the workflow runs.
Expected workflow after enabling Trivy
After completing the steps above:
- Trivy runs automatically on pull requests + additional tf checks depending on the repo type.
- Security findings are visible in Github Code Scanning (a comment with relevant link will appear on pr)
- High and critical issues block merges Via branch protection rules
- Approved exceptions are explicit and reviewable
Ownership and review
- Owner: NVVS DevOps
- Slack:
#nvvs-devops - Review this runbook every 6 months or after CI changes
This page was last reviewed on 13 January 2026.
It needs to be reviewed again on 13 July 2026
by the page owner #nvvs-devops
.
This page was set to be reviewed before 13 July 2026
by the page owner #nvvs-devops.
This might mean the content is out of date.