Tutorials · DevSecOps & Cloud
How to Add Security Checks to a CI/CD Pipeline (Secrets, SAST, Dependencies, Images)
Shift security left: catch leaked secrets, insecure code, vulnerable dependencies and risky infrastructure settings automatically on every commit, before anything is deployed.
Before you start
- A Git repository with CI (GitHub Actions, GitLab CI, Jenkins or similar)
- Free tools: Gitleaks, Semgrep, Trivy
Step by step
Scan for secrets
Gitleaks finds API keys, passwords and tokens in code and Git history.
gitleaks detect --source . --redact -vRun static analysis (SAST)
Semgrep checks code for common security bugs such as injection and unsafe deserialisation.
semgrep scan --config auto --errorCheck dependencies and IaC
Trivy scans dependencies, Dockerfiles, Terraform and Kubernetes files.
trivy fs --scanners vuln,misconfig --severity HIGH,CRITICAL --exit-code 1 .Scan the built image
After docker build, scan the exact image you are going to deploy.
trivy image --ignore-unfixed --severity CRITICAL --exit-code 1 registry.example.com/app:${GIT_SHA}Put it together in CI
Example GitHub Actions job (similar for other CI systems):
jobs: security: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: { fetch-depth: 0 } - run: docker run --rm -v $PWD:/repo zricethezav/gitleaks:latest detect --source /repo --redact - run: docker run --rm -v $PWD:/src semgrep/semgrep semgrep scan --config auto --error /src - run: docker run --rm -v $PWD:/src aquasec/trivy:latest fs --exit-code 1 --severity HIGH,CRITICAL /src
Protect the main branch
Require the security job to pass and a code review before merging. Nobody pushes directly to main.
Handle findings
Fix real issues, mark false positives with a comment, and track accepted risks with an owner and expiry date.
Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.
Pro tips
- Start in report-only mode for two weeks, then make the checks blocking once the noise is under control.
- Pin tool versions in CI so results do not change unexpectedly.
- If a secret is leaked, rotate it immediately: removing it from Git is not enough.
FAQ
Frequently asked questions
Will this slow down the pipeline?
Usually by one to three minutes. Run the quick checks on every push and deeper scans nightly.
Keep learning
Related guides
Scan images with Trivy
Read more →Manage secrets with Vault or OpenBao
Read more →Keep network configs in Git
Read more →How to Scan Container Images, Code and IaC for Vulnerabilities With Trivy
Trivy is a free scanner for container images, file systems, Git repositories and infrastructure-as-code. Find vulnerable packages and misconfigurations before they reach production.
Read more →How to Generate an SBOM for Your Software and Scan It With Grype
A Software Bill of Materials lists every component in your software. Customers and regulations (such as the EU Cyber Resilience Act) increasingly ask for it. Generate SBOMs with Syft and check them for vulnerabilities with Grype.
Read more →How to Keep Passwords and API Keys Out of Code With Vault or OpenBao
Hard-coded passwords end up in Git, chat and backups. Store secrets centrally in HashiCorp Vault or its open-source fork OpenBao, control who can read them and let applications fetch them at runtime.
Read more →Stuck on a step?
Ask Navijin technical support or an authorised partner for help with your configuration.