-
Notifications
You must be signed in to change notification settings - Fork 4
chore: rename CLAUDE.md to AGENTS.md and improve it #1537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Molter73
wants to merge
2
commits into
main
Choose a base branch
from
mauro/chore/update-agents-md
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−184
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # AGENTS.md | ||
|
|
||
| ## Project Overview | ||
|
|
||
| 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. | ||
|
|
||
| ## Workspace Structure | ||
|
|
||
| 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 | ||
|
|
||
| ### Build system dependencies | ||
|
|
||
| `libbpf-dev`, `protobuf-compiler`, `clang` (for BPF compilation), `make`, `git` (build.rs runs `make version` to embed git tag). | ||
|
|
||
| Proto submodule: `git submodule update --init` after fresh clone. | ||
|
|
||
| ## Commands | ||
|
|
||
| ### Build & check | ||
| ```sh | ||
| cargo build # builds only `fact` (default member) | ||
| cargo build --release | ||
| cargo check | ||
| ``` | ||
|
Molter73 marked this conversation as resolved.
|
||
|
|
||
| ### Lint | ||
| ```sh | ||
| make lint # cargo clippy --all-targets --all-features -- -D warnings + tests/ | ||
| cargo clippy --all-targets --all-features -- -D warnings # Rust only | ||
| ``` | ||
|
|
||
| ### Format | ||
| ```sh | ||
| make format # cargo fmt + clang-format (BPF C/H) + ruff format tests/ | ||
| make format-check # check only, no modifications | ||
| ``` | ||
|
|
||
| ### Test | ||
|
|
||
| **Rust unit tests** (no sudo needed): | ||
| ```sh | ||
| cargo test | ||
| ``` | ||
|
|
||
| **BPF unit tests** (requires sudo, avoid in automated workflows): | ||
| ```sh | ||
| cargo test --config 'target."cfg(all())".runner="sudo -E"' --features=bpf-test | ||
| ``` | ||
|
|
||
| **Integration tests** (require Docker, a built image, and proto codegen): | ||
| ```sh | ||
| make image # build container image first | ||
| python3 -m venv .venv # create venv (first time) | ||
| source .venv/bin/activate # activate venv | ||
| pip install -r tests/requirements.txt # install deps (first time) | ||
| cd tests/ | ||
| make grpc-gen # generate Python proto stubs | ||
| pytest --image="<image-tag>" # run all tests | ||
| pytest test_file_open.py --image="<image-tag>" # single file | ||
| pytest --output=otlp --image="<image-tag>" # test OTLP output | ||
| ``` | ||
|
|
||
| Integration tests use the Docker Python SDK — they launch `fact` in a privileged container with `--network=host`, bind-mount `/` as `/host`, and communicate via gRPC/OTLP mock servers + health check endpoint. Python linting: `ruff check . && pyright .` (from `tests/`). | ||
|
|
||
| ### Run locally (requires sudo) | ||
| ```sh | ||
| cargo run --release --config 'target."cfg(all())".runner="sudo -E"' -- -p /etc -p /var/log | ||
| ``` | ||
|
|
||
| ## Key Architecture Notes | ||
|
|
||
| ### Event flow | ||
| 1. Kernel LSM hooks → BPF programs (`fact-ebpf/src/bpf/main.c`) → ring buffer | ||
| 2. `Bpf` worker (`fact/src/bpf/mod.rs`) reads ring buffer → channel | ||
| 3. `HostScanner` (`fact/src/host_scanner.rs`) does periodic inode scanning | ||
| 4. Rate limiting (`fact/src/rate_limiter.rs`) → output (gRPC/OTLP/JSON) | ||
|
|
||
| ### Event type definitions | ||
| `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. | ||
|
|
||
| ### BPF build integration | ||
| `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. | ||
|
|
||
| ### Config | ||
| - Schema: `fact/src/config/mod.rs` | ||
| - Hot-reload: `fact/src/config/reloader/mod.rs` (polls every 10s + SIGHUP trigger) | ||
| - Config tests: `fact/src/config/tests.rs` and `fact/src/config/reloader/tests.rs` | ||
| - Config loaded from YAML files, env vars, or CLI args | ||
|
|
||
| ### Feature flags | ||
| - `bpf-test`: gates tests that load actual BPF programs (requires sudo) | ||
| - `otel`: enables OpenTelemetry/OTLP output (`fact/Cargo.toml`) | ||
|
|
||
| ## Gotchas | ||
|
|
||
| - `config.toml` at workspace root sets `rustflags = ["-C", "force-frame-pointers=yes"]` — this affects all builds | ||
|
Molter73 marked this conversation as resolved.
|
||
| - `fact/build.rs` shells out to `make -sC .. version` to embed the git version string — builds fail without `make` and a valid git repo | ||
| - `CLANG_FMT` defaults to `clang-format`; CI uses `clang-format-18`. Override via env if your system name differs | ||
| - `CLAUDE.md` exists alongside this file with identical content — `AGENTS.md` is canonical | ||
| - Prometheus metrics use prefix `stackrox_fact` | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AGENTS.md |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.