Skip to content

Commit 1a39987

Browse files
ChrisPC-39Sebastian
andauthored
Grype and Trivy security vulnerability scanning (#348)
* Grype and Trivy security vulnerability scanning Signed-off-by: Sebastian <[email protected]> * Add grype security scan in github workflows Signed-off-by: Sebastian <[email protected]> * Ensure Grype is installed Signed-off-by: Sebastian <[email protected]> * Linting Signed-off-by: Sebastian <[email protected]> * Fix Push to GHCR Signed-off-by: Sebastian <[email protected]> * Fix key-less Cosign for image Signed-off-by: Sebastian <[email protected]> * Add info in SECURITY.md Signed-off-by: Sebastian <[email protected]> * Add info in docs Signed-off-by: Sebastian <[email protected]> --------- Signed-off-by: Sebastian <[email protected]> Co-authored-by: Sebastian <[email protected]>
1 parent 394e0d1 commit 1a39987

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

.github/workflows/docker-image.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# - Lints the Dockerfile with **Hadolint** (CLI) → SARIF
99
# - Lints the finished image with **Dockle** (CLI) → SARIF
1010
# - Generates an SPDX SBOM with **Syft**
11-
# - Scans the image for CRITICAL CVEs with **Trivy**
11+
# - Scans the image for CRITICAL CVEs with **Trivy/Grype**
1212
# - Uploads Hadolint, Dockle and Trivy results as SARIF files
1313
# - Pushes the image to **GitHub Container Registry (GHCR)**
1414
# - Signs & attests the image with **Cosign (key-less OIDC)**
@@ -142,7 +142,7 @@ jobs:
142142
output-file: sbom.spdx.json
143143

144144
# -------------------------------------------------------------
145-
# 6️⃣ Trivy CVE scan → SARIF
145+
# 6️⃣ Trivy, Grype CVE scan → SARIF
146146
# -------------------------------------------------------------
147147
- name: 🛡️ Trivy vulnerability scan
148148
id: trivy
@@ -160,6 +160,21 @@ jobs:
160160
with:
161161
sarif_file: trivy-results.sarif
162162

163+
- name: 📥 Installing Grype CLI
164+
run: |
165+
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
166+
- name: 🔍 Grype vulnerability scan
167+
run: |
168+
grype ${{ env.IMAGE_NAME }}:latest --scope all-layers --only-fixed
169+
- name: 📄 Generating Grype SARIF report
170+
run: |
171+
grype ${{ env.IMAGE_NAME }}:latest --scope all-layers --output sarif --file grype-results.sarif
172+
- name: ☁️ Upload Grype SARIF
173+
if: always()
174+
uses: github/codeql-action/upload-sarif@v3
175+
with:
176+
sarif_file: grype-results.sarif
177+
163178
# -------------------------------------------------------------
164179
# 7️⃣ Push both tags to GHCR
165180
# -------------------------------------------------------------
@@ -170,7 +185,8 @@ jobs:
170185
username: ${{ github.actor }}
171186
password: ${{ secrets.GITHUB_TOKEN }}
172187

173-
- name: 🚀 Push image to GHCR
188+
- name: 🚀 Push image to GHCR
189+
if: github.ref == 'refs/heads/main'
174190
run: |
175191
docker push $IMAGE_NAME:${{ env.TAG }}
176192
docker push $IMAGE_NAME:latest
@@ -179,9 +195,11 @@ jobs:
179195
# 8️⃣ Key-less Cosign sign + attest (latest **and** timestamp)
180196
# -------------------------------------------------------------
181197
- name: 📥 Install Cosign
198+
if: github.ref == 'refs/heads/main'
182199
uses: sigstore/cosign-installer@v3 # provides the matching CLI
183200

184201
- name: 🔏 Sign & attest images (latest + timestamp)
202+
if: github.ref == 'refs/heads/main'
185203
env:
186204
COSIGN_EXPERIMENTAL: "1"
187205
run: |

Makefile

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,30 @@ check-manifest: ## 📦 Verify MANIFEST.in completeness
509509
@echo "📦 Verifying MANIFEST.in completeness..."
510510
@$(VENV_DIR)/bin/check-manifest
511511

512+
# -----------------------------------------------------------------------------
513+
# 📑 GRYPE SECURITY/VULNERABILITY SCANNING
514+
# -----------------------------------------------------------------------------
515+
# help: grype-install - Install Grype
516+
# help: grype-scan - Scan all files using grype
517+
# help: grype-sarif - Generate SARIF report
518+
# help: security-scan - Run Trivy security-scan
519+
.PHONY: grype-install grype-scan grype-sarif security-scan
520+
521+
grype-install:
522+
@echo "📥 Installing Grype CLI..."
523+
@curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
524+
525+
grype-scan:
526+
@echo "🔍 Grype vulnerability scan..."
527+
@grype $(IMG):latest --scope all-layers --only-fixed
528+
529+
grype-sarif:
530+
@echo "📄 Generating Grype SARIF report..."
531+
@grype $(IMG):latest --scope all-layers --output sarif --file grype-results.sarif
532+
533+
security-scan: trivy grype-scan
534+
@echo "✅ Multi-engine security scan complete"
535+
512536
# -----------------------------------------------------------------------------
513537
# 📑 YAML / JSON / TOML LINTERS
514538
# -----------------------------------------------------------------------------
@@ -731,12 +755,18 @@ sonar-info:
731755
# 🛡️ SECURITY & PACKAGE SCANNING
732756
# =============================================================================
733757
# help: 🛡️ SECURITY & PACKAGE SCANNING
758+
# help: trivy-install - Install Trivy
734759
# help: trivy - Scan container image for CVEs (HIGH/CRIT). Needs podman socket enabled
735-
.PHONY: trivy
760+
.PHONY: trivy-install trivy
761+
762+
trivy-install:
763+
@echo "📥 Installing Trivy..."
764+
@curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
765+
736766
trivy:
737767
@systemctl --user enable --now podman.socket
738768
@echo "🔎 trivy vulnerability scan..."
739-
@trivy --format table --severity HIGH,CRITICAL image $(PROJECT_NAME)/$(PROJECT_NAME)
769+
@trivy --format table --severity HIGH,CRITICAL image $(IMG)
740770

741771
# help: dockle - Lint the built container image via tarball (no daemon/socket needed)
742772
.PHONY: dockle

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ pysonar-scanner - Run scan with Python wrapper (pysonar-scanner)
18761876
sonar-info - How to create a token & which env vars to export
18771877
🛡️ SECURITY & PACKAGE SCANNING
18781878
trivy - Scan container image for CVEs (HIGH/CRIT). Needs podman socket enabled
1879+
grype-scan - Scan container for security audit and vulnerability scanning
18791880
dockle - Lint the built container image via tarball (no daemon/socket needed)
18801881
hadolint - Lint Containerfile/Dockerfile(s) with hadolint
18811882
pip-audit - Audit Python dependencies for published CVEs

SECURITY.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Our security pipeline operates at multiple levels:
7575

7676
**Supply Chain Security**: We maintain strict oversight of our software supply chain through automated dependency vulnerability scanning, Software Bill of Materials (SBOM) generation, and license compliance checking to ensure all components meet security standards.
7777

78-
**Container Security Hardening**: Our containerized deployments follow security best practices including multi-stage builds, minimal base images (UBI Micro) with the latest updates, non-root user execution, read-only filesystems, and comprehensive container scanning with tools like Trivy, Dockle, and OSV-Scanner.
78+
**Container Security Hardening**: Our containerized deployments follow security best practices including multi-stage builds, minimal base images (UBI Micro) with the latest updates, non-root user execution, read-only filesystems, and comprehensive container scanning with tools like Trivy, Grype, Dockle, and OSV-Scanner.
7979

8080
**Runtime Security Monitoring**: Beyond build-time security, we implement runtime monitoring and security policies to detect and respond to potential threats in production environments.
8181

@@ -84,8 +84,8 @@ Our security pipeline operates at multiple levels:
8484
Our security toolchain includes **24+ different security and quality tools**, each serving a specific purpose in our defense strategy and executed on every pull request:
8585

8686
- **Static Analysis Security Testing (SAST)**: CodeQL, Bandit, and multiple type checkers
87-
- **Dependency Vulnerability Scanning**: OSV-Scanner, Trivy, npm audit, and GitHub dependency review
88-
- **Container Security**: Hadolint for Dockerfile linting, Dockle for container security, and Trivy for vulnerability scanning
87+
- **Dependency Vulnerability Scanning**: OSV-Scanner, Trivy, Grype, npm audit, and GitHub dependency review
88+
- **Container Security**: Hadolint for Dockerfile linting, Dockle for container security, and Trivy/Grype for vulnerability scanning
8989
- **Code Quality & Complexity**: Multiple linters ensuring code maintainability and reducing attack surface
9090
- **Documentation Security**: Spellcheck and markdown validation to prevent information disclosure
9191

@@ -98,6 +98,7 @@ We believe that security should enhance rather than hinder the development proce
9898
- `make test` - Full test suite with coverage analysis and security validation
9999
- `make bandit` - Security scanner for Python code vulnerabilities
100100
- `make trivy` - Container vulnerability scanning
101+
- `make grype-scan` - Container security audit and vulnerability scanning
101102
- `make dockle` - Container security and best practices analysis
102103
- `make hadolint` - Dockerfile linting for security issues
103104
- `make osv-scan` - Open Source Vulnerability database scanning
@@ -307,7 +308,8 @@ flowchart TD
307308
S --> S1[Hadolint - Dockerfile Linting]
308309
S --> S2[Dockle - Container Security]
309310
S --> S3[Trivy - Vulnerability Scanner]
310-
S --> S4[OSV-Scanner - Open Source Vulns]
311+
S --> S4[Grype - Security Audit]
312+
S --> S5[OSV-Scanner - Open Source Vulns]
311313
312314
T[Local Development] --> U[Make Targets]
313315
@@ -323,9 +325,10 @@ flowchart TD
323325
W --> W1[make bandit - Security Scanner]
324326
W --> W2[make osv-scan - Vulnerability Check]
325327
W --> W3[make trivy - Container Security]
326-
W --> W4[make dockle - Image Analysis]
327-
W --> W5[make hadolint - Dockerfile Linting]
328-
W --> W6[make pip-audit - Dependency Scanning]
328+
W --> W4[make grype-scan - Container Vulnerability Scan]
329+
W --> W5[make dockle - Image Analysis]
330+
W --> W6[make hadolint - Dockerfile Linting]
331+
W --> W7[make pip-audit - Dependency Scanning]
329332
330333
X --> X1[CycloneDX SBOM Generation]
331334
X --> X2[Dependency Inventory]

0 commit comments

Comments
 (0)