-
Notifications
You must be signed in to change notification settings - Fork 0
353 lines (306 loc) · 15.4 KB
/
Copy pathci.yml
File metadata and controls
353 lines (306 loc) · 15.4 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
name: CI
on:
push:
branches: ["main"]
pull_request:
# Manual trigger for the privileged real-kernel enforcement job, which can only
# run on a self-hosted BPF-LSM runner (see the kernel-lsm-real job below).
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# ─────────────────────────────────────────────────────────────────────────────
# Job 1: Release build
# ─────────────────────────────────────────────────────────────────────────────
build:
name: Build (release)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y libz3-dev keyutils
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-target-release-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-release-
- name: Build release
run: cargo build --release 2>&1
- name: Upload release binary
uses: actions/upload-artifact@v4
with:
name: ts_cli-release-${{ github.sha }}
path: target/release/ts_cli
# ─────────────────────────────────────────────────────────────────────────────
# Job 2: Test suite (unit + integration)
# ─────────────────────────────────────────────────────────────────────────────
test:
name: Tests
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v5
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y libz3-dev keyutils
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-target-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-test-
${{ runner.os }}-cargo-target-release-
- name: Download release binary
uses: actions/download-artifact@v4
with:
name: ts_cli-release-${{ github.sha }}
path: target/release/
- name: Mark binary executable
run: chmod +x target/release/ts_cli
- name: Run all tests
env:
JINNGUARD_TEST_BINARY: ${{ github.workspace }}/target/release/ts_cli
run: cargo test --workspace 2>&1
# Anti-lockout / safe-mode invariants in the LSM verdict loop only build
# under the kernel feature. Run them so a regression that could strand the
# operator fails CI.
- name: Run kernel-feature safety invariants
run: cargo test --bin ts_cli --features kernel_telemetry 2>&1
# The privileged kernel_lsm enforcement tests (incl. #54 default-deny egress
# and #55 AF_UNIX deputy denylist) need BPF LSM + root, so they cannot run on
# a GitHub-hosted runner — they execute on the self-hosted kernel-lsm-real job
# below. Compile them here under --features enterprise so a change that breaks
# the harness (or the daemon-side enforcement wiring) fails PR CI immediately.
- name: Compile kernel_lsm enforcement tests (gating, no-run)
run: cargo test -p ts_cli --features enterprise --test kernel_lsm --no-run 2>&1
# ─────────────────────────────────────────────────────────────────────────────
# Job 2b: Fleet feature gate (open-core enterprise client)
# The signed-bundle client (`--fleet-policy-url`) compiles only with the
# `fleet` feature (off by default). The other jobs build feature-off; this one
# guarantees the gated code still compiles, lints, and that the accept/reject
# decision (apply-forward / reject-rollback / reject-bad-signature) is correct.
# ─────────────────────────────────────────────────────────────────────────────
fleet:
name: Fleet feature gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y libz3-dev keyutils
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-target-fleet-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-fleet-
- name: Install clippy
run: rustup component add clippy
- name: Clippy (fleet feature, deny warnings)
run: cargo clippy -p ts_cli --features fleet -- -D warnings 2>&1
- name: Test fleet bundle accept/reject decision
run: cargo test -p ts_cli --features fleet --bin ts_cli fleet_policy 2>&1
# ─────────────────────────────────────────────────────────────────────────────
# Job 3: Benchmark compilation check
# ─────────────────────────────────────────────────────────────────────────────
bench:
name: Bench (compile check)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y libz3-dev keyutils
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-target-bench-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-bench-
- name: Compile benchmarks (no-run)
run: cargo bench --no-run 2>&1
# ─────────────────────────────────────────────────────────────────────────────
# Job 4: Clippy (deny warnings)
# ─────────────────────────────────────────────────────────────────────────────
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y libz3-dev keyutils
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Install clippy
run: rustup component add clippy
- name: Run clippy
run: cargo clippy -- -D warnings 2>&1
# ─────────────────────────────────────────────────────────────────────────────
# Job 5: Rustfmt check
# ─────────────────────────────────────────────────────────────────────────────
fmt:
name: Format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --check 2>&1
# ─────────────────────────────────────────────────────────────────────────────
# Job 6: eBPF build
# ─────────────────────────────────────────────────────────────────────────────
build-ebpf:
name: Build eBPF LSM objects
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install clang, llvm, libbpf-dev
run: |
sudo apt-get update -qq
sudo apt-get install -y clang llvm libbpf-dev
# Compile each of the five LSM objects the daemon actually loads against the
# vendored bpf/vmlinux.h (committed to the repo). This deliberately does NOT
# use bpftool or the runner's live BTF: obtaining a working bpftool on
# GitHub's Azure-kernel runner is unreliable, and a compile sanity check
# doesn't need the runner's own kernel types. This GATES CI — a change that
# breaks BPF compilation (bad map, missing helper, etc.) fails the build.
- name: Compile LSM objects (gating)
run: |
set -euo pipefail
test -f bpf/vmlinux.h || { echo "ERROR: bpf/vmlinux.h missing (it is vendored)"; exit 1; }
cd bpf
for f in lsm/jg_socket_connect lsm/jg_socket_sendmsg \
lsm/jg_bprm_check_security lsm/jg_inode_create lsm/jg_inode_unlink; do
echo " CLANG $f.o"
clang -O2 -g -target bpf -D__TARGET_ARCH_x86 -I/usr/include -I. -c "$f.c" -o "$f.o"
done
- name: Upload eBPF LSM objects
uses: actions/upload-artifact@v4
with:
name: jinnguard-lsm-objects-${{ github.sha }}
path: bpf/lsm/*.o
if-no-files-found: error
# ─────────────────────────────────────────────────────────────────────────────
# Job 7: Real-kernel LSM enforcement matrix (self-hosted, privileged)
# GitHub-hosted runners cannot enable the BPF LSM (boot param) or attach LSM
# programs as root, so the #[ignore]d kernel_lsm tests — the actual allow/deny
# enforcement proofs, including #54 default-deny IPv4 egress and #55 the AF_UNIX
# deputy denylist — can only execute on self-hosted runners whose kernel was
# booted with `lsm=...,bpf` and cgroup v2 mounted.
#
# Fans out across the validated distro/kernel runners (each registered with the
# shared `bpf-lsm` label plus a per-host label): AlphaOS 6.12, Ubuntu 24.04 6.17
# (jinn2), AlmaLinux 9.8 5.14 (jinn3). 5.14 is the floor that exercises the
# oldest supported verifier. fail-fast: false so one distro's failure still lets
# the others report. The steps are package-manager agnostic (build deps are baked
# into each runner image), so no per-distro branching is needed.
#
# Manually dispatched (workflow_dispatch) so normal push/PR CI is never queued
# against a self-hosted runner that may be offline. Mirrors the proven incantation
# from scripts/validate/kernel_floor_demo.sh: compile the test binary as the build
# user, then exec the raw binary as root (no cargo at root, no root-owned target
# churn). JINNGUARD_TEST_BINARY must be ABSOLUTE.
# ─────────────────────────────────────────────────────────────────────────────
kernel-lsm-real:
name: Real-kernel LSM (${{ matrix.distro }} k${{ matrix.kernel }})
if: github.event_name == 'workflow_dispatch'
strategy:
fail-fast: false
matrix:
include:
- distro: AlphaOS
label: alphaos
kernel: "6.12"
- distro: Ubuntu 24.04
label: jinn2
kernel: "6.17"
- distro: AlmaLinux 9.8
label: jinn3
kernel: "5.14"
runs-on: [self-hosted, bpf-lsm, "${{ matrix.label }}"]
steps:
- uses: actions/checkout@v5
- name: Show host kernel / distro
run: |
echo "matrix: ${{ matrix.distro }} (expected kernel ${{ matrix.kernel }}, label ${{ matrix.label }})"
uname -a
- name: Build + install LSM objects (-> /usr/lib/jinnguard/lsm)
run: sudo make -C bpf install
- name: Build enterprise daemon
run: cargo build -p ts_cli --features enterprise
- name: Compile kernel_lsm test binary (as build user)
run: cargo test -p ts_cli --features enterprise --test kernel_lsm --no-run
- name: Run armed kernel-LSM enforcement tests (root)
run: |
set -euo pipefail
BIN="$PWD/target/debug/ts_cli"
test -x "$BIN" || { echo "enterprise daemon not built at $BIN"; exit 1; }
TESTBIN="$(find "$PWD/target/debug/deps" -maxdepth 1 -type f -executable \
-name 'kernel_lsm-*' ! -name '*.d' -printf '%T@ %p\n' \
| sort -rn | head -1 | cut -d' ' -f2-)"
test -n "$TESTBIN" && test -x "$TESTBIN" \
|| { echo "kernel_lsm test binary not found under target/debug/deps"; exit 1; }
echo " daemon: $BIN"
echo " testbin: $TESTBIN"
export PATH="$PATH:/usr/sbin"
# Runs the whole #[ignore]d kernel_lsm suite — the 6 baseline surfaces plus
# the new #54 default-deny egress and #55 deputy-denylist enforcement tests.
sudo -E env "PATH=$PATH" JINNGUARD_TEST_BINARY="$BIN" \
"$TESTBIN" --ignored --test-threads=1 --nocapture