on
Integrate SAST, SCA and Container Scanning into your GitHub Actions workflow
Modern GitHub workflows should catch vulnerabilities as early as possible. A practical, recent approach is to combine three complementary scans inside your CI: semantic static analysis (SAST) with CodeQL, dependency-supply-chain checks with Dependabot (SCA), and container/image scanning with Trivy — plus SBOM generation to make results auditable. The rest of this article explains why that combo works and shows a compact GitHub Actions example you can adapt. (docs.github.com)
Why this trio?
- CodeQL (SAST) finds code-level issues — SQL injection patterns, insecure use of crypto, race conditions — by analyzing the code’s semantics rather than just regex matches. GitHub provides tight integration so CodeQL runs as part of your repo’s code scanning. (docs.github.com)
- Dependabot (SCA) tracks your package ecosystem and raises pull requests to fix known vulnerable dependency versions; it can also handle GitHub Actions updates. That keeps third-party libraries and workflow actions current with security patches. (docs.github.com)
- Trivy scans built images (and filesystems) for known CVEs in packages and OS layers. Running it in CI prevents shipping images with high- or critical-severity findings. (github.com)
Adding SBOM generation (for example with Syft via the anchore/sbom-action) creates a machine-readable inventory of components that other tools (or auditors) can consume. Anchore’s SBOM action runs Syft and can upload SBOM artifacts from the workflow. (github.com)
Key safety notes (non-negotiable)
- Pin GitHub Actions to immutable commit SHAs (not floating tags). Popular scanner actions have been targeted in supply-chain attacks; pinning reduces risk from force-pushed tags or compromised maintainers. Multiple security guides and incident reviews advise this practice. (labs.cloudsecurityalliance.org)
- Limit workflow permissions (principle of least privilege) and avoid exposing secrets to untrusted contexts (forked PRs). Tools like the OWASP GitHub Actions security cheat sheet explain specifics for hardening. (cheatsheetseries.owasp.org)
Example setup: files you’ll add
Below are compact examples showing:
- a dependabot.yml to keep dependencies and actions updated,
- a GitHub Actions workflow that runs CodeQL (SAST), generates an SBOM, and scans images with Trivy.
dependabot.yml (place in .github/dependabot.yml)
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 5
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
reviewers: ["team-security"]
(Dependabot will raise PRs for vulnerable packages and for actions in workflows when configured.) (docs.github.com)
.github/workflows/security-pipeline.yml (simplified)
name: Security pipeline
on: [push, pull_request]
permissions:
contents: read
security-events: write
packages: read
jobs:
codeql:
name: CodeQL analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript,python
- name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v3
sbom:
name: Generate SBOM
runs-on: ubuntu-latest
needs: codeql
steps:
- uses: actions/checkout@v4
- name: Generate SBOM (Syft via Anchore action)
uses: anchore/sbom-action@sha256:<IMMUTABLE_SHA>
with:
output-file: sbom.spdx.json
- name: Upload SBOM artifact
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.spdx.json
trivy:
name: Container scan
runs-on: ubuntu-latest
needs: sbom
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -t $:pr-$ .
- name: Trivy scan image
uses: aquasecurity/trivy-action@sha256:<IMMUTABLE_SHA>
with:
image-ref: $:pr-$
format: sarif
output: trivy.sarif
- name: Upload Trivy SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy.sarif
Notes:
- Replace @sha256:
with the exact digest for each action to avoid tag hijacking. Incident analyses show pinning actions to SHAs is an effective mitigation. ([labs.cloudsecurityalliance.org](https://labs.cloudsecurityalliance.org/wp-content/uploads/2026/04/CSA_research_note_teampcp_ai_infra_supply_chain_20260406-csa-styled.pdf?utm_source=openai)) - Use the minimal required permissions block and only enable writes for security-related scopes.
How this workflow fits into pull requests
- CodeQL runs on PRs and creates code-scanning alerts in GitHub’s UI so reviewers can see the context of the finding. Many organizations gate merges on “code scanning” and other security checks; configure them as required status checks. (docs.github.com)
- Dependabot opens PRs automatically (when enabled) to update vulnerable deps and actions, making automated remediation part of the dev flow. (docs.github.com)
- Trivy produces SARIF (or other reports) that can be uploaded into the same security tab or surfaced in PR comments, giving developers immediate, actionable feedback. (github.com)
Practical tuning tips
- Fail the pipeline only on severity thresholds you can realistically triage (for example, fail on CRITICAL, warn on HIGH). High false-positive rates lead to ignored checks. Community guidance and scanner docs include recommended flags for exit codes. (github.com)
- Keep an ignore list outside the workflow (e.g., .trivyignore or equivalent) and require expiry metadata for exceptions so tech debt doesn’t become permanent. Community practice suggests moving ignores into tracked files. (github.com)
- Generate SBOMs as artifacts (and sign them if your process needs provenance) so security teams and downstream consumers can verify component inventories. Anchore’s SBOM action and Syft are a common CI integration. (github.com)
Quick checklist before enabling this in a repo
- Enable code scanning/CodeQL in repository settings (or org policy) so results show up in the security tab. (docs.github.com)
- Add dependabot.yml to tune frequency and ecosystems. (docs.github.com)
- Pin third-party actions to SHAs and scope workflow permissions narrowly. Security incidents involving widely used scanner actions make immutable pins essential. (labs.cloudsecurityalliance.org)
Combining CodeQL, Dependabot, Trivy, and SBOMs gives layered coverage: semantic code problems, vulnerable dependencies, image-level CVEs, and an auditable inventory of components. That combination reduces surprise during release and makes it much easier for developers and security teams to act on findings inside the natural GitHub workflow. (docs.github.com)