-
Notifications
You must be signed in to change notification settings - Fork 627
196 lines (171 loc) · 6.03 KB
/
docker-scan.yml
File metadata and controls
196 lines (171 loc) · 6.03 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# ===============================================================
# Docker Security Scan Workflow
# ===============================================================
#
# This workflow performs security scanning on container images:
# 1. Lint Dockerfile with Hadolint
# 2. Build image locally (no push required)
# 3. Lint image with Dockle
# 4. Generate SBOM with Syft
# 5. Scan for vulnerabilities with Trivy and Grype
#
# Runs on both PRs and pushes to catch issues early.
#
# ===============================================================
name: Docker Security Scan
on:
push:
branches: ["main"]
paths:
- 'Containerfile.lite'
- 'mcpgateway/**'
- 'plugins/**'
- 'pyproject.toml'
- '.github/workflows/docker-scan.yml'
pull_request:
types: [opened, synchronize, ready_for_review]
branches: ["main"]
paths:
- 'Containerfile.lite'
- 'mcpgateway/**'
- 'plugins/**'
- 'pyproject.toml'
- '.github/workflows/docker-scan.yml'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
security-events: write
actions: read
env:
IMAGE_NAME: mcp-context-forge-scan
jobs:
# ---------------------------------------------------------------
# Lint Dockerfile
# ---------------------------------------------------------------
lint:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: Lint Dockerfile
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Hadolint
id: hadolint
continue-on-error: true
run: |
curl -sSL https://github.com/hadolint/hadolint/releases/latest/download/hadolint-Linux-x86_64 -o /usr/local/bin/hadolint
chmod +x /usr/local/bin/hadolint
hadolint -f sarif Containerfile.lite > hadolint-results.sarif || true
- name: Upload Hadolint SARIF
if: always() && hashFiles('hadolint-results.sarif') != ''
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: hadolint-results.sarif
category: hadolint
# ---------------------------------------------------------------
# Build and scan image
# ---------------------------------------------------------------
scan:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: Security Scan
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image locally
uses: docker/build-push-action@v6
with:
context: .
file: Containerfile.lite
platforms: linux/amd64
push: false
load: true
tags: ${{ env.IMAGE_NAME }}:scan
cache-from: type=gha,scope=build-amd64
cache-to: type=gha,mode=max,scope=build-amd64
- name: Image lint (Dockle)
id: dockle
continue-on-error: true
env:
DOCKLE_VERSION: 0.4.15
run: |
curl -sSL "https://github.com/goodwithtech/dockle/releases/download/v${DOCKLE_VERSION}/dockle_${DOCKLE_VERSION}_Linux-64bit.tar.gz" \
| tar -xz -C /usr/local/bin dockle
dockle --exit-code 1 --format sarif \
--output dockle-results.sarif \
${{ env.IMAGE_NAME }}:scan
echo "DOCKLE_EXIT=$?" >> "$GITHUB_ENV"
exit 0
- name: Upload Dockle SARIF
if: always() && hashFiles('dockle-results.sarif') != ''
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: dockle-results.sarif
category: dockle
- name: Generate SBOM (Syft)
uses: anchore/sbom-action@v0
with:
image: ${{ env.IMAGE_NAME }}:scan
output-file: sbom.spdx.json
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.spdx.json
retention-days: 30
- name: Install Trivy
run: |
sudo apt-get update
sudo apt-get install -y wget gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key \
| gpg --dearmor \
| sudo tee /usr/share/keyrings/trivy.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" \
| sudo tee /etc/apt/sources.list.d/trivy.list >/dev/null
sudo apt-get update
sudo apt-get install -y trivy
trivy --version
- name: Trivy vulnerability scan
run: |
trivy image \
--format sarif \
--output trivy-results.sarif \
--severity CRITICAL,HIGH \
--exit-code 0 \
${{ env.IMAGE_NAME }}:scan
- name: Upload Trivy SARIF
if: always() && hashFiles('trivy-results.sarif') != ''
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: trivy-results.sarif
category: trivy
- name: Install Grype
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
- name: Grype vulnerability scan
continue-on-error: true
run: |
grype ${{ env.IMAGE_NAME }}:scan --scope all-layers --only-fixed
- name: Grype SARIF report
continue-on-error: true
run: |
grype ${{ env.IMAGE_NAME }}:scan --scope all-layers --output sarif --file grype-results.sarif
- name: Upload Grype SARIF
if: always() && hashFiles('grype-results.sarif') != ''
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: grype-results.sarif
category: grype
- name: Enforce lint gates
if: env.DOCKLE_EXIT != '0'
run: |
echo "Dockle exit: $DOCKLE_EXIT"
exit 1