Repository navigation
85 lines (77 loc) · 2.76 KB
/
Copy pathcomponent-python-security.yml
File metadata and controls
85 lines (77 loc) · 2.76 KB
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
# Workflow regarding python security scanning.
name: Python Security
on:
workflow_call:
inputs:
context:
description: "Path to the module to lint"
default: ""
type: string
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
jobs:
# https://github.com/marketplace/actions/anchore-container-scan
dependency-check:
name: Grype & Pip Audit dependency scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Checkout the current branch/merge state
- name: Grype Scan
uses: anchore/scan-action@v3
id: grype-scan
with:
path: ${{ inputs.context }}
- name: Upload grype sarif file
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.grype-scan.outputs.sarif }}
category: grype-scan
- name: Inspect grype SARIF report
if: always()
run: cat ${{ steps.grype-scan.outputs.sarif }}
- name: Pip Audit
uses: pypa/gh-action-pip-audit@v1.1.0
with:
inputs: ${{ inputs.context }}
code-check:
name: Bandit scan
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
permissions:
security-events: write
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Bandit + converter
working-directory: ./${{ inputs.context }}
run: |
python -m pip install --upgrade pip
python -m pip install "bandit>=1.8.6" bandit-sarif-formatter
- name: Run Bandit (JSON)
working-directory: ./${{ inputs.context }}
# Utilise -x pour exclure ce qui n'a pas besoin d'être scanné (réduit les faux positifs et les bugs snippet)
run: |
bandit -r . -c pyproject.toml \
-x ".venv,venv,dist,build,**/migrations/**,**/tests/data/**" \
-f json -o bandit.json || true
- name: Convert JSON -> SARIF
working-directory: ./${{ inputs.context }}
run: |
bandit_sarif_formatter bandit.json bandit.sarif
- name: Upload bandit sarif file
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ./${{ inputs.context }}/bandit.sarif
category: bandit-python-analysis
- name: Inspect bandit SARIF report
if: always()
run: cat ${{ inputs.context }}/bandit.sarif