CodeQL #207
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: | |
| schedule: | |
| - cron: '27 21 * * *' # At 21:27 every day | |
| jobs: | |
| analyze: | |
| name: Analyze | |
| runs-on: kibana | |
| permissions: | |
| actions: read | |
| contents: read | |
| security-events: write | |
| if: github.repository == 'elastic/kibana' # Hack: Do not run on forks | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| language: [ 'javascript' ] | |
| branch: [ 'main', '8.19' ] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ matrix.branch }} | |
| persist-credentials: false | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8 | |
| with: | |
| languages: ${{ matrix.language }} | |
| config-file: ./.github/codeql/codeql-config.yml | |
| # TODO: Possibly required to follow all call paths, however, when enabled, the step below runs out of memory. | |
| # Possible workarounds: Apply for access to the GitHub beta where we can use beefier machines, or run it ourselves on Buildkite | |
| # - name: yarn kbn bootstrap | |
| # run: | | |
| # mkdir ~/.npm-global | |
| # npm config set prefix '~/.npm-global' | |
| # export PATH=~/.npm-global/bin:$PATH | |
| # yarn kbn bootstrap --no-validate --no-vscode | |
| - name: Set sha and branch | |
| run: | | |
| echo "CHECKOUT_REF=$(git symbolic-ref HEAD)" >> "$GITHUB_ENV" | |
| echo "CHECKOUT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" | |
| - name: Perform CodeQL Analysis | |
| uses: github/codeql-action/analyze@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8 | |
| id: analyze | |
| env: | |
| NODE_OPTIONS: "--max-old-space-size=8192" | |
| CODEQL_EXTRACTOR_JAVASCRIPT_OPTION_SKIP_TYPES: true | |
| with: | |
| category: "/language:${{matrix.language}}" | |
| ref: ${{ env.CHECKOUT_REF }} | |
| sha: ${{ env.CHECKOUT_SHA }} | |
| output: sarif-results | |
| - name: Dismiss alerts | |
| id: dismiss-alerts | |
| continue-on-error: true | |
| uses: advanced-security/dismiss-alerts@046d6b48d2e43cf563f96f67332c47c432eff83e # 2.0.2 | |
| env: | |
| GITHUB_TOKEN: ${{secrets.KIBANAMACHINE_TOKEN}} | |
| with: | |
| sarif-id: ${{ steps.analyze.outputs.sarif-id }} | |
| sarif-file: sarif-results/${{ matrix.language }}.sarif | |
| - name: Notify Slack on suppression failure | |
| if: steps.dismiss-alerts.outcome == 'failure' | |
| continue-on-error: true | |
| uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1 | |
| with: | |
| method: chat.postMessage | |
| token: ${{ secrets.CODE_SCANNING_SLACK_TOKEN }} | |
| payload: | | |
| channel: ${{ secrets.CODE_SCANNING_SLACK_CHANNEL_ID }} | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":warning: CodeQL alerts suppression step failed for ${{ github.repository }}." | |
| } | |
| }, | |
| { | |
| "type": "actions", | |
| "elements": [ | |
| { | |
| "type": "button", | |
| "text": { | |
| "type": "plain_text", | |
| "text": "View Workflow Run" | |
| }, | |
| "url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| } | |
| ] | |
| } | |
| ] | |
| alert: | |
| name: Alert | |
| runs-on: ubuntu-latest | |
| needs: analyze | |
| if: ${{ github.repository == 'elastic/kibana' && success() }} # Hack: Do not run on forks | |
| steps: | |
| - name: Checkout kibana-operations | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| repository: 'elastic/kibana-operations' | |
| ref: main | |
| path: ./kibana-operations | |
| token: ${{secrets.KIBANAMACHINE_TOKEN}} | |
| persist-credentials: false | |
| - name: CodeQL alert | |
| working-directory: ./kibana-operations/triage | |
| env: | |
| GITHUB_TOKEN: ${{secrets.KIBANAMACHINE_TOKEN}} | |
| GITHUB_REPO: kibana | |
| SLACK_TOKEN: ${{secrets.CODE_SCANNING_SLACK_TOKEN}} | |
| SLACK_CHANNEL: ${{secrets.CODE_SCANNING_SLACK_CHANNEL_ID}} | |
| CODE_SCANNING_ES_HOST: ${{secrets.CODE_SCANNING_ES_HOST}} | |
| CODE_SCANNING_ES_API_KEY: ${{secrets.CODE_SCANNING_ES_API_KEY}} | |
| CODE_SCANNING_INDEX_NAME: appex-codeql-alerts | |
| CODE_SCANNING_BRANCHES: main,8.19 | |
| run: | | |
| npm ci --omit=dev | |
| node codeql-alert | |
| notify_on_failure: | |
| name: Failure notification | |
| runs-on: ubuntu-latest | |
| needs: analyze | |
| if: failure() | |
| steps: | |
| - name: Send notification to slack | |
| uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1 | |
| with: | |
| method: chat.postMessage | |
| token: ${{ secrets.CODE_SCANNING_SLACK_TOKEN }} | |
| payload: | | |
| channel: ${{ secrets.CODE_SCANNING_SLACK_CHANNEL_ID }} | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":broken_heart: CodeQL analysis failed for ${{ github.repository }}." | |
| } | |
| }, | |
| { | |
| "type": "actions", | |
| "elements": [ | |
| { | |
| "type": "button", | |
| "text": { | |
| "type": "plain_text", | |
| "text": "View Workflow Run" | |
| }, | |
| "url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| } | |
| ] | |
| } | |
| ] | |