1+ name : Security Audit
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ paths :
7+ - ' **/Cargo.toml'
8+ - ' **/Cargo.lock'
9+ - ' .github/workflows/security.yml'
10+ pull_request :
11+ paths :
12+ - ' **/Cargo.toml'
13+ - ' **/Cargo.lock'
14+ - ' .github/workflows/security.yml'
15+ schedule :
16+ - cron : ' 0 0 * * *' # Daily at midnight UTC
17+
18+ env :
19+ CARGO_TERM_COLOR : always
20+
21+ jobs :
22+ security-audit :
23+ name : Security Audit
24+ runs-on : ubuntu-latest
25+ steps :
26+ - name : Checkout code
27+ uses : actions/checkout@v4
28+
29+ - name : Install Rust
30+ uses : dtolnay/rust-toolchain@stable
31+
32+ - name : Cache cargo registry
33+ uses : Swatinem/rust-cache@v2
34+ with :
35+ cache-on-failure : true
36+
37+ - name : Install cargo-audit
38+ uses : taiki-e/install-action@v2
39+ with :
40+ tool : cargo-audit
41+
42+ - name : Run security audit
43+ run : cargo audit --deny warnings
44+
45+ - name : Run audit and generate SARIF
46+ run : cargo audit --json | python3 -c "
47+ import sys, json
48+ sarif = {
49+ ' version ' : ' 2.1.0' ,
50+ ' runs ' : [{
51+ ' tool ' : {'driver': {'name': 'cargo-audit', 'informationUri': 'https://rustsec.org/'}},
52+ ' results ' : []
53+ }]
54+ }
55+ try :
56+ data = json.load(sys.stdin)
57+ for vuln in data.get('vulnerabilities', {}).get('list', []) :
58+ sarif['runs'][0]['results'].append({
59+ ' ruleId ' : vuln['advisory']['id'],
60+ ' level ' : ' error' if vuln['advisory'].get('cvss') and float(vuln['advisory']['cvss'].split('/')[0].split(':')[-1]) >= 7 else 'warning',
61+ ' message ' : {'text': vuln['advisory']['title']},
62+ ' locations ' : [{'physicalLocation': {'artifactLocation': {'uri': 'Cargo.lock'}}}]
63+ })
64+ except : pass
65+ print(json.dumps(sarif))
66+ " > audit.sarif || echo '{" version":"2.1.0","runs":[{"tool":{"driver":{"name":"cargo-audit"}},"results":[]}]}' > audit.sarif
67+
68+ - name : Upload audit results to GitHub Security
69+ if : always()
70+ uses : github/codeql-action/upload-sarif@v3
71+ with :
72+ sarif_file : audit.sarif
73+ category : dependency-audit
74+
75+ cargo-deny :
76+ name : Dependency Check
77+ runs-on : ubuntu-latest
78+ steps :
79+ - name : Checkout code
80+ uses : actions/checkout@v4
81+
82+ - name : Run cargo-deny
83+ uses : EmbarkStudios/cargo-deny-action@v2
84+ with :
85+ command : check
86+ arguments : --all-features
87+ continue-on-error : true # Don't fail until deny.toml is configured
88+
89+ dependency-review :
90+ name : Dependency Review
91+ runs-on : ubuntu-latest
92+ if : github.event_name == 'pull_request'
93+ steps :
94+ - name : Checkout code
95+ uses : actions/checkout@v4
96+
97+ - name : Dependency Review
98+ uses : actions/dependency-review-action@v4
99+ with :
100+ fail-on-severity : high
101+ deny-licenses : GPL-3.0, AGPL-3.0
0 commit comments