Skip to content

Docker Image Security Scan #49

Docker Image Security Scan

Docker Image Security Scan #49

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@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: '3.13'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
with:
role-to-assume: arn:aws:iam::979633842206:role/EnergyAppsDeployment
role-session-name: energy-apps-trivy-scan
aws-region: eu-west-1
- name: ECR login
id: ecr-login
uses: aws-actions/amazon-ecr-login@183a1442edf41672e66566b7fc560e297a290896
with:
registry-type: private
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1
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 }}/energy-apps:latest
format: 'json'
output: 'trivy-results.json'
ignore-unfixed: true
- name: Upload scan results
id: upload-artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
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: Energy Apps
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@306ad8b4768287c24be25ebc9c0dd9d2af55a20a
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 Energy Apps"
message: |
Trivy scan job failed.