Docker Image Security Scan #12
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
| name: Docker Image Security Scan | |
| on: | |
| schedule: | |
| # Runs at 10:00 AM UTC every Monday | |
| - cron: '0 10 * * 1' | |
| # Optional: Allow manual triggering | |
| workflow_dispatch: | |
| jobs: | |
| scan: | |
| name: Scan Latest Image | |
| runs-on: runs-on | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v6 | |
| with: | |
| role-to-assume: arn:aws:iam::979633842206:role/LocalOfficeSearchApiDeployment | |
| role-session-name: local-office-search-api-trivy-scan | |
| aws-region: eu-west-1 | |
| - name: ECR login | |
| id: ecr-login | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| registry-type: private | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@master | |
| id: trivy-scan | |
| env: | |
| TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db | |
| TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db | |
| TRIVY_DISABLE_VEX_NOTICE: true | |
| with: | |
| image-ref: ${{ steps.ecr-login.outputs.registry }}/local-office-search-api:latest | |
| format: 'json' | |
| output: 'trivy-results.json' | |
| ignore-unfixed: true | |
| - name: Upload scan results | |
| id: upload-artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: trivy-scan-results | |
| path: trivy-results.json | |
| retention-days: 7 | |
| - name: Install Dependency | |
| run: pip install git+https://github.com/citizensadvice/trivy-image-slack-reporter.git@2.0.0 | |
| - name: Send Slack notification | |
| env: | |
| RESULTS_FILE: trivy-results.json | |
| ARTIFACT_URL: ${{ steps.upload-artifact.outputs.artifact-url }} | |
| IMAGE_TITLE: Local Office Search API | |
| SEVERITY: HIGH,CRITICAL | |
| SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
| SLACK_CHANNEL_ID: "C08LQKF02TA" #content-platform_security | |
| run: python3 -m trivy_image_slack_reporter | |
| slack-failure: | |
| name: Slack Notification (Failure) | |
| runs-on: runs-on | |
| needs: scan | |
| if: failure() | |
| steps: | |
| - name: Notify Slack | |
| uses: citizensadvice/message-slack-action@v1 | |
| with: | |
| slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| channel_id: "C08LQKF02TA" #content-platform_security | |
| title: ":x: :shield: Trivy scan failure for Local Office Search API" | |
| message: | | |
| Trivy scan job failed. |