Repository navigation
101 lines (96 loc) · 3.72 KB
/
Copy pathsecurity.yml
File metadata and controls
101 lines (96 loc) · 3.72 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
name: Security
on:
pull_request:
push:
branches: [main]
schedule:
- cron: "23 9 * * 1"
permissions:
contents: read
pull-requests: read
jobs:
local-security:
name: Local security checks
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
- name: Install Python security tools
# Editable install of this repo's own package plus the dev tools. pip
# resolves these from the pyproject ranges at CI time; uv.lock is NOT
# consulted here. The dependency audit itself runs against uv.lock
# (via `uv export` in scripts/security), not this ad hoc environment.
run: python -m pip install -e '.[dev]' # NOSONAR
- name: Install uv
# Lets scripts/security export and audit the locked set in uv.lock.
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
enable-cache: false
version: "0.13.1"
- name: Install Gitleaks
uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run repository security script
run: GITHUB_USAGE_SKIP_GITLEAKS=1 scripts/security
# Dependabot alerts are never raised for actions pinned by commit SHA (only
# for semver tags), so check pinned actions against GitHub's advisory
# database here. zizmor resolves each SHA to its release tag. Only the
# known-vulnerable-actions audit fails the job; other zizmor findings are
# out of scope for this check.
vulnerable-actions:
name: Known-vulnerable actions (zizmor)
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Install zizmor
run: "pip install --only-binary=:all: zizmor==1.31.0"
- name: Check actions against GitHub security advisories
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ -z "${GH_TOKEN:-}" ]; then echo "::error::GH_TOKEN is empty; zizmor would skip its online audits"; exit 1; fi
set +e
zizmor --format=json . > "$RUNNER_TEMP/zizmor.json"
rc=$?
set -e
# 0 = no findings, 10-14 = findings by severity; anything else
# (e.g. 1) means the audit itself failed, which must not pass.
if [ "$rc" -ne 0 ] && { [ "$rc" -lt 10 ] || [ "$rc" -gt 14 ]; }; then
echo "::error::zizmor failed (exit $rc)"
exit 1
fi
python3 - <<'PY'
import json
import os
import sys
findings = [
f for f in json.load(open(os.path.join(os.environ["RUNNER_TEMP"], "zizmor.json")))
if f["ident"] == "known-vulnerable-actions" and not f.get("ignored")
]
for f in findings:
loc = (f.get("locations") or [{}])[0]
key = loc.get("symbolic", {}).get("key", {})
path = key.get("Local", {}).get("verbatim_path", "?") if isinstance(key, dict) else "?"
line = loc.get("concrete", {}).get("location", {}).get("start_point", {}).get("row", 0) + 1
note = loc.get("symbolic", {}).get("annotation", "")
print(f"::error file={path},line={line}::{f['desc']}: {note}")
print(f"{len(findings)} known-vulnerable action reference(s)")
sys.exit(1 if findings else 0)
PY