2024-01-27 22:32:42 +00:00
|
|
|
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
|
|
|
|
|
2022-10-10 13:10:16 +00:00
|
|
|
name: report-on-vulnerabilities
|
2023-06-20 20:01:16 +00:00
|
|
|
|
2023-06-30 11:44:57 +00:00
|
|
|
permissions: {}
|
|
|
|
|
2022-10-10 13:10:16 +00:00
|
|
|
on:
|
|
|
|
workflow_dispatch: {}
|
|
|
|
schedule:
|
|
|
|
- cron: '23 2 * * *' # Every day at 02:23
|
2023-06-20 20:01:16 +00:00
|
|
|
|
2022-10-10 13:10:16 +00:00
|
|
|
env:
|
|
|
|
REGISTRY: ghcr.io
|
|
|
|
IMAGE_NAME: ${{ github.repository }}
|
2023-06-20 20:01:16 +00:00
|
|
|
|
2022-10-10 13:10:16 +00:00
|
|
|
jobs:
|
|
|
|
scan:
|
2023-06-21 15:15:55 +00:00
|
|
|
runs-on: ubuntu-latest
|
2022-10-10 13:10:16 +00:00
|
|
|
outputs:
|
|
|
|
results: ${{ steps.parse-results.outputs.results }}
|
2023-12-19 13:01:40 +00:00
|
|
|
steps:
|
|
|
|
- name: Get Branches Name
|
|
|
|
id: get-branches
|
|
|
|
run: |
|
2024-06-13 15:09:06 +00:00
|
|
|
all_branches=$(curl -s 'https://api.github.com/repos/${{ env.IMAGE_NAME }}/branches?per_page=100' | jq -r '.[].name | select(startswith("release-"))' | sort -rV | head -n 2)
|
2023-12-19 13:01:40 +00:00
|
|
|
releasebranch1=$(echo "$all_branches" | sed -n 1p)
|
|
|
|
releasebranch2=$(echo "$all_branches" | sed -n 2p)
|
|
|
|
|
|
|
|
echo "releasebranch1=$releasebranch1" >> $GITHUB_OUTPUT
|
|
|
|
echo "releasebranch2=$releasebranch2" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
- name: Scan for vulnerabilities in latest image
|
2024-06-07 08:26:44 +00:00
|
|
|
uses: aquasecurity/trivy-action@595be6a0f6560a0a8fc419ddf630567fc623531d # v0.8.0 (Trivy v0.34.0)
|
2023-12-19 13:01:40 +00:00
|
|
|
|
2022-10-10 13:10:16 +00:00
|
|
|
with:
|
|
|
|
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
|
|
format: json
|
|
|
|
ignore-unfixed: false
|
|
|
|
severity: HIGH,CRITICAL
|
2023-12-19 13:01:40 +00:00
|
|
|
output: scan1.json
|
|
|
|
|
|
|
|
- name: Scan for vulnerabilities in latest-1 image
|
2024-06-07 08:26:44 +00:00
|
|
|
uses: aquasecurity/trivy-action@595be6a0f6560a0a8fc419ddf630567fc623531d # v0.8.0 (Trivy v0.34.0)
|
2023-12-19 13:01:40 +00:00
|
|
|
with:
|
|
|
|
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get-branches.outputs.releasebranch1 }}
|
|
|
|
format: json
|
|
|
|
ignore-unfixed: false
|
|
|
|
severity: HIGH,CRITICAL
|
|
|
|
output: scan2.json
|
|
|
|
|
|
|
|
- name: Scan for vulnerabilities in latest-2 image
|
2024-06-07 08:26:44 +00:00
|
|
|
uses: aquasecurity/trivy-action@595be6a0f6560a0a8fc419ddf630567fc623531d # v0.8.0 (Trivy v0.34.0)
|
2023-12-19 13:01:40 +00:00
|
|
|
with:
|
|
|
|
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get-branches.outputs.releasebranch2 }}
|
|
|
|
format: json
|
|
|
|
ignore-unfixed: false
|
|
|
|
severity: HIGH,CRITICAL
|
|
|
|
output: scan3.json
|
|
|
|
|
|
|
|
- name: Merge scan results
|
|
|
|
id: merge-results
|
|
|
|
run: |
|
|
|
|
jq -s add scan1.json scan2.json scan3.json > scan.json
|
|
|
|
cat scan.json
|
2022-10-10 13:10:16 +00:00
|
|
|
|
|
|
|
- name: Parse scan results
|
|
|
|
id: parse-results
|
|
|
|
continue-on-error: true
|
|
|
|
run: |
|
2024-01-05 13:24:04 +00:00
|
|
|
VULNS=$(cat scan.json | jq '.Results[] | select(.Target=="ko-app/kyverno").Vulnerabilities | length')
|
2023-06-21 15:15:55 +00:00
|
|
|
if [[ $VULNS -eq 0 ]]
|
|
|
|
then
|
2022-10-10 13:10:16 +00:00
|
|
|
echo "No vulnerabilities found, halting"
|
2022-11-30 11:53:30 +00:00
|
|
|
echo "results=nothing" >> $GITHUB_OUTPUT
|
2023-06-21 15:15:55 +00:00
|
|
|
else
|
|
|
|
echo "Vulnerabilities found, creating issue"
|
|
|
|
echo "results=found" >> $GITHUB_OUTPUT
|
2022-10-10 13:10:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Upload vulnerability scan report
|
2023-09-07 10:05:24 +00:00
|
|
|
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
|
2023-06-21 15:15:55 +00:00
|
|
|
if: steps.parse-results.outputs.results == 'found'
|
2022-10-10 13:10:16 +00:00
|
|
|
with:
|
|
|
|
name: scan.json
|
|
|
|
path: scan.json
|
|
|
|
if-no-files-found: error
|
|
|
|
|
|
|
|
open-issue:
|
|
|
|
runs-on: ubuntu-latest
|
2023-06-21 15:15:55 +00:00
|
|
|
if: needs.scan.outputs.results == 'found'
|
2022-10-10 13:10:16 +00:00
|
|
|
needs: scan
|
2023-06-20 20:01:16 +00:00
|
|
|
permissions:
|
|
|
|
issues: write
|
2022-10-10 13:10:16 +00:00
|
|
|
steps:
|
2023-01-05 15:52:52 +00:00
|
|
|
- name: Checkout
|
2024-05-23 10:33:32 +00:00
|
|
|
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
2022-10-10 13:10:16 +00:00
|
|
|
- name: Download scan
|
2023-01-06 08:18:08 +00:00
|
|
|
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
|
2022-10-10 13:10:16 +00:00
|
|
|
with:
|
|
|
|
name: scan.json
|
|
|
|
- name: Set scan output
|
|
|
|
id: set-scan-output
|
2023-06-21 15:15:55 +00:00
|
|
|
run: echo "results=$(cat scan.json | jq -c)" >> $GITHUB_OUTPUT
|
2024-02-15 14:08:40 +00:00
|
|
|
- uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
|
2022-10-10 13:10:16 +00:00
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
RESULTS: ${{ steps.set-scan-output.outputs.results }}
|
|
|
|
with:
|
2023-06-22 13:33:48 +00:00
|
|
|
filename: .github/ISSUE_TEMPLATE/VULN-TEMPLATE.md
|