|
| 1 | +name: Scan Image |
| 2 | +description: Composite action to check an image for vulnerabilities |
| 3 | + |
| 4 | +inputs: |
| 5 | + image_name: |
| 6 | + description: "The name of the image to scan, including the registry e.g. docker.io/hello-world" |
| 7 | + required: true |
| 8 | + image_source: |
| 9 | + description: "The source of the image to scan" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - public |
| 13 | + - private_dockerhub |
| 14 | + - private_gar |
| 15 | + default: public |
| 16 | + fail_on: |
| 17 | + description: "Whether to fail the workflow if vulnerabilities are found" |
| 18 | + type: choice |
| 19 | + options: |
| 20 | + - critical |
| 21 | + - high |
| 22 | + - medium |
| 23 | + - low |
| 24 | + default: critical |
| 25 | + fail_on_threshold: |
| 26 | + description: "The threshold of vulnerabilities to fail the workflow on" |
| 27 | + type: integer |
| 28 | + default: 1 |
| 29 | + trivy_version: |
| 30 | + description: "The version of Trivy to use (The latest will be used if not provided)" |
| 31 | + type: string |
| 32 | + |
| 33 | +outputs: |
| 34 | + trivy: |
| 35 | + description: "The results of the Trivy scan" |
| 36 | + value: ${{ steps.run-trivy.outputs.results }} |
| 37 | + |
| 38 | +runs: |
| 39 | + using: composite |
| 40 | + steps: |
| 41 | + |
| 42 | + - name: Login to DockerHub |
| 43 | + id: login-to-dockerhub |
| 44 | + if: inputs.image_source == 'private_dockerhub' |
| 45 | + uses: grafana/shared-workflows/actions/[email protected] |
| 46 | + |
| 47 | + - name: Extract GAR registry |
| 48 | + id: extract-gar-registry |
| 49 | + if: inputs.image_source == 'private_gar' |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + IMAGE_NAME="${{ inputs.image_name }}" |
| 53 | + REGISTRY="${IMAGE_NAME%%/*}" |
| 54 | + echo "registry=${REGISTRY}" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + - name: Login to GAR |
| 57 | + id: login-to-gar |
| 58 | + if: inputs.image_source == 'private_gar' |
| 59 | + uses: grafana/shared-workflows/actions/login-to-gar@login-to-gar/v1.0.0 |
| 60 | + with: |
| 61 | + registry: ${{ steps.extract-gar-registry.outputs.registry }} |
| 62 | + |
| 63 | + - name: Setup Trivy (Latest) |
| 64 | + id: setup-trivy-latest |
| 65 | + if: inputs.trivy_version == '' |
| 66 | + uses: aquasecurity/[email protected] |
| 67 | + |
| 68 | + - name: Setup Trivy (Pinned) |
| 69 | + id: setup-trivy-pinned |
| 70 | + if: inputs.trivy_version != '' |
| 71 | + uses: aquasecurity/[email protected] |
| 72 | + with: |
| 73 | + version: ${{ inputs.trivy_version }} |
| 74 | + |
| 75 | + - name: Run Trivy |
| 76 | + id: run-trivy |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + trivy image ${{ inputs.image_name }} -f json > trivy.json |
| 80 | + cat trivy.json |
| 81 | + echo "results=$(cat trivy.json)" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + |
0 commit comments