CodeQL #336
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: ${{ vars.PROXY_BUILD_GITHUB_RUNNER }} | |
| language: 'cpp' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # 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 libtinfo5 automake autoconf curl unzip | |
| # Note: the llvm/clang version should match the version specifed in: | |
| # - bazel/repository_locations.bzl | |
| # - .github/workflows/codeql-push.yml | |
| # - https://github.com/envoyproxy/envoy-build-tools/blob/main/build_container/build_container_ubuntu.sh#L84 | |
| mkdir -p bin/clang18.1.8 | |
| cd bin/clang18.1.8 | |
| wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz | |
| tar -xf clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz --strip-components 1 | |
| - name: Build (for C++) | |
| if: matrix.config.language == 'cpp' | |
| run: | | |
| bazel/setup_clang.sh bin/clang18.1.8 | |
| bazelisk shutdown | |
| 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@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # v4 | |
| - name: Perform CodeQL Analysis | |
| uses: github/codeql-action/analyze@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # 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 |