Skip to content

Commit 9c38835

Browse files
authored
Merge pull request #1 from edera-dev/bleggett/preflight-newstuff
Various fixes and reorg
2 parents adc0c32 + 51dd4e0 commit 9c38835

21 files changed

Lines changed: 1635 additions & 914 deletions

File tree

Cargo.lock

Lines changed: 468 additions & 155 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "preflight"
33
version = "0.1.0"
44
edition = "2024"
5+
description = "CLI to run pre-deployment checks before running workloads."
56

67
[dependencies]
78
anyhow = "1.0.99"
@@ -12,3 +13,9 @@ log = "0.4.28"
1213
procfs = "0.18.0"
1314
sysinfo = "0.36.1"
1415
tar = "0.4.44"
16+
tokio = { version = "1", features = ["full"] }
17+
tokio-util = { version = "0.7" }
18+
tokio-stream = { version = "0.1", features = ["io-util", "net"] }
19+
nix = { version= "0.31", features = ["sched"] }
20+
futures = "0.3"
21+
async-trait = "0.1"

README.md

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
# Preflight CLI
22

33
Internal CLI to run **pre-deployment checks** before running workloads.
4-
Checks are organized into groups (e.g., `System Checks`, `Scripted Checks`) and controlled via environment variables.
4+
Checks are organized into groups (e.g., `PVH Checks`, `Kernel Checks`) and controlled via environment variables.
55

66
---
77

88
## Usage
99

10-
Run inside Docker:
10+
### Run official release via Docker
1111

1212
```bash
1313
docker run \
1414
--pull always \
1515
--env RUST_LOG=debug \
1616
--env EDERA_PREFLIGHT_VERBOSE=true \
17-
--env EDERA_PREFLIGHT_TARGET_DIR='/host' \
18-
--env EDERA_PREFLIGHT_SKIP_GROUPS='ScriptedChecks;SystemChecks' \
19-
--env EDERA_PREFLIGHT_SCRIPTS_DIR=/scripts \
20-
--volume /:/host \
17+
--env EDERA_PREFLIGHT_SKIP_GROUPS='PVHChecks;KernelChecks' \
2118
--pid host \
22-
--net host \
2319
--privileged \
2420
us-central1-docker.pkg.dev/edera-protect/staging/protect-preflight:main
2521
```
2622

23+
Podman should also work.
24+
25+
### Run locally from repo root via Docker
26+
27+
Recommended way to run locally and debug/validate, will use local copy of repo.
28+
29+
```bash
30+
sh hack/debug/local.sh
31+
```
32+
2733
---
2834

2935
## Environment Variables
@@ -32,28 +38,46 @@ docker run \
3238
| ----------------------------- | ------------------------------------------------------ | ----------------------------- |
3339
| `RUST_LOG` | Log level (`error`, `warn`, `info`, `debug`, `trace`). | `debug` |
3440
| `EDERA_PREFLIGHT_VERBOSE` | Enable verbose output (`true`/`false`). | `true` |
35-
| `EDERA_PREFLIGHT_SKIP_GROUPS` | Semicolon-separated list of groups to skip. | `SystemChecks;ScriptedChecks` |
36-
| `EDERA_PREFLIGHT_SCRIPTS_DIR` | Directory containing custom shell-script checks. | `/scripts` |
37-
| `EDERA_PREFLIGHT_TARGET_DIR` | Directory to chroot to before running checks. Needed when running in a container. | `/host` |
41+
| `EDERA_PREFLIGHT_SKIP_GROUPS` | Semicolon-separated list of groups to skip. | `PVHChecks;KernelChecks` |
3842
| `EDERA_PREFLIGHT_REPORT_DIR` | Directory to write a report to. Defaults to tmpdir | `/tmp` |
3943

4044
---
4145

4246
## Example Output
4347

4448
```text
45-
[2025-09-17T05:05:33Z INFO preflight] Running Group [System Checks] - System requirement checks
46-
[2025-09-17T05:05:33Z DEBUG preflight::system] total memory = 66617298944
47-
[2025-09-17T05:05:33Z ERROR preflight] [System Checks] Errored: group errored
48-
[2025-09-17T05:05:33Z INFO preflight] [System Checks] Enough Memory: Passed
49-
[2025-09-17T05:05:33Z ERROR preflight] [System Checks] Should Error: Errored: Pretending to error
50-
[2025-09-17T05:05:33Z WARN preflight] [System Checks] Should Fail: Failed: Pretending to fail
51-
[2025-09-17T05:05:33Z INFO preflight] Running Group [Scripted Checks] - Checks composed through small shell scripts
52-
[2025-09-17T05:05:33Z ERROR preflight] [Scripted Checks] Errored: group errored
53-
[2025-09-17T05:05:33Z INFO preflight] [Scripted Checks] Should Pass: Passed
54-
[2025-09-17T05:05:33Z WARN preflight] [Scripted Checks] Should Fail: Failed: script returned Some(1)
55-
[2025-09-17T05:05:33Z ERROR preflight] [Scripted Checks] /totally/fake/script: Errored: No such file or directory (os error 2)
56-
Error: checks failed
49+
[2026-02-13T00:28:35Z INFO preflight] Writing all files to /tmp/protect-preflight-bundle-20260213-002835
50+
[2026-02-13T00:28:35Z INFO preflight] Running Group [System Checks] - System requirement checks
51+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::system] Enough space on disk mounted at / - 617760940032
52+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::system] Not enough space on disk mounted at /etc/resolv.conf - 9729925120
53+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::system] Enough space on disk mounted at /etc/hostname - 617760940032
54+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::system] Enough space on disk mounted at /etc/hosts - 617760940032[2026-02-13T00:28:35Z DEBUG preflight::checkers::system] total memory = 28762972160
55+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Checks] Passed
56+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Checks] Enough Memory: Passed
57+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Checks] Enough Disk: Passed
58+
[2026-02-13T00:28:35Z INFO preflight] Running Group [PVH Checks] - PVH capability checks
59+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::pvh] VM_CR=0x0 (svmdis=0)
60+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::pvh] EFER=0x200d01 (SVME=0)
61+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::pvh] AMD-V supported but unavailable under hypervisor
62+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::pvh] Virtualization is enabled or can be enabled
63+
[2026-02-13T00:28:35Z DEBUG preflight::helpers] [PVH Checks] Skipped
64+
[2026-02-13T00:28:35Z INFO preflight::helpers] [PVH Checks] PVH Support: Passed
65+
[2026-02-13T00:28:35Z INFO preflight] Running Group [Kernel Checks] - Kernel requirement checks
66+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::kernel] module msr
67+
[2026-02-13T00:28:35Z DEBUG preflight::checkers::kernel] module nf_tables
68+
[2026-02-13T00:28:35Z INFO preflight::helpers] [Kernel Checks] Passed
69+
[2026-02-13T00:28:35Z INFO preflight::helpers] [Kernel Checks] Host Has Necessary Modules: Passed
70+
[2026-02-13T00:28:35Z INFO preflight::helpers] [Kernel Checks] Host Kernel Version Is Good: Passed
71+
[2026-02-13T00:28:35Z INFO preflight] Running Group [System Info Recorder] - System requirement and status checks - records for informational purposes
72+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Passed
73+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Record lspci -vvv: Passed
74+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Record dmidecode: Passed
75+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Record /proc/cpuinfo: Passed
76+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Record /proc/cmdline: Passed
77+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Record /boot/grub2/grub.cfg: Passed
78+
[2026-02-13T00:28:35Z INFO preflight::helpers] [System Info Recorder] Record boot/config-6.18.6: Passed
79+
[2026-02-13T00:28:35Z DEBUG preflight] Read 84023 bytes of tar
80+
[2026-02-13T00:28:35Z INFO preflight] Wrote to: /tmp/protect-preflight-bundle-20260213-002835.tar.gz
5781
```
5882

5983
* **INFO** → check passed or group started
@@ -67,8 +91,11 @@ Exit code is **non-zero** if any check/group fails or errors.
6791
## Notes
6892

6993
* Use `EDERA_PREFLIGHT_SKIP_GROUPS` to bypass slow or irrelevant checks.
70-
* Script-based checks must be **executable** and located in `EDERA_PREFLIGHT_SCRIPTS_DIR`.
7194

72-
## Script Based Checks
95+
## Dev Notes
96+
97+
* [src/recorders](src/recorders) - Special category of checkers that capture host machine state and generate informational reports.
98+
* [src/checkers](src/checkers) - All checkers that validate and actively interrogate various aspects of the host machine go here.
99+
* [src/helpers](src/helpers) - Shared bits.
73100

74-
Check the scripts [README.md](./scripts/README.md)
101+
By default, everything runs inside the container, and any system tools or binaries or other bits needed by the checkers can be installed or baked inside the container. For checks that need to jump out and touch the host filesystem or state, we use the [src/helpers/host_executor.rs](src/helpers/host_executor.rs).

hack/code/autofix.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
REAL_SCRIPT="$(realpath "${0}")"
5+
cd "$(dirname "${REAL_SCRIPT}")/../.."
6+
7+
./hack/build/cargo.sh clippy --all --fix --allow-dirty --allow-staged
8+
./hack/build/cargo.sh fmt --all

hack/debug/local.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
VER=$(date +%s)
5+
USERIMG=$(whoami)
6+
REGISTRY="localhost"
7+
8+
docker build . -f ./images/Containerfile.preflight -t "${REGISTRY}/${USERIMG}-preflight-debug:${VER}"
9+
10+
docker run --privileged --pid="host" \
11+
-e RUST_LOG="debug" \
12+
-e EDERA_PREFLIGHT_VERBOSE=true \
13+
-e EDERA_PREFLIGHT_TARGET_DIR='/host' \
14+
-e EDERA_PREFLIGHT_SKIP_GROUPS='' \
15+
-e EDERA_PREFLIGHT_SCRIPTS_DIR=/scripts \
16+
"${REGISTRY}/${USERIMG}-preflight-debug:${VER}"
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/edera-dev/cross-base-linux-musl:latest@sha256:87ba899ea380bd85c22f194ab2f4f2cf791fc832d27ee20bb00d07ce23771975 AS build
1+
FROM ghcr.io/edera-dev/cross-base-linux-musl:latest@sha256:a591bb18a5ede06c6e814a4d263dddb172e0b9f998873841163585c286484983 AS build
22

33
ENV TARGET_LIBC=musl TARGET_VENDOR=unknown DISABLE_CROSS_RS=1
44

@@ -10,4 +10,3 @@ RUN mv ./target/$(./hack/build/target.sh)/release/preflight /usr/sbin
1010
FROM cgr.dev/chainguard/wolfi-base:latest
1111
ENTRYPOINT ["/usr/sbin/preflight"]
1212
COPY --from=build /usr/sbin/preflight /usr/sbin/preflight
13-
COPY --from=build /usr/src/app/scripts /scripts

scripts/README.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)