Repository navigation
708 lines (635 loc) · 32.9 KB
/
Copy pathci.yml
File metadata and controls
708 lines (635 loc) · 32.9 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
name: CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches: [master, main]
workflow_dispatch:
permissions:
contents: read
# GitHub's Azure-hosted runners reach the in-region Ubuntu mirror
# (azure.archive.ubuntu.com) far faster than the default archive.ubuntu.com,
# which is intermittently rate-limited from Azure and made the image build's
# base-dependency apt take 35+ min (blowing the job timeout). coi build
# forwards COI_APT_MIRROR into the build container (see internal/image/builder.go
# buildScriptEnv → build.sh configure_apt_mirror), so the build uses the fast
# mirror in CI. Local builds leave it unset and keep the stock mirrors.
env:
COI_APT_MIRROR: http://azure.archive.ubuntu.com/ubuntu
jobs:
# Build job gates all tests - nothing runs if build fails
build:
name: Build
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Go build
uses: ./.github/actions/setup-go-build
- name: Run golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
version: latest
args: --timeout=5m
- name: Build
run: go build -v ./...
- name: Verify all test paths are assigned to a CI group
run: python3 scripts/check-ci-coverage.py
# Go unit tests run in parallel with integration tests (after build passes)
unit-tests:
name: Unit Tests
runs-on: ubuntu-24.04
needs: build
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Go build
uses: ./.github/actions/setup-go-build
- name: Run unit tests with coverage and race detector
run: |
# Run all tests except session package (immutable tests need CAP_LINUX_IMMUTABLE)
go test -v -race -coverprofile=coverage-main.out -covermode=atomic $(go list ./... | grep -v /internal/session)
# Build session test binary separately and grant CAP_LINUX_IMMUTABLE
go test -c -race -cover -covermode=atomic -o /tmp/session.test ./internal/session/
sudo setcap cap_linux_immutable=ep /tmp/session.test
/tmp/session.test -test.v -test.coverprofile=coverage-session.out
# Merge coverage profiles
cat coverage-main.out > coverage.out
tail -n +2 coverage-session.out >> coverage.out 2>/dev/null || true
go tool cover -func=coverage.out | tail -1 # Show total coverage
- name: Compile-check integration tier
# The //go:build integration tests are not built by the default `go test`
# above, so compile them here (no Incus needed) to keep them from rotting.
run: go vet -tags integration ./...
# Native-macOS coverage for the OS-sensitive host-detection code. coi's full
# binary is Linux-only (internal/monitor uses fanotify/inotify with no darwin
# stubs; releases ship linux only) and on macOS coi actually runs inside the
# Colima/Lima VM — so we do NOT build the whole binary here. But internal/vmhost
# (VM detection + the #817 shared-Mac-home config resolution) is darwin-clean
# and its logic is exactly what only a real Mac exercises, so run its unit tests
# natively to catch darwin-specific regressions (e.g. path/mount handling).
macos-unit-tests:
name: macOS Unit Tests (vmhost)
runs-on: macos-latest
needs: build
timeout-minutes: 8
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.26'
check-latest: true
cache: true
- name: Run vmhost unit tests natively on macOS
run: go test -v ./internal/vmhost/...
# Integration tests run in parallel with unit tests (after build passes)
# Split into 15 test groups for parallel execution
# Network isolation uses nftables (ip coi forward chain)
integration:
name: Integration Tests (${{ matrix.test_group.name }})
runs-on: ubuntu-24.04
needs: build
# 90 (not 60): the build-heavy lanes (core-build especially) run ~15 tests
# that each build a full Coi image. On a cold image cache — which happens
# whenever internal/image/**, profiles/default/**, or the build script
# change — those rebuild from scratch (a slim build alone can take ~10min on
# a slow runner), and the suite legitimately exceeds 60min. The IPv4 apt fix
# removed the indefinite hang; this gives the genuinely-long cold runs room
# to finish instead of being cancelled at the cap. Fast/warm lanes are
# unaffected (they finish well under either limit).
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
test_group:
- name: shell-ephemeral
path: tests/shell/ephemeral
description: "Ephemeral shell session tests"
- name: shell-persistent
path: tests/shell/persistent
description: "Persistent shell session tests"
- name: network
path: tests/network
description: "Network isolation tests"
- name: no-sudoers
path: tests/network/test_no_sudo_mode.py
no_sudoers: true
description: "Non-sudoers path (#508): [network] use_sudo=false, no passwordless nft sudo rule — restricted/allowlist fail clearly, open mode + health work"
- name: container-file
path: tests/container tests/file
description: "Container and file operations"
- name: core
path: tests/list tests/attach tests/tmux tests/kill tests/persist
description: "Core commands: list/attach/tmux/kill/persist"
- name: core-build
path: tests/build
description: "Build command tests (each builds a full image — kept on its own lane)"
- name: core-run
path: tests/run
description: "Run command tests"
- name: misc-cli
path: tests/cli
description: "CLI flag/format/output tests"
- name: misc-snapshot
path: tests/meta tests/snapshot tests/image
description: "Snapshot, image, and meta command tests"
- name: misc-commands
path: tests/audit tests/clean tests/completion tests/docker tests/errors tests/help tests/info tests/mount tests/monitor tests/top tests/shutdown tests/update tests/version tests/main_help_flag.py tests/main_help_shorthand.py
description: "Misc commands: audit/clean/completion/docker/errors/help/info/mount/monitor/top/shutdown/update/version + root help files"
- name: misc-config
path: tests/config tests/health tests/schema
description: "Config, health, and schema tests"
- name: monitoring-nft
path: tests/integration/test_nft_monitoring.py
description: "NFT network monitoring tests"
- name: monitoring-threats
path: tests/security_monitoring/threats
description: "Threat detection tests"
- name: monitoring-response
path: tests/security_monitoring/response
description: "Response and threshold tests"
- name: monitoring-advanced
path: tests/security_monitoring/advanced
description: "Host-side monitoring: env scan, process walk, fork bomb, spawn rate, auth log, proc events, cgroup init PID"
- name: monitoring-network-detection
path: tests/integration/test_network_connection_detection.py
description: "Host-side /proc/<pid>/net TCP/UDP suspicious connection detection"
- name: monitoring-log-inotify
path: tests/integration/test_log_watcher_inotify.py
description: "inotify-driven auth.log/syslog monitoring: syslog coverage, prompt delivery, log rotation"
- name: monitoring-file-fanotify
path: tests/integration/test_file_watcher_fanotify.py
description: "fanotify sensitive file monitoring: shadow read, sudoers write, authorized_keys write"
# fanotify_init needs CAP_SYS_ADMIN; resolving /proc/<pid>/root and
# reading root-only files need CAP_SYS_PTRACE and CAP_DAC_READ_SEARCH.
file_caps: cap_sys_admin,cap_sys_ptrace,cap_dac_read_search
- name: uid-mapping
path: tests/container/uid_mapping_shift_true.py tests/container/uid_mapping_raw_idmap.py tests/limits
description: "UID mapping and limits tests (limits sits here to shorten the slow misc-config lane)"
- name: git-hooks
path: tests/git_hooks
description: "Git hooks and security protection tests"
- name: monitoring-db
path: tests/integration/test_issue_505_resume_monitoring_panic.py tests/integration/test_gtfobins_db_pattern_detection.py tests/integration/test_gtfobins_db_absent_fallback.py tests/integration/test_sigma_db_detection.py
description: "Monitoring detection-DB load paths (GTFOBins + Sigma), present and absent, incl. #505 regression"
- name: terminal-pollution
path: tests/integration/test_session_diagnostics_no_terminal_pollution.py
description: "Session-runtime diagnostics must not leak onto the attached terminal (#372): nft debug + runtime-limit auto-stop"
# Incus 6.1..7.4 paths (file push without --archive): Zabbly LTS 7.0.
- name: incus-lts-file
path: tests/file
incus_channel: lts-7.0
description: "File push/pull on Incus LTS 7.0 (pre-7.5 client and server)"
- name: incus-lts-session
path: tests/shell/ephemeral/resume_content_roundtrip_ephemeral.py tests/shell/ephemeral/new_session_with_resume_ephemeral.py tests/shell/ephemeral/managed_settings_permissions_ephemeral.py
incus_channel: lts-7.0
description: "Session setup (config-dir restore, managed settings) on Incus LTS 7.0 (pre-7.5 client and server)"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Go build
uses: ./.github/actions/setup-go-build
with:
packages: nftables
- name: Configure nft and journal access
env:
NO_SUDOERS: ${{ matrix.test_group.no_sudoers }}
run: |
# Set up NFT monitoring access for CI
# Add runner to systemd-journal group for log access
sudo usermod -aG systemd-journal $USER
# The no-sudoers lane (#508) deliberately skips the passwordless-nft
# sudoers rule the installer would add, to exercise the path where a
# user declines it. (Note: GitHub runners still grant the runner
# blanket sudo, so the use_sudo=false config flag — not the absence of
# this file — is what actually drives the non-privileged behavior the
# tests assert.)
if [ "$NO_SUDOERS" = "true" ]; then
echo "no-sudoers lane: skipping /etc/sudoers.d/coi-nft"
else
# Configure sudo NOPASSWD for nft commands
bash scripts/install-sudoers-dropin.sh "#$(id -u) ALL=(ALL) NOPASSWD: /usr/sbin/nft *" /etc/sudoers.d/coi-nft
# Verify nft access
sudo -n nft list ruleset || echo "NFT access configured"
fi
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.12'
- name: Cache Python dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt', '**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/support/requirements.txt
- name: Lint Python code with ruff
run: |
echo "Running ruff linter on Python test code..."
ruff check tests/
echo "Checking Python code formatting..."
ruff format --check tests/
- name: Enable swap (for future cgroup controller support)
run: |
# Activate swap so the memory.swap cgroup controller can work if
# the kernel supports delegation (currently it doesn't on GHA runners,
# so we also patch the embedded config to skip swap limits).
if [ -f /swapfile ]; then
sudo swapon /swapfile 2>/dev/null || true
fi
swapon --show || true
- name: Set up Incus
uses: ./.github/actions/setup-incus
with:
channel: ${{ matrix.test_group.incus_channel || 'stable' }}
- name: Check Incus is below 7.5
if: matrix.test_group.incus_channel
run: |
incus version
for v in "$(incus version | sed -n 's/^Client version: //p')" \
"$(incus version | sed -n 's/^Server version: //p')"; do
if ! printf '6.1\n%s\n' "$v" | sort -V -C || printf '7.5\n%s\n' "$v" | sort -V -C; then
echo "ERROR: Incus $v is not in [6.1, 7.5)"
exit 1
fi
done
- name: Check kernel idmap support
run: |
echo "Kernel version:"
uname -r
echo "Checking for idmapped mount support:"
grep -i idmap /proc/filesystems || echo "No idmap in /proc/filesystems"
echo "Checking btrfs features:"
sudo btrfs filesystem df /var/lib/incus/storage-pools/default || true
echo "AppArmor status:"
sudo aa-status | grep incus || echo "No incus AppArmor profiles"
echo "Checking if AppArmor is blocking bind mounts:"
sudo dmesg | grep -i "apparmor.*denied" | tail -20 || echo "No recent AppArmor denials"
- name: Build Coi binary
run: |
go build -o coi ./cmd/coi
# Grant CAP_LINUX_IMMUTABLE for host-side immutable protection tests,
# plus any lane-specific capabilities (test_group.file_caps)
sudo setcap "cap_linux_immutable${FILE_CAPS:+,$FILE_CAPS}=ep" ./coi
getcap ./coi
./coi version
env:
FILE_CAPS: ${{ matrix.test_group.file_caps }}
- name: Configure Coi for CI (use open network mode for builds)
run: |
# Use open mode by default so image builds can access internet
# Tests will explicitly use restricted/allowlist modes when testing network isolation
# Monitoring is NOT enabled globally - monitoring tests use their own enable_monitoring fixture
mkdir -p ~/.coi
cat > ~/.coi/config.toml << 'EOF'
[network]
mode = "open"
EOF
echo "Created Coi config with network.mode = open"
- name: Test bind mount functionality
continue-on-error: true
run: |
# Skip if base image is not available (e.g., remote was unreachable and no cache)
if ! incus image info coi-ubuntu-24.04 >/dev/null 2>&1; then
echo "WARNING: coi-ubuntu-24.04 image not available, skipping bind mount test"
exit 0
fi
echo "Testing if bind mounts work with shift=true..."
# Create test directory and file
mkdir -p /tmp/test-bind-mount
echo "test-content" > /tmp/test-bind-mount/test-file.txt
# Launch test container (use local alias to avoid external network dependency)
incus launch coi-ubuntu-24.04 test-bind-mount-container
sleep 5
# Add bind mount with shift=true
incus config device add test-bind-mount-container testmount disk source=/tmp/test-bind-mount path=/mnt/test shift=true
# Check if file is visible inside container
echo "Files in container /mnt/test:"
incus exec test-bind-mount-container -- ls -la /mnt/test/
# Try to read the file
echo "Reading file from container:"
incus exec test-bind-mount-container -- cat /mnt/test/test-file.txt || echo "FAILED: Cannot read file in container"
# Try to create a file from inside container
incus exec test-bind-mount-container -- sh -c 'echo "created-from-container" > /mnt/test/created.txt'
# Check if file appears on host
if [ -f /tmp/test-bind-mount/created.txt ]; then
echo "SUCCESS: File created in container is visible on host"
cat /tmp/test-bind-mount/created.txt
else
echo "FAILED: File created in container NOT visible on host"
ls -la /tmp/test-bind-mount/
fi
# Cleanup
incus delete test-bind-mount-container --force
rm -rf /tmp/test-bind-mount
- name: Restore Coi image from cache
id: cache-coi-image
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /tmp/coi-image.tar
key: ${{ runner.os }}-coi-image-${{ hashFiles('internal/image/**', 'testdata/dummy/**', 'profiles/default/**', '.github/ci-image.toml') }}
- name: Import Coi image from cache
if: steps.cache-coi-image.outputs.cache-hit == 'true'
run: |
echo "Restoring Coi image from cache..."
incus image import /tmp/coi-image.tar --alias coi-default
./coi image list
- name: Build Coi image
if: steps.cache-coi-image.outputs.cache-hit != 'true'
run: |
echo "Building Coi image (not cached)..."
# The build script apt/curls external mirrors; those occasionally reset
# ("curl: (35) Recv failure: Connection reset by peer"). The old 3x/10s
# loop (~20s total) was too tight to ride out a blip. Widen to 5 attempts
# with progressive backoff (15/30/45/60s, ~150s total) so a transient
# network error self-heals instead of redding the lane.
max_attempts=5
for attempt in $(seq 1 "$max_attempts"); do
echo "Attempt $attempt of $max_attempts..."
# Both OpenCode versions: see .github/ci-image.toml.
if COI_CONFIG=.github/ci-image.toml ./coi build; then
echo "Image built successfully on attempt $attempt"
break
fi
if [ "$attempt" -eq "$max_attempts" ]; then
echo "Failed to build Coi image after $max_attempts attempts"
exit 1
fi
backoff=$((attempt * 15))
echo "Build failed (often a transient curl/network error in the build script), retrying in ${backoff}s..."
sleep "$backoff"
done
./coi image list
# Export image for caching. setup-incus sets images.compression_algorithm: none,
# so incus writes /tmp/coi-image.tar (actions/cache compresses it itself).
incus image export coi-default /tmp/coi-image
- name: Save Coi image to cache
if: steps.cache-coi-image.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /tmp/coi-image.tar
key: ${{ runner.os }}-coi-image-${{ hashFiles('internal/image/**', 'testdata/dummy/**', 'profiles/default/**', '.github/ci-image.toml') }}
- name: Free disk space for image-intensive tests
if: matrix.test_group.name == 'core-build' || matrix.test_group.name == 'core-run'
run: |
# core-build publishes many full images; free up space to avoid "no space left on device"
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/hostedtoolcache/CodeQL
sudo apt-get clean
df -h
- name: Debug iptables/nft state before tests
run: |
echo "=== FORWARD chain policy and rules ==="
sudo iptables -L FORWARD -n -v --line-numbers
echo ""
echo "=== nft coi table (if it exists) ==="
sudo nft list table ip coi 2>/dev/null || echo "(ip coi table not yet created)"
echo ""
echo "=== NAT table ==="
sudo iptables -t nat -L -n -v | head -30
- name: Run ${{ matrix.test_group.name }} tests with coverage
run: |
echo "============================================"
echo "Running: ${{ matrix.test_group.description }}"
echo "Path: ${{ matrix.test_group.path }}"
echo "Args: ${{ matrix.test_group.pytest_args }}"
echo "============================================"
# Run test group with coverage reporting.
# pytest_args allows filtering specific test classes within a file.
# --reruns retries a failed test a couple of times before giving up:
# these lanes drive real containers/incus/nft and have a documented tail
# of timing flakes (monitoring dedup, auth-log/inotify watchers,
# shell poweroff detection — see #653/#658/#665) where a single transient
# miss reds the whole run. A genuine bug still fails after every attempt;
# only integration lanes get this, never the strict Go unit lane.
python -m pytest ${{ matrix.test_group.path }} ${{ matrix.test_group.pytest_args }} -v -rs --tb=short --durations=0 --reruns 2 --reruns-delay 3 --cov=tests --cov-report=term-missing
env:
COI_BINARY: ./coi
GITHUB_REPOSITORY_URL: ${{ github.event.pull_request.head.repo.clone_url || format('https://github.com/{0}.git', github.repository) }}
- name: Cleanup
if: always()
run: |
./coi kill --all --force || true
./coi clean --force || true
# Coi inside a Lima VM (issue #543): runner -> Lima/QEMU-KVM Ubuntu guest with a
# virtiofs $HOME mount -> Incus -> Coi containers. This is the only lane where
# isColimaOrLimaEnvironment() is genuinely TRUE (it keys on virtiofs in
# /proc/mounts), reproducing the macOS Colima/Lima environment class (#530,
# #534, #221, #45) that hosted macOS runners cannot cover (Colima needs Intel
# nested virt; GitHub retired those runners). Most test workspaces live on the
# guest's native fs (pytest tmp_path -> /tmp); the #534 regression test
# deliberately puts its workspace ON the virtiofs mount to prove the
# isolation fallback covers idmap-incompatible device filesystems.
lima-smoke:
name: Lima Smoke (Coi inside a Lima VM, virtiofs)
runs-on: ubuntu-24.04
timeout-minutes: 60
needs: build
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
# qemu-system-x86 + qemu-utils: Lima's qemu driver; virtiofsd: the Rust
# vhost-user daemon Lima discovers via /usr/share/qemu/vhost-user/*.json
# (Lima does NOT search PATH for it).
- name: Set up Go build (+ QEMU, virtiofsd)
uses: ./.github/actions/setup-go-build
with:
packages: qemu-system-x86 qemu-utils virtiofsd
- name: Enable KVM (fail fast if unavailable)
run: |
# Standard GitHub pattern for /dev/kvm access on Linux runners.
# udev applies the rule ASYNCHRONOUSLY: without settle + retry the
# permission check races the mode change (observed: identical code
# passed twice, then failed on the third run purely on timing).
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
sudo udevadm settle --timeout=15 || true
for i in 1 2 3 4 5; do
if [ -r /dev/kvm ] && [ -w /dev/kvm ]; then break; fi
sleep 2
done
# Node exists but perms still not applied -> set them directly (the
# udev rule stays in place for any future node re-creation).
if [ -e /dev/kvm ] && { [ ! -r /dev/kvm ] || [ ! -w /dev/kvm ]; }; then
sudo chmod 666 /dev/kvm
fi
if [ ! -r /dev/kvm ] || [ ! -w /dev/kvm ]; then
echo "FATAL: /dev/kvm not usable — this lane must not run under TCG emulation"
ls -l /dev/kvm 2>&1 || echo "(no /dev/kvm node at all)"
lsmod | grep -i kvm || echo "(no kvm modules loaded)"
grep -m1 -oE 'vmx|svm' /proc/cpuinfo || echo "(no virt extensions in cpuinfo)"
exit 1
fi
ls -l /dev/kvm
# Rust virtiofsd sandboxes itself via unprivileged user namespaces;
# make sure noble's restriction cannot block it (cheap insurance).
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 || true
df -h /
- name: Build Coi binary (on the runner; go.mod needs Go 1.26)
run: |
# The guest is the same distro/arch (Ubuntu 24.04 amd64), so the binary
# runs there as-is. setcap happens in the guest on a native-fs copy —
# xattrs on the virtiofs mount are unreliable.
go build -o coi ./cmd/coi
./coi version
- name: Install Lima
run: |
LIMA_VERSION=2.1.4
curl -fsSL --retry 3 "https://github.com/lima-vm/lima/releases/download/v${LIMA_VERSION}/lima-${LIMA_VERSION}-Linux-x86_64.tar.gz" -o /tmp/lima.tar.gz
echo "78da175634c38beab62a6618d16b9c7aeeabdbb5d99ed5c9a03bac212c786bfa /tmp/lima.tar.gz" | sha256sum -c
sudo tar -C /usr/local -xzf /tmp/lima.tar.gz
limactl --version
- name: Cache Lima guest image downloads
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/lima
key: ${{ runner.os }}-lima-guest-${{ hashFiles('scripts/lima-coi.yaml') }}
- name: Restore Coi image from cache (restore-only; core-build owns saves)
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /tmp/coi-image.tar
key: ${{ runner.os }}-coi-image-${{ hashFiles('internal/image/**', 'testdata/dummy/**', 'profiles/default/**', '.github/ci-image.toml') }}
- name: Restore base Ubuntu image from cache (restore-only)
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /tmp/ubuntu-base-image.tar.gz
key: ${{ runner.os }}-ubuntu-24.04-base-image
- name: Stage image tarballs under $HOME (the guest sees only the ~ mount, not /tmp)
run: |
cp /tmp/coi-image.tar "$HOME/" 2>/dev/null || echo "no cached coi image (will build inside the guest)"
cp /tmp/ubuntu-base-image.tar.gz "$HOME/" 2>/dev/null || echo "no cached base image (smoke tests don't need it)"
- name: Create the stand-in Mac home (mounted at /Users/runner, #853)
run: mkdir -p /tmp/coi-mac-home
- name: Start the Lima VM (retry x3, refuse TCG fallback)
run: |
started=0
for attempt in 1 2 3; do
echo "limactl start attempt $attempt/3"
if timeout 600 limactl start --name=coi --tty=false "$GITHUB_WORKSPACE/scripts/lima-coi.yaml"; then
started=1
break
fi
limactl stop -f coi 2>/dev/null || true
limactl delete -f coi 2>/dev/null || true
sleep 10
done
if [ "$started" != 1 ]; then
echo "FATAL: lima failed to start after 3 attempts"
exit 1
fi
limactl list
# Lima v2 silently falls back to TCG when KVM is unusable — refuse that:
# a TCG run would blow the time budget and mask perf-class regressions.
if ! pgrep -af qemu-system-x86_64 | grep -Eq 'accel[ =]kvm|-enable-kvm'; then
echo "FATAL: QEMU is running WITHOUT KVM acceleration (TCG fallback):"
pgrep -af qemu-system-x86_64 || true
exit 1
fi
- name: Provision the guest (incus, deps, coi binary, image import-or-build)
# timeout-wrapped: if the guest dies mid-provision (first run: host memory
# exhaustion killed the VM during `incus publish`), the dead SSH session
# otherwise lingers ~20+ min on TCP timeouts before exiting 255.
run: |
timeout 2400 limactl shell --workdir "$GITHUB_WORKSPACE" coi -- bash "$GITHUB_WORKSPACE/scripts/lima-guest-setup.sh" \
"$GITHUB_WORKSPACE" "$HOME/coi-image.tar" "$HOME/ubuntu-base-image.tar.gz"
- name: Run smoke tests inside the Lima guest
run: |
# Single-quoted body: $HOME resolves in the GUEST (/home/<user>.guest,
# native fs) where the venv lives. cwd is the virtiofs-mounted checkout.
# COI_TEST_VIRTIOFS_DIR is quote-spliced from the HOST shell: the host
# $HOME is the virtiofs mount inside the guest — the #534 regression
# test creates its workspace there.
# No --cov: it measures test code only (all native lanes already emit it)
# and coverage's SQLite file on virtiofs is a needless flake surface.
limactl shell --workdir "$GITHUB_WORKSPACE" coi -- bash -c '
set -euo pipefail
export COI_BINARY=/usr/local/bin/coi
export COI_TEST_VIRTIOFS_DIR="'"$HOME"'"
export COI_TEST_MAC_HOME=/Users/runner
exec "$HOME/venv/bin/python" -m pytest \
tests/run/test_uid_mapping.py tests/run/test_run_script.py tests/run/test_virtiofs_workspace.py \
tests/run/test_mac_host_git_identity.py \
-v --tb=short --durations=0
'
- name: Diagnostics (on failure)
if: failure()
# Every limactl invocation is timeout-wrapped: if the guest/SSH is the
# thing that broke, an unguarded `limactl shell` hangs this step until
# the job timeout (observed on the first run) instead of surfacing logs.
run: |
set +e
echo "=== host ==="
df -h; free -m
echo "--- host dmesg tail (OOM kills of qemu land here) ---"
sudo dmesg | tail -n 30
timeout 30 limactl list
echo "--- hostagent stderr (virtiofsd/QEMU spawn failures land here) ---"
tail -n 100 "$HOME/.lima/coi/ha.stderr.log" 2>/dev/null
echo "--- guest serial console tail (guest kernel oops/OOM land here) ---"
tail -n 80 "$HOME"/.lima/coi/serial*.log 2>/dev/null
echo "=== guest ==="
timeout 90 limactl shell coi -- bash -c '
grep virtiofs /proc/mounts; id
timeout 15 incus list 2>&1
timeout 15 incus warning list 2>&1 | head -20
sudo journalctl -u incus -n 100 --no-pager 2>&1 | tail -n 60
sudo dmesg | tail -n 40
df -h /; free -m
' 2>&1 | head -n 200
echo "=== diagnostics done ==="
- name: Stop the VM
if: always()
run: timeout 60 limactl stop -f coi 2>/dev/null || true
# End-to-end regression guard for #666 on a REAL non-apt distro. The stubbed Go
# tests (Unit lane) source install.sh with a hand-set PKG_MANAGER and mocked
# binaries; this runs the actual storage-selection logic inside a genuine Arch
# container where `pacman` and `command -v zfs` resolve for real, proving the
# installer never auto-installs ZFS on Arch (which breaks the initramfs) and
# selects btrfs instead. incus/sudo are intercepted by a recording shim — we
# must never actually run `pacman -S zfs*`, and there is no incus daemon here.
installer-storage-arch:
# Quoted because the unquoted ' #666)' would be parsed as a YAML comment,
# truncating the job name to 'Installer Storage E2E (Arch,'.
name: "Installer Storage E2E (Arch, #666)"
runs-on: ubuntu-24.04
timeout-minutes: 10
needs: build
container:
# Pinned by digest (like every action in this file) so the test's
# environmental assumptions — real pacman, zfs absent, btrfs absent by
# default — can't drift out from under it on an upstream image rebuild.
image: archlinux:latest@sha256:b0deabeb3d283da2c7f7dbf0eea051b7b2cd0554e0b737cc457fd21683bdcdd1
steps:
- name: Install git (needed by actions/checkout)
run: pacman -Sy --noconfirm --needed git
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: ZFS gate — btrfs absent (installer must reach for btrfs-progs, never zfs)
run: bash tests/installer/zfs_gate_arch_e2e.sh
- name: ZFS gate — btrfs already present (reporter's case, no install at all)
env:
COI_E2E_BTRFS_PRESENT: "1"
run: bash tests/installer/zfs_gate_arch_e2e.sh
ci-success:
name: CI Success
runs-on: ubuntu-24.04
timeout-minutes: 5
if: always()
needs:
- build
- unit-tests
- macos-unit-tests
- integration
- lima-smoke
- installer-storage-arch
steps:
- name: Check all jobs passed
if: |
contains(needs.*.result, 'failure') ||
contains(needs.*.result, 'cancelled') ||
contains(needs.*.result, 'skipped')
run: exit 1
- run: echo "All CI checks passed!"