-
Notifications
You must be signed in to change notification settings - Fork 1
242 lines (215 loc) · 8.52 KB
/
Copy pathci.yml
File metadata and controls
242 lines (215 loc) · 8.52 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: ci
on:
push:
branches: ["main"]
tags: ["v*.*.*"]
pull_request:
branches: ["main"]
workflow_dispatch:
env:
# FreeRADIUS version - must match the version installed in Dockerfile
# Actual version is verified post-build via freeradius -v
IMAGE_VERSION: "3.2.8"
# Docker Hub
DOCKERHUB_REGISTRY: docker.io
DOCKERHUB_IMAGE: cepatkilatteknologi/freeradius
# GitHub Container Registry
GHCR_REGISTRY: ghcr.io
GHCR_IMAGE: ${{ github.repository_owner }}/freeradius
jobs:
# ========================
# Job 1: Build & Push Docker Image
# ========================
build-and-push:
name: Build & Push Docker Image
runs-on: ubuntu-latest
environment: ci
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Login to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKERHUB_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Login to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata for tags
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }}
tags: |
type=raw,value=${{ env.IMAGE_VERSION }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
# Build and push to both registries
- name: Build & Push
id: build-push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
provenance: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Scan for vulnerabilities
- name: Scan for vulnerabilities
uses: aquasecurity/trivy-action@master
if: ${{ github.event_name != 'pull_request' }}
with:
image-ref: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}:${{ env.IMAGE_VERSION }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
exit-code: '0'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
if: ${{ github.event_name != 'pull_request' }}
with:
sarif_file: 'trivy-results.sarif'
continue-on-error: true
# Detect actual FreeRADIUS version from built image
- name: Detect FreeRADIUS version
if: ${{ github.event_name != 'pull_request' }}
run: |
# Extract version from the amd64 image
VERSION=$(docker run --rm --platform linux/amd64 ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}:${{ env.IMAGE_VERSION }} freeradius -v 2>/dev/null | grep -oP 'FreeRADIUS Version \K[0-9]+\.[0-9]+\.[0-9]+' || echo "${{ env.IMAGE_VERSION }}")
echo "Detected FreeRADIUS version: $VERSION"
if [ "$VERSION" != "${{ env.IMAGE_VERSION }}" ]; then
echo "::warning::IMAGE_VERSION (${{ env.IMAGE_VERSION }}) does not match actual FreeRADIUS version ($VERSION). Update IMAGE_VERSION in ci.yml."
fi
# Generate artifact attestation for Docker Hub
- name: Generate attestation (Docker Hub)
uses: actions/attest-build-provenance@v2
if: ${{ github.event_name != 'pull_request' }}
with:
subject-name: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}
subject-digest: ${{ steps.build-push.outputs.digest }}
push-to-registry: true
# Generate artifact attestation for GHCR
- name: Generate attestation (GHCR)
uses: actions/attest-build-provenance@v2
if: ${{ github.event_name != 'pull_request' }}
with:
subject-name: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }}
subject-digest: ${{ steps.build-push.outputs.digest }}
push-to-registry: true
- name: Summary
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "## Docker Image Published 🐳" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Images" >> $GITHUB_STEP_SUMMARY
echo "| Registry | Image |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Docker Hub | \`${{ env.DOCKERHUB_IMAGE }}:${{ env.IMAGE_VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| GHCR | \`${{ env.GHCR_IMAGE }}:${{ env.IMAGE_VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Tags" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Digest:** \`${{ steps.build-push.outputs.digest }}\`" >> $GITHUB_STEP_SUMMARY
# ========================
# Job 2: Test Docker Image
# ========================
test:
name: Test Docker Image
runs-on: ubuntu-latest
needs: build-and-push
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
load: true
tags: freeradius:test
cache-from: type=gha
- name: Start services
working-directory: examples/docker
run: |
# Create test .env (no leading whitespace)
cat > .env <<EOF
MYSQL_USER=radius
MYSQL_PASSWORD=testpass123
MYSQL_HOST=db
MYSQL_PORT=3306
MYSQL_DBNAME=radius
MYSQL_ROOT_PASSWORD=rootpass123
RADIUS_SECRET=testing123
HEALTHCHECK_SECRET=testing123
TZ=UTC
RADIUS_ALLOW_PRIVATE_NETWORKS=true
EOF
# Strip leading whitespace from .env
sed -i 's/^[[:space:]]*//' .env
# Override image in compose
FREERADIUS_IMAGE=freeradius:test docker compose up -d
- name: Wait for services
working-directory: examples/docker
run: |
echo "Waiting for all services to be healthy..."
for i in $(seq 1 90); do
HEALTHY=$(docker compose ps --format json | grep -c '"healthy"' || true)
TOTAL=$(docker compose ps --format json | wc -l | tr -d ' ')
echo " Healthy: $HEALTHY / $TOTAL ($i/90)"
if [ "$HEALTHY" -ge 2 ] 2>/dev/null; then
echo "All services are healthy!"
break
fi
if [ "$i" -eq 90 ]; then
echo "Timeout waiting for services"
docker compose ps
docker compose logs
exit 1
fi
sleep 5
done
docker compose ps
- name: Test RADIUS authentication
working-directory: examples/docker
run: |
# Verify MySQL is actually accepting connections
docker compose exec -T db mysqladmin ping -uroot -prootpass123 --silent
# Add test user
docker compose exec -T db mysql -uroot -prootpass123 radius -e \
"INSERT INTO radcheck (username, attribute, op, value) VALUES ('testuser', 'Cleartext-Password', ':=', 'testpass') ON DUPLICATE KEY UPDATE value='testpass';"
# Test auth (secret must match clients.conf localhost default)
docker compose exec -T freeradius radtest testuser testpass localhost 0 testing123
- name: Cleanup
if: always()
working-directory: examples/docker
run: docker compose down -v --remove-orphans