add docker image scanner
This commit is contained in:
@@ -9,6 +9,12 @@ on:
|
||||
dockerfile_path:
|
||||
type: string
|
||||
default: "."
|
||||
run_image_scan:
|
||||
type: boolean
|
||||
default: true
|
||||
scan_severity:
|
||||
type: string
|
||||
default: "HIGH,CRITICAL"
|
||||
secrets:
|
||||
REGISTRY_USERNAME: { required: true }
|
||||
REGISTRY_PASSWORD: { required: true }
|
||||
@@ -74,6 +80,38 @@ jobs:
|
||||
docker tag "${FULL_IMAGE}:${SHA_SHORT}" "${FULL_IMAGE}:${MAJOR}"
|
||||
fi
|
||||
|
||||
- name: Image Vulnerability Scan
|
||||
if: ${{ inputs.run_image_scan }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Fallback for runner images without Trivy baked in. Pinned version +
|
||||
# checksum, never "latest": Trivy releases were compromised in the
|
||||
# March 2026 supply-chain incident (malicious v0.69.4). Keep in sync
|
||||
# with the ARGs in the PipelineImage Dockerfiles.
|
||||
TRIVY_VERSION=0.71.0
|
||||
TRIVY_SHA256=30a3d22b23f88c233f1658f562fb477cae3b3e8b4761109d515b7698daf85814
|
||||
if ! command -v trivy >/dev/null 2>&1; then
|
||||
echo "=== Trivy not in runner image, installing v${TRIVY_VERSION} ==="
|
||||
curl -sSfLO "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
|
||||
echo "${TRIVY_SHA256} trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" | sha256sum -c -
|
||||
tar -xzf "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" -C /usr/local/bin trivy
|
||||
rm "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
|
||||
fi
|
||||
trivy --version
|
||||
|
||||
SHA_SHORT="$(git rev-parse --short HEAD)"
|
||||
FULL_IMAGE="${{ secrets.DOCKER_REGISTRY }}/${{ inputs.image_name }}"
|
||||
|
||||
echo "=== Scanning ${FULL_IMAGE}:${SHA_SHORT} (fail on fixable ${{ inputs.scan_severity }}) ==="
|
||||
trivy image \
|
||||
--exit-code 1 \
|
||||
--severity "${{ inputs.scan_severity }}" \
|
||||
--ignore-unfixed \
|
||||
--scanners vuln,secret \
|
||||
"${FULL_IMAGE}:${SHA_SHORT}"
|
||||
|
||||
- name: Push image
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
Reference in New Issue
Block a user