Skip to content

[PAN-1943] Trivy analysis #28

[PAN-1943] Trivy analysis

[PAN-1943] Trivy analysis #28

name: DockerVulnerabilities
on:
push:
branches:
- main
pull_request:
jobs:
docker-analysis:
name: Trivy analysis for Docker image
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
# - uses: step-security/harden-runner@v2
# with:
# disable-sudo: false
# egress-policy: audit
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: buildx
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-v1.0-service-node-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-v1.0-service-node-
- name: Build and load
run: |
docker buildx bake \
--set "*.cache-from=type=local,src=/tmp/.buildx-cache" \
--set "*.cache-to=type=local,dest=/tmp/.buildx-cache-new" \
--set "*.platform=linux/amd64" \
--builder ${{ steps.buildx.outputs.name }} \
-f docker-compose.yml \
--load \
app worker
env:
DOCKER_TAG: analysis-latest
# - name: Set output url
# id: set-output-url
# run: |
# echo "deployment_dockerhub_url=https://hub.docker.com/r/pantosio/service-node/tags?name=analysis" >> $GITHUB_OUTPUT
# - name: Run Trivy Image Docker vulnerability scanner
# uses: aquasecurity/[email protected]
# with:
# image-ref: 'service-node-${{ github.sha }}'
# format: 'table'
# output: 'trivy-image-scan-results.output'
# severity: 'CRITICAL,HIGH'
- name: Sign the images
run: |
for app in $(docker buildx bake -f docker-compose.yml --print --progress "plain" | jq -r '.target[].tags | add'); do
for image in $(docker buildx imagetools inspect $app --raw | jq -r '.manifests[].digest'); do
echo "Check $image from $app";
done;
done;
- name: Scan vulnerabilities app image
uses: aquasecurity/[email protected]
with:
image-ref: 'pantosio/service-node-app'
format: 'sarif'
output: 'trivy-app-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results for app to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-app-results.sarif'
# - name: Store Trivy scan results in env
# run: |
# echo 'TRIVY_IMAGE_RESULTS<<EOF' >> $GITHUB_ENV
# cat trivy-image-scan-results.output >> $GITHUB_ENV
# echo 'EOF' >> $GITHUB_ENV
- name: Move cache
if: always()
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# - name: Add comment to PR
# uses: actions/github-script@v6
# if: always()
# with:
# script: |
# const name = '${{ github.workflow }}';
# const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
# const success = '${{ job.status }}' === 'success';
# await github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: `${{ env.TRIVY_IMAGE_RESULTS }}`
# })
# - name: Comment Trivy scan results in PR
# uses: thollander/actions-comment-pull-request@v2
# with:
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# message: |
# ## Trivy scan results
# ### Docker image scan
# ```
# ${{ env.TRIVY_IMAGE_RESULTS }}
# ```
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v3
# with:
# sarif_file: 'trivy-image-scan-results.sarif'