fact (File ACTivity) is a BPF-based file integrity monitoring tool for PCI DSS compliance. It attaches to kernel LSM hooks, receives file system events via ring buffers, enriches them, and outputs via gRPC, OTLP, or JSON. Supports hot-reload via SIGHUP and exposes Prometheus metrics.
Requires: BTF symbols, LSM hooks, BPF trampolines. Tested on RHEL 9.6+/10+, RHCOS 4.16+, Fedora CoreOS 43.
Cargo workspace with three crates (default-members = ["fact"], so bare cargo build only builds the main crate):
- fact (edition 2024): Main binary — BPF loading (aya), event processing, config, output, metrics
- fact-api (edition 2021): gRPC API generated from protos in
third_party/stackrox/proto(git submodule) - fact-ebpf (edition 2021): BPF C programs (
src/bpf/main.c,checks.c) + Rust bindings via bindgen
libbpf-dev, protobuf-compiler, clang/libclang (BPF compilation + bindgen), make, git (version string). Proto submodule: git submodule update --init after fresh clone.
cargo build # builds only `fact` (default member)
cargo build --release
cargo checkmake lint # cargo clippy --all-targets --all-features -- -D warnings + tests/
cargo clippy --all-targets --all-features -- -D warnings # Rust onlymake -C tests lint runs grpc-gen, so it needs the proto submodule and ruff/pyright installed in the active venv.
make format # cargo fmt + clang-format (BPF C/H) + ruff format tests/
make format-check # check only, no modificationsCLANG_FMT defaults to clang-format; CI uses clang-format-18. C/H files use 2-space indent (.editorconfig, .clang-format).
Rust unit tests (no sudo needed):
cargo testBPF unit tests (requires sudo, avoid in automated workflows):
cargo test --config 'target."cfg(all())".runner="sudo -E"' --features=bpf-testIntegration tests (require Docker, a built image, and proto codegen):
make image # build container image first
python3 -m venv .venv # create venv (first time)
source .venv/bin/activate
pip install -r tests/requirements.txt
make -C tests pytest # grpc-gen + pytest --image=$(make image-name)
pytest --image="<image-tag>" test_file_open.py # single file, from tests/
pytest --image="<image-tag>" --output=otlp # test OTLP outputIntegration tests use the Docker Python SDK — they launch fact in a privileged container with --network=host, bind-mount / as /host, and mount the config at /etc/stackrox/fact.yml. They communicate via gRPC/OTLP mock servers + health check endpoint. Missing fact images are pulled automatically; QA helper images use tests/containers/QA_TAG (override with FACT_QA_TAG), and --no-local-builds fails instead of building them. Python linting: ruff check . && pyright . (from tests/).
cargo run --release --config 'target."cfg(all())".runner="sudo -E"' -- -p /etc -p /var/log--replay <jsonl> reads pre-recorded events and skips BPF loading and HostScanner (fact/src/replay.rs), useful for testing the pipeline without sudo.
- Kernel LSM hooks → BPF programs (
fact-ebpf/src/bpf/main.c) → ring buffer Bpfworker (fact/src/bpf/mod.rs) reads ring buffer → mpsc channelHostScanner(fact/src/host_scanner.rs) enriches host paths, filters events, and does periodic inode scanningoutput(fact/src/output/mod.rs) fans out over a broadcast channel → gRPC, OTLP, or JSON stdout- gRPC output rate limiting lives in
fact/src/output/grpc.rs(governor);rate_limit: 0means unlimited
fact-ebpf/src/bpf/types.h is the single source of truth for event structs and enums. build.rs runs bindgen on it to generate $OUT_DIR/bindings.rs, which lib.rs pulls in via include!. Edit only types.h — Rust bindings are generated automatically. Keep it minimal and do not include vmlinux.h there.
fact-ebpf/build.rs compiles main.c and checks.c with clang targeting BPF, then runs bindgen on types.h. BPF objects are embedded in the binary. No manual clang invocation needed. fact-ebpf/src/bpf/vmlinux/{x86_64,aarch64}.h are checked-in generated kernel headers; do not hand-edit them.
- Files loaded low → high precedence:
/etc/stackrox/fact.yml,/etc/stackrox/fact.yaml,./fact.yml,./fact.yaml; CLI args andFACT_*env vars override them. - YAML parsing is strict: unknown keys cause errors.
- Hot-reload watches those files by mtime every 10s plus SIGHUP (
fact/src/config/reloader/mod.rs). Only paths/endpoint/grpc/otel/scan_interval propagate; changinghotreloaditself requires a restart. FACT_HOST_MOUNT(default/, tests use/host) controls monitored-path and host lookups.scan_interval: 0disables periodic scanning.- Schema:
fact/src/config/mod.rs. Config tests:fact/src/config/tests.rsandfact/src/config/reloader/tests.rs.
bpf-test: gates tests that load actual BPF programs (requires sudo)otel: enables OpenTelemetry/OTLP output (fact/Cargo.toml); seedocs/otel/otel.md
.cargo/config.tomlsetsbuild.rustflags = ["-C", "force-frame-pointers=yes"]for all builds andregistry.global-min-publish-age = "3 days". Cargo auto-loads.cargo/config.tomlin ancestor dirs and$CARGO_HOME/config.toml.fact/build.rsshells out tomake -sC .. versionto embed the git version string — builds requiremake; outside a git checkout the embedded version is empty.CLAUDE.mdis a symlink to this file; edit onlyAGENTS.md.- Prometheus metrics use prefix
stackrox_fact. - Don't hand-edit generated artifacts:
tests/internalapi/,mock-server/internalapi/,fact-ebpf/src/bpf/vmlinux/*, andcompile_commands.json.
- PR checklist is enforced by
.github/workflows/pr-checklist.yml: changes need aCHANGELOG.mdentry or an explicit note that none is needed, and CI results must be inspected. - Release process:
docs/release.md(prepare-release.yml/release.yml).