Vulnerability alerts #4
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: 'Vulnerability alerts' | |
| on: | |
| schedule: | |
| - cron: '4 9 * * 1' # every Monday at 9:04 AM | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| vulnerability-alerts: read | |
| env: | |
| SEVERITIES: critical,high | |
| ALERT_THRESHOLD: 30 # hard limit (MAX_COUNT_SLACK) in the kunalnagarco/action-cve code | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Count alerts | |
| id: count_alerts | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| REPO="${{ github.repository }}" | |
| SEVERITIES="${{ env.SEVERITIES }}" | |
| alerts=$(gh api \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "/repos/$REPO/dependabot/alerts?state=open&per_page=100&severity=$SEVERITIES" \ | |
| --paginate \ | |
| --jq '.[]') | |
| total=$(echo "$alerts" | jq -s 'length') | |
| critical=$(echo "$alerts" | jq -s '[.[] | select(.security_advisory.severity=="critical")] | length') | |
| high=$(echo "$alerts" | jq -s '[.[] | select(.security_advisory.severity=="high")] | length') | |
| echo "total=$total" >> $GITHUB_OUTPUT | |
| echo "critical=$critical" >> $GITHUB_OUTPUT | |
| echo "high=$high" >> $GITHUB_OUTPUT | |
| echo "total=$total" | |
| echo "critical=$critical" | |
| echo "high=$high" | |
| - name: Send list to Slack | |
| uses: kunalnagarco/action-cve@v1.17.0 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| slack_webhook: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| count: ${{ env.ALERT_THRESHOLD }} | |
| severity: ${{ env.SEVERITIES }} | |
| - name: Extra Slack message | |
| if: fromJSON(steps.count_alerts.outputs.total) > fromJSON(env.ALERT_THRESHOLD) | |
| run: | | |
| set -euo pipefail | |
| threshold="${{ env.ALERT_THRESHOLD }}" | |
| critical="${{ steps.count_alerts.outputs.critical }}" | |
| high="${{ steps.count_alerts.outputs.high }}" | |
| repo="${{ github.repository }}" | |
| url="https://github.com/$repo/security/dependabot" | |
| payload=$(jq -n \ | |
| --arg critical "$critical" \ | |
| --arg high "$high" \ | |
| --arg threshold "$threshold" \ | |
| --arg url "$url" \ | |
| '{ | |
| text: [ | |
| "*:exclamation: The real number of alerts is more than \($threshold)*\n\n", | |
| "Critical: \($critical)\n", | |
| "High: \($high)\n\n", | |
| ":eyes: Please review manually:\n\($url)\n", | |
| "----------------------------------------------------------------------------------------------------------------" | |
| ] | join("") | |
| }') | |
| curl -X POST \ | |
| -H 'Content-type: application/json' \ | |
| --data "$payload" \ | |
| ${{ secrets.SLACK_WEBHOOK_URL }} |