|
1 | | -name: Security Gatekeeper (Weekly) |
| 1 | +name: Security Scan (Dashboard & Log) |
2 | 2 |
|
3 | | -# Decision: Run heavy scans daily during hackathon, not on PR |
4 | | -# Reason: Syft+Grype takes 3-5min; use Dependabot+built-in tools for PR checks |
5 | | -# Hackathon ends 2026-02-21, so daily scan ensures coverage throughout the event |
| 3 | +# Decision: Use Trivy + GitHub Code Scanning for lightweight, dashboard-integrated security |
| 4 | +# Reason: Hackathon-friendly (non-blocking, fast), better UX than Issue accumulation |
6 | 5 | on: |
| 6 | + push: |
| 7 | + branches: ["main", "develop"] |
| 8 | + pull_request: |
| 9 | + branches: ["main", "develop"] |
7 | 10 | schedule: |
8 | | - # Daily at 3:00 AM JST (18:00 UTC previous day) - Review results each morning |
| 11 | + # Daily at 3:00 AM JST for comprehensive scan |
9 | 12 | - cron: "0 18 * * *" |
10 | | - workflow_dispatch: # Allow manual trigger anytime |
11 | | - push: |
12 | | - branches: ["main"] |
13 | | - paths: |
14 | | - - ".grype.yaml" |
15 | | - - ".github/workflows/security.yml" |
| 13 | + workflow_dispatch: |
16 | 14 |
|
17 | 15 | permissions: |
18 | 16 | contents: read |
19 | | - issues: write # For creating issues on vulnerability detection |
| 17 | + security-events: write # Required for uploading to Security tab |
20 | 18 |
|
21 | 19 | jobs: |
22 | | - security-check: |
23 | | - name: Deep Supply Chain & Secret Scan |
| 20 | + trivy-scan: |
| 21 | + name: Trivy Security Scan |
24 | 22 | runs-on: ubuntu-latest |
25 | | - timeout-minutes: 10 |
| 23 | + timeout-minutes: 5 |
26 | 24 |
|
27 | 25 | steps: |
28 | 26 | - name: Checkout code |
29 | 27 | uses: actions/checkout@v4 |
30 | | - with: |
31 | | - fetch-depth: 0 # Full history for TruffleHog |
32 | | - |
33 | | - # 1. Secret Scanning (TruffleHog) |
34 | | - # Decision: Full repository scan for scheduled runs (not diff-based) |
35 | | - # Reason: Scheduled scans should audit entire codebase to prevent blind spots |
36 | | - - name: Secret Scan |
37 | | - id: trufflehog |
38 | | - uses: trufflesecurity/trufflehog@v3.82.13 |
39 | | - with: |
40 | | - path: ./ |
41 | | - # Note: No base/head specified = full repository scan |
42 | | - extra_args: --only-verified |
43 | | - continue-on-error: true |
44 | 28 |
|
45 | | - # 2. SBOM Generation (Syft) |
46 | | - - name: Generate SBOM |
47 | | - uses: anchore/sbom-action@v0.17.9 |
| 29 | + # 1. Console output for immediate feedback in CI logs |
| 30 | + - name: Run Trivy (Log Output) |
| 31 | + uses: aquasecurity/trivy-action@0.28.0 |
48 | 32 | with: |
49 | | - path: . |
50 | | - format: spdx-json |
51 | | - output-file: sbom.spdx.json |
52 | | - |
53 | | - # 3. Vulnerability Scan (Grype) |
54 | | - # Decision: Fail on vulnerabilities but don't stop workflow (create issue instead) |
55 | | - # Reason: Need actual failure signal to trigger issue creation |
56 | | - - name: Vulnerability Scan |
57 | | - id: grype |
58 | | - uses: anchore/scan-action@v5.1.0 |
| 33 | + scan-type: "fs" |
| 34 | + scan-ref: "." |
| 35 | + format: "table" |
| 36 | + exit-code: "0" # Don't fail CI (hackathon-friendly) |
| 37 | + severity: "CRITICAL,HIGH" |
| 38 | + trivyignores: ".trivyignore" |
| 39 | + |
| 40 | + # 2. SARIF output for GitHub Security tab integration |
| 41 | + - name: Run Trivy (SARIF Output) |
| 42 | + uses: aquasecurity/trivy-action@0.28.0 |
59 | 43 | with: |
60 | | - sbom: sbom.spdx.json |
61 | | - fail-build: true # Exit code 1 on vulnerabilities (enables detection) |
62 | | - severity-cutoff: critical |
63 | | - output-format: table |
64 | | - continue-on-error: true # Don't stop workflow, proceed to issue creation |
65 | | - |
66 | | - # 4. Create Issue on Vulnerability Detection |
67 | | - # Decision: Avoid duplicate issues by checking for open security alerts |
68 | | - # Reason: Daily scans would create noise if vulnerabilities persist |
69 | | - - name: Create Security Issue |
70 | | - if: steps.grype.outcome == 'failure' || steps.trufflehog.outcome == 'failure' |
71 | | - uses: actions/github-script@v7 |
| 44 | + scan-type: "fs" |
| 45 | + scan-ref: "." |
| 46 | + format: "sarif" |
| 47 | + output: "trivy-results.sarif" |
| 48 | + exit-code: "0" # Don't fail CI |
| 49 | + severity: "CRITICAL,HIGH" |
| 50 | + trivyignores: ".trivyignore" |
| 51 | + |
| 52 | + # 3. Upload results to GitHub Security tab (visible like Dependabot alerts) |
| 53 | + - name: Upload Trivy scan results to GitHub Security tab |
| 54 | + uses: github/codeql-action/upload-sarif@v3 |
| 55 | + if: always() # Upload even if scan found issues |
72 | 56 | with: |
73 | | - script: | |
74 | | - const grypeFailure = '${{ steps.grype.outcome }}' === 'failure'; |
75 | | - const truffleFailure = '${{ steps.trufflehog.outcome }}' === 'failure'; |
76 | | -
|
77 | | - // Fixed title for deduplication |
78 | | - const title = '🔒 Security Alert: Automated Scan Results'; |
79 | | -
|
80 | | - // Check for existing open issue |
81 | | - const existingIssues = await github.rest.issues.listForRepo({ |
82 | | - owner: context.repo.owner, |
83 | | - repo: context.repo.repo, |
84 | | - state: 'open', |
85 | | - labels: 'security-scan', |
86 | | - per_page: 1 |
87 | | - }); |
88 | | -
|
89 | | - const issues = []; |
90 | | - if (grypeFailure) issues.push('Critical vulnerabilities in dependencies'); |
91 | | - if (truffleFailure) issues.push('Secrets detected in repository'); |
| 57 | + sarif_file: "trivy-results.sarif" |
| 58 | + category: "trivy-fs-scan" |
92 | 59 |
|
93 | | - const body = `## Latest Scan: ${new Date().toISOString().split('T')[0]} |
94 | | -
|
95 | | - **Issues Detected**: ${issues.join(', ')} |
96 | | - **Scan Date**: ${new Date().toISOString()} |
97 | | - **Workflow Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
98 | | -
|
99 | | - ### Detected Issues |
100 | | - ${grypeFailure ? '- ⚠️ **Critical vulnerabilities** in dependencies (see Grype logs)' : ''} |
101 | | - ${truffleFailure ? '- 🔑 **Secrets leaked** in repository (see TruffleHog logs)' : ''} |
102 | | -
|
103 | | - ### Action Required |
104 | | - 1. Review the workflow logs for detailed information |
105 | | - 2. ${grypeFailure ? 'Update affected dependencies or add exceptions to `.grype.yaml` with justification' : ''} |
106 | | - 3. ${truffleFailure ? 'Remove secrets from repository and rotate compromised credentials immediately' : ''} |
107 | | - 4. Close this issue once resolved |
| 60 | + secret-scan: |
| 61 | + name: Secret Scanning |
| 62 | + runs-on: ubuntu-latest |
| 63 | + timeout-minutes: 5 |
108 | 64 |
|
109 | | - ### Notes |
110 | | - - This is a daily automated scan during hackathon |
111 | | - - PRs are checked with lightweight tools (pip-audit/npm audit) |
112 | | - - Dependabot will create PRs for available updates |
113 | | - `; |
| 65 | + steps: |
| 66 | + - name: Checkout code |
| 67 | + uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + fetch-depth: 0 |
114 | 70 |
|
115 | | - if (existingIssues.data.length > 0) { |
116 | | - // Update existing issue |
117 | | - const issueNumber = existingIssues.data[0].number; |
118 | | - await github.rest.issues.createComment({ |
119 | | - owner: context.repo.owner, |
120 | | - repo: context.repo.repo, |
121 | | - issue_number: issueNumber, |
122 | | - body: `---\n${body}` |
123 | | - }); |
124 | | - console.log(`Updated existing issue #${issueNumber}`); |
125 | | - } else { |
126 | | - // Create new issue |
127 | | - await github.rest.issues.create({ |
128 | | - owner: context.repo.owner, |
129 | | - repo: context.repo.repo, |
130 | | - title: title, |
131 | | - body: body, |
132 | | - labels: ['security-scan', 'dependencies'] |
133 | | - }); |
134 | | - console.log('Created new security issue'); |
135 | | - } |
| 71 | + - name: TruffleHog Secret Scan |
| 72 | + uses: trufflesecurity/trufflehog@v3.82.13 |
| 73 | + with: |
| 74 | + path: ./ |
| 75 | + extra_args: --only-verified |
| 76 | + continue-on-error: true |
0 commit comments