-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (127 loc) · 4.44 KB
/
security.yml
File metadata and controls
150 lines (127 loc) · 4.44 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Security
on:
pull_request:
branches: [main]
push:
branches: [main]
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
rust-security:
name: Rust Security Scan
runs-on: ubuntu-latest
defaults:
run:
working-directory: src-tauri
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Install Linux dependencies
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
- name: Install security tools
run: |
cargo install cargo-audit --locked
cargo install cargo-deny --locked
- name: Run security checks
id: security
shell: bash
run: |
set +e
cargo audit > /tmp/cargo-audit.txt 2>&1
audit_exit=$?
cargo deny check advisories > /tmp/cargo-deny.txt 2>&1
deny_exit=$?
cargo clippy --all-targets --all-features -- -D warnings -W clippy::unwrap_used -W clippy::expect_used -W clippy::panic > /tmp/cargo-clippy-security.txt 2>&1
clippy_exit=$?
echo "audit_exit=$audit_exit" >> "$GITHUB_OUTPUT"
echo "deny_exit=$deny_exit" >> "$GITHUB_OUTPUT"
echo "clippy_exit=$clippy_exit" >> "$GITHUB_OUTPUT"
if [ "$audit_exit" -ne 0 ] || [ "$deny_exit" -ne 0 ] || [ "$clippy_exit" -ne 0 ]; then
exit 1
fi
- name: Upload security logs
if: always()
uses: actions/upload-artifact@v4
with:
name: rust-security-logs
path: |
/tmp/cargo-audit.txt
/tmp/cargo-deny.txt
/tmp/cargo-clippy-security.txt
- name: Comment security results on PR
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
AUDIT_EXIT: ${{ steps.security.outputs.audit_exit }}
DENY_EXIT: ${{ steps.security.outputs.deny_exit }}
CLIPPY_EXIT: ${{ steps.security.outputs.clippy_exit }}
with:
script: |
const fs = require("fs");
const marker = "<!-- kore-rust-security-scan -->";
const readTail = (file) => {
try {
const data = fs.readFileSync(file, "utf8");
return data.slice(-3000);
} catch {
return "No output captured.";
}
};
const statusLine = (name, code) => Number(code) === 0 ? `- ${name}: PASS` : `- ${name}: FAIL (exit ${code})`;
const body = `${marker}
## Rust Security Scan
${statusLine("cargo audit", process.env.AUDIT_EXIT)}
${statusLine("cargo deny (advisories)", process.env.DENY_EXIT)}
${statusLine("cargo clippy security lints", process.env.CLIPPY_EXIT)}
<details><summary>cargo audit (tail)</summary>
\`\`\`
${readTail("/tmp/cargo-audit.txt")}
\`\`\`
</details>
<details><summary>cargo deny (tail)</summary>
\`\`\`
${readTail("/tmp/cargo-deny.txt")}
\`\`\`
</details>
<details><summary>cargo clippy (tail)</summary>
\`\`\`
${readTail("/tmp/cargo-clippy-security.txt")}
\`\`\`
</details>`;
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find((c) => c.user.type === "Bot" && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}