|
| 1 | +name: Docker Image Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Runs at 10:00 AM UTC every Monday |
| 6 | + - cron: '0 10 * * 1' |
| 7 | + # Optional: Allow manual triggering |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + scan: |
| 12 | + name: Scan Latest Image |
| 13 | + runs-on: runs-on |
| 14 | + permissions: |
| 15 | + id-token: write |
| 16 | + contents: read |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v6 |
| 19 | + |
| 20 | + - uses: actions/setup-python@v6 |
| 21 | + with: |
| 22 | + python-version: '3.13' |
| 23 | + |
| 24 | + - name: Configure AWS Credentials |
| 25 | + uses: aws-actions/configure-aws-credentials@v5 |
| 26 | + with: |
| 27 | + role-to-assume: arn:aws:iam::979633842206:role/LocalOfficeSearchApiDeployment |
| 28 | + role-session-name: local-office-search-api-trivy-scan |
| 29 | + aws-region: eu-west-1 |
| 30 | + |
| 31 | + - name: ECR login |
| 32 | + id: ecr-login |
| 33 | + uses: aws-actions/amazon-ecr-login@v2 |
| 34 | + with: |
| 35 | + registry-type: private |
| 36 | + |
| 37 | + - name: Run Trivy vulnerability scanner |
| 38 | + uses: aquasecurity/trivy-action@master |
| 39 | + id: trivy-scan |
| 40 | + env: |
| 41 | + TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db |
| 42 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db |
| 43 | + TRIVY_DISABLE_VEX_NOTICE: true |
| 44 | + with: |
| 45 | + image-ref: ${{ steps.ecr-login.outputs.registry }}/local-office-search-api:latest |
| 46 | + format: 'json' |
| 47 | + output: 'trivy-results.json' |
| 48 | + ignore-unfixed: true |
| 49 | + |
| 50 | + - name: Upload scan results |
| 51 | + id: upload-artifact |
| 52 | + uses: actions/upload-artifact@v5 |
| 53 | + with: |
| 54 | + name: trivy-scan-results |
| 55 | + path: trivy-results.json |
| 56 | + retention-days: 7 |
| 57 | + |
| 58 | + - name: Install Dependency |
| 59 | + run: pip install git+https://github.com/citizensadvice/trivy-image-slack-reporter.git@2.0.0 |
| 60 | + |
| 61 | + - name: Send Slack notification |
| 62 | + env: |
| 63 | + RESULTS_FILE: trivy-results.json |
| 64 | + ARTIFACT_URL: ${{ steps.upload-artifact.outputs.artifact-url }} |
| 65 | + IMAGE_TITLE: Local Office Search API |
| 66 | + SEVERITY: HIGH,CRITICAL |
| 67 | + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |
| 68 | + SLACK_CHANNEL_ID: "C08LQKF02TA" #content-platform_security |
| 69 | + run: python3 -m trivy_image_slack_reporter |
| 70 | + |
| 71 | + slack-failure: |
| 72 | + name: Slack Notification (Failure) |
| 73 | + runs-on: runs-on |
| 74 | + needs: scan |
| 75 | + if: failure() |
| 76 | + steps: |
| 77 | + - name: Notify Slack |
| 78 | + uses: citizensadvice/message-slack-action@v1 |
| 79 | + with: |
| 80 | + slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} |
| 81 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + channel_id: "C08LQKF02TA" #content-platform_security |
| 83 | + title: ":x: :shield: Trivy scan failure for Local Office Search API" |
| 84 | + message: | |
| 85 | + Trivy scan job failed. |
0 commit comments