|
| 1 | +# ECR Image Scanning GitHub Action |
| 2 | + |
| 3 | +This GitHub Action automatically scans an ECR (Elastic Container Registry) image when it is pushed to the repository. It utilizes the AWS CLI and ECR scanning capabilities to perform the scan and provide a scan report. |
| 4 | + |
| 5 | +## Pre-requisites |
| 6 | + |
| 7 | +To use this action, ensure that you have the AWS CLI installed and properly configured in your runner environment. Additionally, make sure you provide the required AWS credentials with the necessary permissions to access and scan the ECR image.. |
| 8 | + |
| 9 | + |
| 10 | +## Description |
| 11 | + |
| 12 | +This action utilizes a shell script executed within a Docker container to identify critical and high-level vulnerabilities linked to an image being pushed to the ECR repository. |
| 13 | +## Usage |
| 14 | +``` |
| 15 | +name: Push to ECR |
| 16 | +
|
| 17 | +on: |
| 18 | + pull_request: |
| 19 | + branches: |
| 20 | + - main |
| 21 | +jobs: |
| 22 | + Build-Push-Scan-Image: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Scan Docker image |
| 26 | + id: docker-scan |
| 27 | + uses: Ujjwal048/action-ecr-image-scan@main |
| 28 | + env: |
| 29 | + ECR_REPOSITORY: apparel-backend |
| 30 | + IMAGE_TAG: ${{ github.sha }} |
| 31 | + with: |
| 32 | + ecr_repository: ${{ env.ECR_REPOSITORY }} |
| 33 | + image_tag: ${{ env.IMAGE_TAG }} |
| 34 | + pr_comment: true |
| 35 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + url: ${{ github.event.pull_request.comments_url }} |
| 37 | + aws_region: ap-south-1 |
| 38 | + - name: Fail workflow if vulnerabilities found |
| 39 | + env: |
| 40 | + vulnerability: ${{ steps.docker-scan.outputs.VULNERABILITY }} |
| 41 | + block_build_on_failure: true |
| 42 | + run: | |
| 43 | + if [ "${{env.block_build_on_failure }}" = true && "${{ env.vulnerability }}" = true ]; then |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +``` |
| 47 | +## Input |
| 48 | + |
| 49 | + - aws-region (required): The AWS region where your ECR repository is located. |
| 50 | + - ecr_repository (required): The name of your ECR repository. |
| 51 | + - image_tag (required): Tag of the image being pushed |
| 52 | + - pr_comment (required): true/false |
| 53 | + - github_token (required): For updating th PR comment with scan result |
| 54 | + - url (required): URL for calling the POST request to update PR |
| 55 | + |
| 56 | +## Output |
| 57 | + |
| 58 | +After the scan is completed, this action will produce the scan results and provide a link to the scan report. The scan report and the detailed report URL in the AWS console will be included as comments in the pull request and displayed in the GitHub step summary for easy access and visibility. |
| 59 | +### Parameters passed as ouput |
| 60 | + |
| 61 | + - VULNERABILITY : If vulnerabilities are detected or not |
| 62 | + |
| 63 | + |
| 64 | +## Sample Output |
| 65 | +#### Github PR comment |
| 66 | + |
| 67 | + |
| 68 | +#### Github Summary Report |
| 69 | + |
0 commit comments