CodeQL #94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: oracle-vm-32cpu-128gb-x86-64 | |
language: 'cpp' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | |
- name: Initialize CodeQL | |
uses: github/codeql-action/init@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3 | |
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 cmake automake autoconf make ninja-build curl unzip \ | |
virtualenv openjdk-11-jdk build-essential libc++1 | |
mkdir -p bin/clang17 | |
cd bin/clang17 | |
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz | |
tar -xf clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz --strip-components 1 | |
- name: Build (for C++) | |
if: matrix.config.language == 'cpp' | |
run: | | |
bazel/setup_clang.sh bin/clang17 | |
bazelisk shutdown | |
CARGO_BAZEL_REPIN=true bazel build \ | |
-c fastbuild \ | |
--spawn_strategy=local \ | |
--discard_analysis_cache \ | |
--nouse_action_cache \ | |
--features="-layering_check" \ | |
--config=clang \ | |
--config=ci \ | |
cilium-envoy | |
- name: Autobuild | |
if: matrix.config.language != 'cpp' | |
uses: github/codeql-action/autobuild@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3 | |
- name: Perform CodeQL Analysis | |
uses: github/codeql-action/analyze@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3 | |
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 |