Image Scan #168
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: Image Scan | |
| on: | |
| schedule: | |
| - cron: 0 13 * * MON # Every Monday at 1PM UTC (9AM EST) | |
| workflow_dispatch: | |
| permissions: | |
| id-token: write | |
| contents: read | |
| env: | |
| TERRAFORM_AWS_ASSUME_ROLE: ${{ secrets.TERRAFORM_AWS_ASSUME_ROLE }} | |
| AWS_DEFAULT_REGION: us-west-2 | |
| jobs: | |
| ContainerImageScan: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| container_images: | |
| - registry: ".manager.image.repositoryDomainMap.public" | |
| repository: ".manager.image.repository" | |
| tag: ".manager.image.tag" | |
| - registry: ".manager.autoInstrumentationImage.java.repositoryDomain" | |
| repository: ".manager.autoInstrumentationImage.java.repository" | |
| tag: ".manager.autoInstrumentationImage.java.tag" | |
| - registry: ".manager.autoInstrumentationImage.python.repositoryDomain" | |
| repository: ".manager.autoInstrumentationImage.python.repository" | |
| tag: ".manager.autoInstrumentationImage.python.tag" | |
| - registry: ".manager.autoInstrumentationImage.dotnet.repositoryDomain" | |
| repository: ".manager.autoInstrumentationImage.dotnet.repository" | |
| tag: ".manager.autoInstrumentationImage.dotnet.tag" | |
| - registry: ".manager.autoInstrumentationImage.nodejs.repositoryDomain" | |
| repository: ".manager.autoInstrumentationImage.nodejs.repository" | |
| tag: ".manager.autoInstrumentationImage.nodejs.tag" | |
| - registry: ".agent.image.repositoryDomainMap.public" | |
| repository: ".agent.image.repository" | |
| tag: ".agent.image.tag" | |
| - registry: ".dcgmExporter.image.repositoryDomainMap.public" | |
| repository: ".dcgmExporter.image.repository" | |
| tag: ".dcgmExporter.image.tag" | |
| - registry: ".neuronMonitor.image.repositoryDomainMap.public" | |
| repository: ".neuronMonitor.image.repository" | |
| tag: ".neuronMonitor.image.tag" | |
| steps: | |
| - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 | |
| with: | |
| role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE }} | |
| aws-region: ${{ env.AWS_DEFAULT_REGION }} | |
| - name: "Get image registry" | |
| id: registry | |
| uses: mikefarah/yq@751d8ad57b84f1794661bc70c0afb92a22ad7b3c # v4.53.2 | |
| with: | |
| cmd: yq '${{ matrix.container_images.registry }}' charts/amazon-cloudwatch-observability/values.yaml | |
| - name: "Get image repository" | |
| id: repository | |
| uses: mikefarah/yq@751d8ad57b84f1794661bc70c0afb92a22ad7b3c # v4.53.2 | |
| with: | |
| cmd: yq '${{ matrix.container_images.repository }}' charts/amazon-cloudwatch-observability/values.yaml | |
| - name: "Get image tag" | |
| id: tag | |
| uses: mikefarah/yq@751d8ad57b84f1794661bc70c0afb92a22ad7b3c # v4.53.2 | |
| with: | |
| cmd: yq '${{ matrix.container_images.tag }}' charts/amazon-cloudwatch-observability/values.yaml | |
| - name: "Scan for vulnerabilities" | |
| id: scan | |
| uses: crazy-max/ghaction-container-scan@4d8e0acba576e46016cbd65b9ecfc604e85e3990 # v3.2.0 | |
| with: | |
| image: ${{ steps.registry.outputs.result }}/${{ steps.repository.outputs.result }}:${{ steps.tag.outputs.result }} | |
| severity_threshold: HIGH | |
| annotations: true | |
| - run: cat ${{ steps.scan.outputs.json }} | |
| if: success() || failure() | |
| # from https://stackoverflow.com/questions/61919141/read-json-file-in-github-actions | |
| - run: | | |
| SCAN_RESULT=$(jq -cr '"\(.ArtifactName): " + (.Results | .[] | select(.Vulnerabilities != null) | .Vulnerabilities | map(.VulnerabilityID) | join(", "))' ${{ steps.scan.outputs.json }} | cut -c -2999) | |
| echo "SCAN_RESULT<<EOF" >> $GITHUB_ENV | |
| echo "$SCAN_RESULT" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| if: success() || failure() | |
| - if: success() || failure() | |
| run: | | |
| echo '${{ env.SCAN_RESULT }}' | |
| - name: Send a saved artifact to a Slack workflow | |
| if: success() || failure() | |
| run: | | |
| curl -X POST "${{ secrets.SLACK_WEBHOOK_URL }}" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"results": "${{ env.SCAN_RESULT }}"}' |