|
| 1 | +## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +## SPDX-License-Identifier: Apache-2.0 |
| 3 | +# Performs a daily scan of: |
| 4 | +# * The latest released ADOT Python image, using Trivy |
| 5 | +# * Project dependencies, using DependencyCheck |
| 6 | +# |
| 7 | +# Publishes results to CloudWatch Metrics. |
| 8 | +name: Daily scan |
| 9 | + |
| 10 | +on: |
| 11 | + schedule: |
| 12 | + - cron: '0 18 * * *' # scheduled to run at 18:00 UTC every day |
| 13 | + workflow_dispatch: # be able to run the workflow on demand |
| 14 | + |
| 15 | +env: |
| 16 | + AWS_DEFAULT_REGION: us-east-1 |
| 17 | + |
| 18 | +permissions: |
| 19 | + id-token: write |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + scan_and_report: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout repo for dependency scan |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Set up Python for dependency scan |
| 32 | + uses: actions/setup-python@v4 |
| 33 | + with: |
| 34 | + python-version: "3.10" |
| 35 | + |
| 36 | + - name: Create requirements.txt for dependency scan |
| 37 | + run: | |
| 38 | + python -m venv env |
| 39 | + source env/bin/activate |
| 40 | + pip install aws-opentelemetry-distro/ |
| 41 | + pip freeze > aws-opentelemetry-distro/requirements.txt |
| 42 | + less aws-opentelemetry-distro/requirements.txt |
| 43 | +
|
| 44 | + - name: Install java for dependency scan |
| 45 | + uses: actions/setup-java@v4 |
| 46 | + with: |
| 47 | + java-version: 17 |
| 48 | + distribution: 'temurin' |
| 49 | + |
| 50 | + - name: Configure AWS credentials for dependency scan |
| 51 | + uses: aws-actions/configure-aws-credentials@v4 |
| 52 | + with: |
| 53 | + role-to-assume: ${{ secrets.SECRET_MANAGER_ROLE_ARN }} |
| 54 | + aws-region: ${{ env.AWS_DEFAULT_REGION }} |
| 55 | + |
| 56 | + - name: Get NVD API key for dependency scan |
| 57 | + uses: aws-actions/aws-secretsmanager-get-secrets@v1 |
| 58 | + id: nvd_api_key |
| 59 | + with: |
| 60 | + secret-ids: ${{ secrets.NVD_API_KEY_SECRET_ARN }} |
| 61 | + parse-json-secrets: true |
| 62 | + |
| 63 | + # See http://jeremylong.github.io/DependencyCheck/dependency-check-cli/ for installation explanation |
| 64 | + - name: Install and run dependency scan |
| 65 | + id: dep_scan |
| 66 | + if: always() |
| 67 | + run: | |
| 68 | + gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 259A55407DD6C00299E6607EFFDE55BE73A2D1ED |
| 69 | + VERSION=$(curl -s https://jeremylong.github.io/DependencyCheck/current.txt) |
| 70 | + curl -Ls "https://github.com/jeremylong/DependencyCheck/releases/download/v$VERSION/dependency-check-$VERSION-release.zip" --output dependency-check.zip |
| 71 | + curl -Ls "https://github.com/jeremylong/DependencyCheck/releases/download/v$VERSION/dependency-check-$VERSION-release.zip.asc" --output dependency-check.zip.asc |
| 72 | + gpg --verify dependency-check.zip.asc |
| 73 | + unzip dependency-check.zip |
| 74 | + ./dependency-check/bin/dependency-check.sh --enableExperimental --suppression .github/dependency-check-suppressions.xml --failOnCVSS 0 --nvdApiKey ${{ env.NVD_API_KEY_NVD_API_KEY }} -s aws-opentelemetry-distro/ |
| 75 | +
|
| 76 | + - name: Print dependency scan results on failure |
| 77 | + if: ${{ steps.dep_scan.outcome != 'success' }} |
| 78 | + run: less dependency-check-report.html |
| 79 | + |
| 80 | + - name: Perform high image scan |
| 81 | + if: always() |
| 82 | + id: high_scan |
| 83 | + uses: ./.github/actions/image_scan |
| 84 | + with: |
| 85 | + image-ref: "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.0.1" |
| 86 | + severity: 'CRITICAL,HIGH' |
| 87 | + |
| 88 | + - name: Perform low image scan |
| 89 | + if: always() |
| 90 | + id: low_scan |
| 91 | + uses: ./.github/actions/image_scan |
| 92 | + with: |
| 93 | + image-ref: "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.0.1" |
| 94 | + severity: 'MEDIUM,LOW,UNKNOWN' |
| 95 | + |
| 96 | + - name: Configure AWS Credentials for emitting metrics |
| 97 | + if: always() |
| 98 | + uses: aws-actions/configure-aws-credentials@v4 |
| 99 | + with: |
| 100 | + role-to-assume: ${{ secrets.MONITORING_ROLE_ARN }} |
| 101 | + aws-region: ${{ env.AWS_DEFAULT_REGION }} |
| 102 | + |
| 103 | + - name: Publish high scan status |
| 104 | + if: always() |
| 105 | + run: | |
| 106 | + value="${{ steps.high_scan.outcome == 'success' && '1.0' || '0.0' }}" |
| 107 | + aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \ |
| 108 | + --metric-name Success \ |
| 109 | + --dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=daily_scan_high \ |
| 110 | + --value $value |
| 111 | +
|
| 112 | + # DependencyCheck for Python is experimental and prone to false positives. Until it is stable, use only for low monitoring. |
| 113 | + - name: Publish low scan status |
| 114 | + if: always() |
| 115 | + run: | |
| 116 | + value="${{ steps.low_scan.outcome == 'success' && steps.dep_scan.outcome == 'success' && 1.0 || 0.0}}" |
| 117 | + aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \ |
| 118 | + --metric-name Success \ |
| 119 | + --dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=daily_scan_low \ |
| 120 | + --value $value |
0 commit comments