-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (144 loc) · 4.51 KB
/
security-scan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Security Scan
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ENV: test
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
jobs:
dependency-scan:
name: Dependency Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: |
cd src/backend && npm ci
cd ../web && npm ci
- name: Run backend npm audit
run: |
cd src/backend
npm audit --audit-level=high --json > backend-audit.json || true
- name: Run frontend npm audit
run: |
cd src/web
npm audit --audit-level=high --json > frontend-audit.json || true
- name: Run OWASP Dependency Check
uses: dependency-check/Dependency-Check_Action@main
with:
project: 'startup-metrics'
path: 'src'
format: 'HTML'
args: >
--suppression suppression.xml
--failOnCVSS 7
--enableRetired
- name: Upload scan results
uses: actions/upload-artifact@v3
with:
name: dependency-scan-results
path: |
src/backend/backend-audit.json
src/web/frontend-audit.json
reports
retention-days: 90
code-analysis:
name: CodeQL Analysis
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript, typescript
queries: security-extended,security-and-quality
config-file: ./.github/codeql/codeql-config.yml
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:javascript"
upload: true
container-scan:
name: Container Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build backend image
run: |
cd src/backend
docker build -t startup-metrics-backend:${{ github.sha }} .
- name: Build frontend image
run: |
cd src/web
docker build -t startup-metrics-frontend:${{ github.sha }} .
- name: Run Trivy vulnerability scanner - Backend
uses: aquasecurity/[email protected]
with:
image-ref: 'startup-metrics-backend:${{ github.sha }}'
format: 'sarif'
output: 'trivy-backend-results.sarif'
severity: 'HIGH,CRITICAL'
ignore-unfixed: true
- name: Run Trivy vulnerability scanner - Frontend
uses: aquasecurity/[email protected]
with:
image-ref: 'startup-metrics-frontend:${{ github.sha }}'
format: 'sarif'
output: 'trivy-frontend-results.sarif'
severity: 'HIGH,CRITICAL'
ignore-unfixed: true
- name: Upload Trivy scan results
uses: actions/upload-artifact@v3
with:
name: container-scan-results
path: |
trivy-backend-results.sarif
trivy-frontend-results.sarif
retention-days: 90
- name: Post scan results to Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: trivy-results.sarif
notify:
name: Notify Security Issues
needs: [dependency-scan, code-analysis, container-scan]
runs-on: ubuntu-latest
if: failure()
steps:
- name: Send Slack notification
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: |
{
"text": "Security scan failed in ${{ github.repository }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Security Scan Failed*\nRepository: ${{ github.repository }}\nBranch: ${{ github.ref }}\nCommit: ${{ github.sha }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ env.SLACK_WEBHOOK_URL }}