Security Check #5
This file contains 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: "Security Check" | |
on: | |
workflow_dispatch: | |
inputs: | |
image: | |
description: 'Docker Image' | |
required: true | |
type: string | |
jobs: | |
grype: | |
name: Grype | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Docker login | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ secrets.PRIVATE_REGISTRY_URL }} | |
username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }} | |
password: ${{ secrets.PRIVATE_REGISTRY_PASSWORD }} | |
- name: Pull Docker Image | |
run: | | |
docker pull ${{ inputs.image }} | |
- name: Install Grype | |
run: | | |
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sudo sh -s -- -b /usr/local/bin | |
- name: Check Grype | |
run: | | |
grype version | |
- name: Run Grype | |
run: | | |
grype ${{ inputs.image }} | tee result.txt | |
- name: Check critical vulnerabilities | |
run: | | |
CRITICALS=$(cat result.txt | grep "Critical" | wc -l | tr -s " ") | |
if [ "$CRITICALS" -gt "0" ]; then | |
echo "There are critical vulnerabilities: $CRITICALS (image: $IMAGE)" | |
echo "--------------------------------------------------------------------------------" | |
cat result.txt | grep "Critical" | |
echo "--------------------------------------------------------------------------------" | |
exit 1 | |
else | |
echo "There are no critical vulnerabilities for image: $IMAGE" | |
echo "Well done!" | |
fi | |
env: | |
IMAGE: ${{ inputs.image }} | |
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} | |
REPO: ${{ github.repository }} | |
RUN: ${{ github.run_id }} |