-
Notifications
You must be signed in to change notification settings - Fork 73
128 lines (122 loc) · 4.35 KB
/
docker-images-security-scan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Scan docker images
on:
workflow_dispatch:
inputs:
image:
type: choice
description: Image/s to scan
# This is a bit annoying, there's no real way to display the integrations dynamically in a dropdown for the action dispatcher
options:
- all
- argocd
- aws
- azure
- azure-devops
- backstage
- datadog
- dynatrace
- fake-integration
- firehydrant
- gcp
- gitlab
- jenkins
- jira
- kafka
- kubecost
- launchdarkly
- linear
- newrelic
- octopus
- opencost
- opsgenie
- pagerduty
- sentry
- servicenow
- snyk
- sonarqube
- statuspage
- terraform-cloud
- wiz
jobs:
detect-images:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.set-images.outputs.images }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Determine which image to scan
id: set-images
run: |
PROJECTS=$(ls --color=never ./integrations | grep -Ev '_infra')
if [[ "${{ inputs.image }}" != "all" ]]; then
PROJECTS="${{ inputs.image }}"
fi
IMAGES_WITH_VERSIONS=()
for PROJECT in ${PROJECTS}; do
if [[ ! -f ./integrations/"${PROJECT}"/pyproject.toml ]]; then
continue
fi
VERSION=$(cat ./integrations/"${PROJECT}"/pyproject.toml | grep -E '^version = "(.*)"$' | awk -F ' ' '{print $3};' | sed 's/"//g')
if [[ -n ${VERSION} ]]; then
IMAGES_WITH_VERSIONS+=( "${PROJECT}:${VERSION}" )
fi
done
IMAGES=$(echo "${IMAGES_WITH_VERSIONS[@]}" | jq -R -s -c 'split(" ") | map(select(length > 0))')
echo "Images to scan: ${IMAGES}"
echo "images=${IMAGES}" >> $GITHUB_OUTPUT
scan-images:
needs: detect-images
runs-on: ubuntu-latest
strategy:
max-parallel: 2
matrix:
image: ${{ fromJson(needs.detect-images.outputs.images) }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Extract version and image tag
id: enrich-version
run: |
INTEGRATION=$(echo "${{ matrix.image }}" | awk -F ':' '{print $1};')
VERSION=$(echo "${{ matrix.image }}" | awk -F ':' '{print $2};')
IDENTIFIER="${INTEGRATION}-${VERSION}-${{ github.sha }}"
IMAGE_FULL_TAG="port-ocean-security-tests-${INTEGRATION}:${VERSON}${{ github.sha }}"
echo "integration=${INTEGRATION}" >> ${GITHUB_OUTPUT}
echo "version=${VERSION}" >> ${GITHUB_OUTPUT}
echo "identifier=${IDENTIFIER}" >> ${GITHUB_OUTPUT}
echo "image_tag=${IMAGE_FULL_TAG}" >> ${GITHUB_OUTPUT}
- name: Build Docker Image
uses: ./.github/workflows/actions/build-docker-image
with:
dockerfile: ./integrations/_infra/Dockerfile
platforms: linux/amd64
skip-push: 'true'
tags: ${{ steps.enrich-version.outputs.image_tag }}
load-created-image: 'true'
docker-user: ${{ secrets.DOCKER_MACHINE_USER }}
docker-password: ${{ secrets.DOCKER_MACHINE_TOKEN }}
build-args: |
BUILD_CONTEXT=./integrations/${{ steps.enrich-version.outputs.integration }}
INTEGRATION_VERSION=${{ steps.enrich-version.outputs.version }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.29.0
with:
image-ref: ${{ steps.enrich-version.outputs.image_tag }}
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
output: trivy-${{ steps.enrich-version.outputs.integration }}.txt
- name: Publish Trivy Output to Summary
run: |
if [[ -s trivy-${{ steps.enrich-version.outputs.integration }}.txt ]]; then
{
echo "### Security Output"
echo "<details><summary>Click to expand</summary>"
echo ""
echo '```terraform'
cat trivy-${{ steps.enrich-version.outputs.integration }}.txt
echo '```'
echo "</details>"
} >> $GITHUB_STEP_SUMMARY
fi