-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathcreate-gh-security-scanning-issues.yml
More file actions
67 lines (59 loc) · 2.14 KB
/
Copy pathcreate-gh-security-scanning-issues.yml
File metadata and controls
67 lines (59 loc) · 2.14 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
name: Create GitHub Security Scanning Issues
on:
workflow_call:
inputs:
artifact-name:
description: 'Name of the artifact containing code scanning alerts'
required: false
type: string
default: gh-security-scanning-alerts
permissions:
issues: write
security-events: read
jobs:
create-gh-security-scanning-issues:
name: Create GitHub Security Scanning Issues
runs-on: ubuntu-latest
permissions:
issues: write
security-events: read
env:
GH_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
steps:
- name: Download alerts artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: ${{ inputs.artifact-name }}
- name: Create backlog issues for new findings
shell: bash
run: |
while IFS= read -r alert; do
RULE_ID=$(echo "$alert" | jq -r '.RuleId')
RULE_DESC=$(echo "$alert" | jq -r '.RuleDescription')
SEVERITY=$(echo "$alert" | jq -r '.SecuritySeverity // "unspecified"')
TOOL=$(echo "$alert" | jq -r '.Tool')
COUNT=$(echo "$alert" | jq -r '.Count')
PATHS=$(echo "$alert" | jq -r '.SamplePaths | join(", ")')
MARKER="automation:security-scan:${RULE_ID}"
existing=$(gh issue list \
--repo "${OWNER}/${REPO}" \
--search "\"[Security] ${RULE_DESC}\" in:title" \
--state open --json number --jq '.[0].number // empty')
if [[ -z "$existing" ]]; then
gh issue create \
--repo "${OWNER}/${REPO}" \
--title "[Security] ${RULE_DESC}" \
--label "security" \
--body "<!-- ${MARKER} -->
## Code Scanning Alert: ${RULE_DESC}
**Rule:** \`${RULE_ID}\`
**Severity:** ${SEVERITY}
**Tool:** ${TOOL}
**Affected files:** ${COUNT} occurrences
### Sample affected paths
${PATHS}
"
fi
done < <(jq -c '.[]' alerts.json)