@@ -13,42 +13,12 @@ jobs:
1313 uses : actions/checkout@v4
1414
1515 - name : Install dependencies
16- run : pip install -r requirements.txt
17-
16+ run : |
17+ pip install -r requirements.txt
18+
1819 - name : Run tests
1920 run : pytest tests/
20-
21-
22- # Run snyk code scanning for vulnerabilities
23- snyk_scan :
24- permissions :
25- contents : read
26- security-events : write
27- actions : read
28- runs-on : ubuntu-latest
29- steps :
30- - uses : actions/checkout@v4
31- - name : Set up Python
32- uses : actions/setup-python@v4
33- with :
34- python-version : " 3.12.5"
35-
3621
37- - name : Install dependencies
38- run : pip install -r requirements.txt
39-
40- - name : Install Snyk CLI
41- uses : snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb
42-
43- env :
44- SNYK_TOKEN : ${{ secrets.SNYK_TOKEN }}
45- - name : Snyk Code test
46- run : snyk code test --sarif > snyk-cide.sarif
47-
48- - name : Snyk Test Dependencies
49- run : snyk test
50-
51-
5222 # Scan the contianer and lists all security vulnerabilities
5323 trivy_scans :
5424 name : Run Trivy security scanner against the image
@@ -57,13 +27,16 @@ jobs:
5727 - name : Checkout code
5828 uses : actions/checkout@v4
5929
60- - name : Run Trivy vulnerability scanner
61- uses : aquasecurity/trivy-action@7b7aa264d83dc58691451798b4d117d53d21edfe
30+ - name : Build Docker Image
31+ run : |
32+ docker build -t awesome-fastapi:${{ github.sha }} . ###- This section needed to be added becasue the image was not persisting between jobs--##
33+
34+ - name : Run Trivy Vulnerability Scanner
35+ uses : aquasecurity/trivy-action@0.28.0
6236 with :
6337 image-ref : ' awesome-fastapi:${{ github.sha }}'
64- format : ' template'
65- template : ' @/contrib/sarif.tpl'
66- output : ' GitHub Actions/Trivy Automation'
38+ format : ' sarif'
39+ output : ' trivy-results.sarif'
6740 severity : ' CRITICAL,HIGH'
6841
6942 - name : Upload Trivy scan results to GitHub Security tab
@@ -75,17 +48,30 @@ jobs:
7548 runs-on : ubuntu-latest
7649 name : app scan
7750 steps :
78- - name : Checkout
79- uses : actions/checkout@v4
80- with :
81- ref : master
82-
83- - name : zap scan
84- uses : zaproxy/action-api-scan@v0.9.0
85- with :
86- token : ${{ secrets.GITHUB_TOKEN}}
87- docker_name : ' ghcr.io/zaproxy/zaproxy:stable'
88- format : openapi
89- target : ' <fast-api-url>'
90- rules_file_name : ' .zap/rules.tsv'
91- cmd_options : ' -a'
51+ - name : Checkout
52+ uses : actions/checkout@v4
53+
54+ # Build and Tag Image
55+ # Run Docker Image in detached mode
56+ - name : Build Docker Image
57+ run : |
58+ docker build -t awesome-fastapi:${{ github.sha }} .
59+ docker run -d -p 8080:8080 awesome-fastapi:${{ github.sha }}
60+
61+ - name : Wait for Docker container to be ready
62+ run : sleep 30
63+
64+ - name : Confirm Docker container is running
65+ run : docker ps
66+
67+ # Run OWASP ZAP scan
68+ - name : zap scan
69+ uses : zaproxy/action-api-scan@v0.9.0
70+ with :
71+ token : ${{ secrets.GITHUB_TOKEN }}
72+ docker_name : ' ghcr.io/zaproxy/zaproxy:stable'
73+ format : openapi
74+ target : ' http://0.0.0.0:8080'
75+ rules_file_name : ' .zap/rules.tsv'
76+ cmd_options : ' -a'
77+ allow_issue_writing : false
0 commit comments