Repository navigation
128 lines (120 loc) · 4.32 KB
/
Copy pathcodeql.yml
File metadata and controls
128 lines (120 loc) · 4.32 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
name: CodeQL
on:
workflow_dispatch:
schedule:
# Run at the end of every day from Monday to Friday
- cron: '0 0 * * 1-5'
jobs:
analyze:
name: Analyze
runs-on: ${{ matrix.config.runner }}
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
config:
- runner: ubuntu-24.04
language: 'actions'
- runner: ubuntu-24.04
language: 'go'
- runner: ${{ vars.PROXY_BUILD_GITHUB_RUNNER }}
language: 'cpp'
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Initialize CodeQL
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4
with:
languages: ${{ matrix.config.language }}
- name: Install deps (for C++)
if: matrix.config.language == 'cpp'
shell: bash
run: |
sudo apt-get update --error-on=any
sudo apt-get install --yes \
libtool automake autoconf curl unzip
- name: Build (for C++)
if: matrix.config.language == 'cpp'
run: |
bazelisk shutdown
bazel build \
-c fastbuild \
--spawn_strategy=local \
--discard_analysis_cache \
--nouse_action_cache \
--features="-layering_check" \
--noshow_progress \
--noshow_loading_progress \
//:cilium-envoy
- name: Autobuild
if: matrix.config.language != 'cpp'
uses: github/codeql-action/autobuild@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4
with:
category: '/language:${{matrix.config.language}}'
output: sarif-output-${{ matrix.config.language }}.sarif
- name: Filter SARIF Results
run: |
REPO_URL="https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/"
jq --arg baseUrl "$REPO_URL" '[.runs[].results[] |
{
ruleId: .ruleId,
message: .message.text,
url: "\($baseUrl)\(.locations[0].physicalLocation.artifactLocation.uri)#L\(.locations[0].physicalLocation.region.startLine)\(if .locations[0].physicalLocation.region.endLine != null then "-L\(.locations[0].physicalLocation.region.endLine)" else "" end)"
}]' sarif-output-${{ matrix.config.language }}.sarif/${{ matrix.config.language }}.sarif > filtered-${{ matrix.config.language }}.json
- name: Display Filtered Results
run: cat filtered-${{ matrix.config.language }}.json
- name: Send Slack Notification
env:
SEC_BOT_SLACK_WEBHOOK: ${{ secrets.SEC_BOT_SLACK_WEBHOOK }}
CHANNEL: "#security-team"
run: |
jq -c '.[]' filtered-${{ matrix.config.language }}.json | while read -r item; do
RULE_ID=$(echo "$item" | jq -r '.ruleId')
MESSAGE=$(echo "$item" | jq -r '.message')
URL=$(echo "$item" | jq -r '.url')
PAYLOAD=$(cat <<EOF
{
"channel": "$CHANNEL",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "🚨 CodeQL Alert for ${{ matrix.config.language }} 🚨",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Rule:* $RULE_ID"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Message:* $MESSAGE"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*File:* $URL"
}
}
]
}
EOF
)
curl -X POST -H "Authorization: Bearer $SEC_BOT_SLACK_WEBHOOK" \
-H "Content-type: application/json" \
--data-raw "$PAYLOAD" https://slack.com/api/chat.postMessage
done