-
Notifications
You must be signed in to change notification settings - Fork 0
380 lines (323 loc) · 12.2 KB
/
quality-gates.yaml
File metadata and controls
380 lines (323 loc) · 12.2 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
name: Quality Gates
permissions:
contents: read
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: true
- name: Download dependencies
run: go mod download
- name: Vet
run: go vet ./...
- name: Build
run: go build -v ./...
- name: Test
run: go test ./... -race -coverprofile=coverage.out
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
hardbox-audit:
name: Self-Audit
runs-on: ubuntu-latest
needs: build-and-test
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build hardbox
run: go build -o hardbox ./cmd/hardbox
- name: Run audit (dry run, non-interactive)
run: |
./hardbox audit --profile cis-level1 --format json --output audit-report.json || true
- name: Validate audit report JSON structure
run: |
jq -e '
has("session_id") and
has("timestamp") and
has("profile") and
has("overall_score") and
(.modules | type == "array" and length > 0) and
all(.modules[]; has("name") and has("score") and has("findings") and (.findings | type == "array")) and
all(.modules[].findings[]?; has("check_id") and has("title") and has("status") and has("severity"))
' audit-report.json > /dev/null
- name: Assert audit returned findings
run: |
jq -e '[.modules[].findings[]] | length > 0' audit-report.json > /dev/null
- name: Assert audit score is non-zero
run: |
jq -e '.overall_score > 0' audit-report.json > /dev/null
- name: Upload audit report
uses: actions/upload-artifact@v4
with:
name: audit-report
path: audit-report.json
markdown-links:
name: Documentation Links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check internal file links in README.md
run: |
FAILED=0
LINKS=$(grep -oP '\]\(\K[^)]+' README.md | grep -v '^https\?://' | grep -v '^#')
for link in $LINKS; do
filepath="${link%%#*}"
[ -z "$filepath" ] && continue
if [ ! -e "$filepath" ]; then
echo "::error file=README.md::Broken link — '$filepath' does not exist"
FAILED=1
else
echo "✓ $filepath"
fi
done
exit $FAILED
- name: Check internal file links in CONTRIBUTING.md
run: |
FAILED=0
LINKS=$(grep -oP '\]\(\K[^)]+' CONTRIBUTING.md | grep -v '^https\?://' | grep -v '^#')
for link in $LINKS; do
filepath="${link%%#*}"
[ -z "$filepath" ] && continue
if [ ! -e "$filepath" ]; then
echo "::error file=CONTRIBUTING.md::Broken link — '$filepath' does not exist"
FAILED=1
else
echo "✓ $filepath"
fi
done
exit $FAILED
profile-consistency:
name: Profile Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Collect shipped profile names
id: shipped
run: |
PROFILES=$(ls configs/profiles/*.yaml 2>/dev/null \
| xargs -I{} basename {} .yaml \
| sort \
| tr '\n' ' ')
echo "list=${PROFILES}" >> "$GITHUB_OUTPUT"
echo "Shipped profiles: ${PROFILES}"
- name: Assert every shipped profile appears in README
run: |
FAILED=0
for profile in ${{ steps.shipped.outputs.list }}; do
if ! grep -q "\`${profile}\`" README.md; then
echo "::error file=README.md::Shipped profile '${profile}' is not documented in README.md"
FAILED=1
else
echo "✓ ${profile} found in README.md"
fi
done
exit $FAILED
- name: Assert every shipped profile appears in COMPLIANCE.md
run: |
FAILED=0
for profile in ${{ steps.shipped.outputs.list }}; do
if ! grep -q "\`${profile}\`" docs/COMPLIANCE.md; then
echo "::error file=docs/COMPLIANCE.md::Shipped profile '${profile}' is not documented in docs/COMPLIANCE.md"
FAILED=1
else
echo "✓ ${profile} found in COMPLIANCE.md"
fi
done
exit $FAILED
- name: Warn about profiles listed in README that are not yet shipped
run: |
DOCS_PROFILES=$(grep -oP '`[a-z][a-z0-9-]+`' README.md \
| tr -d '`' \
| grep -v '^hardbox$\|^cis$\|^json$\|^text$\|^markdown$\|^html$' \
| sort -u)
for doc_profile in ${DOCS_PROFILES}; do
if [ ! -f "configs/profiles/${doc_profile}.yaml" ]; then
echo "::notice file=README.md::Profile '${doc_profile}' is documented in README but not yet shipped (roadmap item)"
fi
done
# ── Distro parity — RHEL / Rocky Linux ──────────────────────────────────────
# Runs build + unit tests + smoke audit inside RPM-based containers to catch
# path assumptions, syscall differences, or package-name drift that only
# surface on non-Debian systems.
#
# Container limitations (documented in docs/DEVSECOPS.md):
# - systemd / systemctl is not available inside GitHub Actions containers.
# Modules that shell out to systemctl will return "inactive" gracefully;
# the audit is expected to complete and produce valid JSON regardless.
# - redhat/ubi9 is the freely available RHEL 9 Universal Base Image.
# It is ABI-compatible with RHEL 9 for our build/test/audit purposes.
distro-parity:
name: Distro Parity / ${{ matrix.distro }}
runs-on: ubuntu-latest
needs: build-and-test
container:
image: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
include:
- distro: Rocky Linux 9
image: rockylinux:9
slug: rocky-linux-9
- distro: RHEL UBI 9
image: redhat/ubi9
slug: rhel-ubi-9
steps:
- name: Install system dependencies
run: |
dnf install -y --nodocs git tar gzip ca-certificates jq
# Mark any directory as safe so Go's VCS stamping doesn't fail when
# the workspace UID (runner) differs from the container UID (root).
git config --global --add safe.directory '*'
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: true
- name: Download dependencies
run: go mod download
- name: Vet
run: go vet ./...
- name: Build
run: go build -v ./...
- name: Test
run: go test ./... -count=1 -timeout=120s
- name: Build hardbox binary
run: go build -o hardbox ./cmd/hardbox
- name: Prepare system stubs for container audit
# Containers lack the OS files hardbox reads during audit.
# Create the minimum stubs so every module can open its config
# files and produce findings rather than aborting with ENOENT.
run: |
mkdir -p /etc/ssh && touch /etc/ssh/sshd_config
mkdir -p /etc/audit/rules.d
mkdir -p /etc/sysctl.d
mkdir -p /etc/pam.d && touch /etc/pam.d/common-auth /etc/pam.d/common-password
mkdir -p /etc/chrony && touch /etc/chrony/chrony.conf
mkdir -p /etc/systemd/system
touch /etc/login.defs
touch /etc/rsyslog.conf
- name: Smoke audit (cis-level1)
run: |
./hardbox audit --profile cis-level1 --format json \
--output audit-${{ matrix.slug }}.json || true
- name: Validate audit report structure
run: |
jq -e '
has("session_id") and
has("overall_score") and
(.modules | type == "array" and length > 0) and
all(.modules[]; has("name") and has("findings"))
' "audit-${{ matrix.slug }}.json" > /dev/null
echo "✓ Audit report structure valid on ${{ matrix.distro }}"
- name: Assert audit produced findings
run: |
COUNT=$(jq '[.modules[].findings[]] | length' "audit-${{ matrix.slug }}.json")
echo "Findings on ${{ matrix.distro }}: ${COUNT}"
if [ "${COUNT}" -eq 0 ]; then
echo "::error::Audit returned 0 findings on ${{ matrix.distro }} — distro detection may be broken"
exit 1
fi
- name: Upload audit report
uses: actions/upload-artifact@v4
with:
name: audit-${{ matrix.slug }}
path: audit-${{ matrix.slug }}.json
# Single gate job that requires all matrix legs — add this check name to
# branch protection so the merge button blocks until every distro passes.
distro-parity-gate:
name: Distro Parity Gate
runs-on: ubuntu-latest
needs: distro-parity
if: always()
steps:
- name: Assert all parity legs passed
run: |
RESULT="${{ needs.distro-parity.result }}"
if [ "${RESULT}" != "success" ]; then
echo "::error::One or more distro parity checks failed (result: ${RESULT})"
exit 1
fi
echo "✓ All distro parity checks passed"
goreleaser-config:
name: Release Configuration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract GoReleaser release target
id: goreleaser
run: |
OWNER=$(grep -A3 'release:' .goreleaser.yaml \
| grep -A2 'github:' \
| grep 'owner:' \
| awk '{print $2}')
REPO=$(grep -A3 'release:' .goreleaser.yaml \
| grep -A2 'github:' \
| grep 'name:' \
| awk '{print $2}')
echo "owner=${OWNER}" >> "$GITHUB_OUTPUT"
echo "repo=${REPO}" >> "$GITHUB_OUTPUT"
echo "Configured release target: ${OWNER}/${REPO}"
- name: Derive canonical owner/name from GITHUB_REPOSITORY
id: canonical
run: |
CANONICAL_OWNER="${GITHUB_REPOSITORY_OWNER}"
CANONICAL_REPO="${GITHUB_REPOSITORY#*/}"
echo "owner=${CANONICAL_OWNER}" >> "$GITHUB_OUTPUT"
echo "repo=${CANONICAL_REPO}" >> "$GITHUB_OUTPUT"
echo "Canonical repository: ${CANONICAL_OWNER}/${CANONICAL_REPO}"
- name: Assert owner matches
run: |
CONFIGURED="${{ steps.goreleaser.outputs.owner }}"
CANONICAL="${{ steps.canonical.outputs.owner }}"
if [ "${CONFIGURED}" != "${CANONICAL}" ]; then
echo "::error file=.goreleaser.yaml::release.github.owner is '${CONFIGURED}' but canonical owner is '${CANONICAL}'. Update .goreleaser.yaml."
exit 1
fi
echo "✓ owner matches: ${CONFIGURED}"
- name: Assert repo name matches
run: |
CONFIGURED="${{ steps.goreleaser.outputs.repo }}"
CANONICAL="${{ steps.canonical.outputs.repo }}"
if [ "${CONFIGURED}" != "${CANONICAL}" ]; then
echo "::error file=.goreleaser.yaml::release.github.name is '${CONFIGURED}' but canonical repo name is '${CANONICAL}'. Update .goreleaser.yaml."
exit 1
fi
echo "✓ repo name matches: ${CONFIGURED}"
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
install-only: true
version: "~> v2"
- name: Check GoReleaser config
run: goreleaser check --config .goreleaser.yaml