Skip to content

Commit

Permalink
Update trivy worflow (#3416)
Browse files Browse the repository at this point in the history
* update trivy worflow

* update

* generate requirements.txt to tmp path to isolate product deps only

* update to use runner.temp path

* change requirements.txt output path for trivy

* update bandit config to exclude tools folder
  • Loading branch information
yunchu committed Apr 30, 2024
1 parent 467208a commit 2a8b0f1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .ci/ipas_default.config
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ exclude_dirs: [
'.vscode/',
'.git/',
'build/',
'tools/',
]

targets: [
'src',
]

### (optional) plugin settings - some test plugins require configuration data
Expand Down
5 changes: 5 additions & 0 deletions .ci/trivy.yaml → .ci/trivy-csv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ scan:
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
vulnerability:
ignore-unfixed: false
format: template
template: "@.ci/csv.tmpl"
output: trivy-results.csv
list-all-pkgs: true
debug: true
6 changes: 6 additions & 0 deletions .ci/trivy-json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ignore-policy: ""
ignorefile: .trivyignore
format: spdx-json
output: trivy-results.spdx.json
list-all-pkgs: true
debug: true
34 changes: 19 additions & 15 deletions .github/workflows/code_scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions: read-all

jobs:
Trivy-scan:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -26,22 +26,27 @@ jobs:
- name: Install dependencies
run: |
pip install --require-hashes --no-deps -r requirements/gh-actions.txt
pip-compile --generate-hashes -o /tmp/otx-dev-requirements.txt requirements/dev.txt
pip install --require-hashes --no-deps -r /tmp/otx-dev-requirements.txt
- name: Trivy Scanning
env:
TRIVY_DOWNLOAD_URL: ${{ vars.TRIVY_DOWNLOAD_URL }}
run: tox -vv -e trivy-scan
pip-compile --extra=full -o requirements.txt setup.py
- name: Trivy Scanning (CSV)
uses: aquasecurity/trivy-action@d710430a6722f083d3b36b8339ff66b32f22ee55 # 0.19.0
with:
trivy-config: ".ci/trivy-csv.yaml"
scan-type: "fs"
scan-ref: .
scanners: vuln,secret
- name: Trivy Scanning (spdx.json)
uses: aquasecurity/trivy-action@d710430a6722f083d3b36b8339ff66b32f22ee55 # 0.19.0
with:
trivy-config: ".ci/trivy-json.yaml"
scan-type: "fs"
scan-ref: .
- name: Upload Trivy results artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: trivy-results
path: |
.tox/trivy-spdx-otx.json
.tox/trivy-results-otx.txt
.tox/trivy-results-otx.csv
path: trivy-results*
Bandit:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -52,9 +57,8 @@ jobs:
- name: Install dependencies
run: |
pip install --require-hashes --no-deps -r requirements/gh-actions.txt
pip-compile --generate-hashes -o /tmp/otx-dev-requirements.txt requirements/dev.txt
pip install --require-hashes --no-deps -r /tmp/otx-dev-requirements.txt
rm /tmp/otx-dev-requirements.txt
pip-compile --generate-hashes -o ${{ runner.temp }}/requirements.txt requirements/dev.txt
pip install --require-hashes --no-deps -r ${{ runner.temp }}/requirements.txt
- name: Bandit Scanning
run: tox -e bandit-scan
- name: Upload Bandit artifact
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ deps =
allowlist_externals =
bandit
commands =
- bandit -r -c .ci/ipas_default.config {toxinidir}/ -f txt -o {toxworkdir}/bandit-report.txt
bandit -r -c .ci/ipas_default.config {toxinidir}/ -f txt -o {toxworkdir}/bandit-report.txt

0 comments on commit 2a8b0f1

Please sign in to comment.