Skip to content

Commit ef51eb6

Browse files
authored
Create security-gateway.yml
1 parent 528d541 commit ef51eb6

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Security Gateway
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read # Чтение содержимого репозитория
13+
pull-requests: write # Запись в pull request для добавления комментариев
14+
15+
jobs:
16+
security-gateway:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.9'
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
if [ -f "requirements.txt" ]; then
32+
pip install -r requirements.txt
33+
else
34+
echo "requirements.txt not found! Skipping dependency installation."
35+
fi
36+
37+
- name: Scan for vulnerabilities with Trivy
38+
id: trivy-scan
39+
uses: aquasecurity/trivy-action@master
40+
with:
41+
scan-type: fs # Сканирование файловой системы
42+
severity: CRITICAL,HIGH # Проверка только критических и высоких угроз
43+
exit-code: '1' # Возвращает ошибку, если найдены уязвимости
44+
45+
- name: Check Trivy results and stop release if vulnerabilities found
46+
if: steps.trivy-scan.outcome == 'failure'
47+
run: |
48+
echo "Critical or high vulnerabilities found! Stopping the release."
49+
exit 1 # Останавливаем пайплайн, если найдены критические уязвимости
50+
51+
- name: Generate Trivy report
52+
if: always() # Выполняется всегда, даже если предыдущие шаги завершились с ошибкой
53+
run: |
54+
trivy result --format json --output trivy-report.json .
55+
if [ -f "trivy-report.json" ]; then
56+
echo "Trivy report generated successfully."
57+
else
58+
echo "Trivy report not found!"
59+
fi
60+
61+
- name: Upload Trivy report as artifact
62+
if: always() # Выполняется всегда
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: trivy-report
66+
path: trivy-report.json
67+
68+
- name: Comment on PR with Trivy findings
69+
if: github.event_name == 'pull_request' && steps.trivy-scan.outcome == 'failure'
70+
uses: thollander/actions-comment-pull-request@v1
71+
with:
72+
message: |
73+
### Security Gateway Alert
74+
75+
Critical or high vulnerabilities have been detected by Trivy:
76+
77+
$(cat trivy-report.json | jq -r '.Results[] | .Vulnerabilities[] | "\(.PkgName): \(.VulnerabilityID) - \(.Severity)"' || echo "No detailed vulnerabilities found.")
78+
79+
Please address these issues before merging this PR.
80+
token: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Run CodeQL Analysis
83+
uses: github/codeql-action/analyze@v2
84+
with:
85+
category: "/language:python" # Анализ кода на Python

0 commit comments

Comments
 (0)