|
| 1 | +name: Grype Scan |
| 2 | +run-name: Grype Scan ${{ inputs.docker_image }} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + # Inputs for manual run |
| 7 | + inputs: |
| 8 | + docker_image: |
| 9 | + description: 'Docker image. If no tag, it will be determined by version_helper.py' |
| 10 | + required: true |
| 11 | + workflow_call: |
| 12 | + # Inputs for workflow call |
| 13 | + inputs: |
| 14 | + docker_image: |
| 15 | + description: 'Docker image. If no tag, it will be determined by version_helper.py' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | +env: |
| 19 | + PYTHONUNBUFFERED: 1 |
| 20 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 21 | + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} |
| 22 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + grype_scan: |
| 26 | + name: Grype Scan |
| 27 | + runs-on: [self-hosted, altinity-on-demand, altinity-func-tester-aarch64] |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Docker |
| 33 | + uses: docker/setup-buildx-action@v3 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + run: | |
| 37 | + export TESTFLOWS_VERSION="2.4.19" |
| 38 | + sudo apt-get update |
| 39 | + sudo apt-get install -y python3-pip python3-venv |
| 40 | + python3 -m venv venv |
| 41 | + source venv/bin/activate |
| 42 | + pip install --upgrade requests chardet urllib3 |
| 43 | + pip install testflows==$TESTFLOWS_VERSION awscli==1.33.28 |
| 44 | + echo PATH=$PATH >>$GITHUB_ENV |
| 45 | +
|
| 46 | + - name: Set image tag if not given |
| 47 | + if: ${{ !contains(inputs.docker_image, ':') }} |
| 48 | + id: set_version |
| 49 | + run: | |
| 50 | + python3 ./tests/ci/version_helper.py | tee /tmp/version_info |
| 51 | + source /tmp/version_info |
| 52 | + echo "docker_image=${{ inputs.docker_image }}:${{ github.event.pull_request.number || 0 }}-$CLICKHOUSE_VERSION_STRING" >> $GITHUB_OUTPUT |
| 53 | + echo "commit_sha=$CLICKHOUSE_VERSION_GITHASH" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Run Grype Scan |
| 56 | + run: | |
| 57 | + DOCKER_IMAGE=${{ steps.set_version.outputs.docker_image || inputs.docker_image }} |
| 58 | + ./.github/grype/run_grype_scan.sh $DOCKER_IMAGE |
| 59 | +
|
| 60 | + - name: Parse grype results |
| 61 | + run: | |
| 62 | + python3 -u ./.github/grype/parse_vulnerabilities_grype.py -o nice --no-colors --log raw.log --test-to-end |
| 63 | +
|
| 64 | + - name: Transform and Upload Grype Results |
| 65 | + if: always() |
| 66 | + id: upload_results |
| 67 | + env: |
| 68 | + S3_BUCKET: "altinity-build-artifacts" |
| 69 | + COMMIT_SHA: ${{ steps.set_version.outputs.commit_sha || github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} |
| 70 | + PR_NUMBER: ${{ github.event.pull_request.number || 0 }} |
| 71 | + DOCKER_IMAGE: ${{ steps.set_version.outputs.docker_image || inputs.docker_image }} |
| 72 | + run: | |
| 73 | + ./.github/grype/transform_and_upload_results_s3.sh |
| 74 | +
|
| 75 | + - name: Create step summary |
| 76 | + if: always() |
| 77 | + id: create_summary |
| 78 | + run: | |
| 79 | + jq -r '"**Image**: \(.source.target.userInput)"' result.json >> $GITHUB_STEP_SUMMARY |
| 80 | + jq -r '.distro | "**Distro**: \(.name):\(.version)"' result.json >> $GITHUB_STEP_SUMMARY |
| 81 | + if jq -e '.matches | length == 0' result.json > /dev/null; then |
| 82 | + echo "No CVEs" >> $GITHUB_STEP_SUMMARY |
| 83 | + else |
| 84 | + echo "| Severity | Count |" >> $GITHUB_STEP_SUMMARY |
| 85 | + echo "|------------|-------|" >> $GITHUB_STEP_SUMMARY |
| 86 | + jq -r ' |
| 87 | + .matches | |
| 88 | + map(.vulnerability.severity) | |
| 89 | + group_by(.) | |
| 90 | + map({severity: .[0], count: length}) | |
| 91 | + sort_by(.severity) | |
| 92 | + map("| \(.severity) | \(.count) |") | |
| 93 | + .[] |
| 94 | + ' result.json >> $GITHUB_STEP_SUMMARY |
| 95 | + fi |
| 96 | +
|
| 97 | + HIGH_COUNT=$(jq -r '.matches | map(.vulnerability.severity) | map(select(. == "High")) | length' result.json) |
| 98 | + CRITICAL_COUNT=$(jq -r '.matches | map(.vulnerability.severity) | map(select(. == "Critical")) | length' result.json) |
| 99 | + TOTAL_HIGH_CRITICAL=$((HIGH_COUNT + CRITICAL_COUNT)) |
| 100 | + echo "total_high_critical=$TOTAL_HIGH_CRITICAL" >> $GITHUB_OUTPUT |
| 101 | +
|
| 102 | + if [ $TOTAL_HIGH_CRITICAL -gt 0 ]; then |
| 103 | + echo '## High and Critical vulnerabilities found' >> $GITHUB_STEP_SUMMARY |
| 104 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 105 | + cat raw.log | tfs --no-colors show tests | grep -Pi 'High|Critical' >> $GITHUB_STEP_SUMMARY |
| 106 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Set commit status |
| 110 | + if: always() |
| 111 | + uses: actions/github-script@v7 |
| 112 | + with: |
| 113 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + script: | |
| 115 | + github.rest.repos.createCommitStatus({ |
| 116 | + owner: context.repo.owner, |
| 117 | + repo: context.repo.repo, |
| 118 | + sha: '${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}', |
| 119 | + state: '${{ steps.create_summary.outputs.total_high_critical > 0 && 'failure' || 'success' }}', |
| 120 | + target_url: '${{ steps.upload_results.outputs.https_s3_path }}/results.html', |
| 121 | + description: 'Grype Scan Completed with ${{ steps.create_summary.outputs.total_high_critical }} high/critical vulnerabilities', |
| 122 | + context: 'Grype Scan ${{ steps.set_version.outputs.docker_image || inputs.docker_image }}' |
| 123 | + }) |
| 124 | +
|
| 125 | + - name: Upload artifacts |
| 126 | + if: always() |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: grype-results-${{ hashFiles('raw.log') }} |
| 130 | + path: | |
| 131 | + result.json |
| 132 | + nice.log.txt |
0 commit comments