Skip to content

feat(config): configurable loaded BPF programs#1086

Open
Molter73 wants to merge 2 commits into
mainfrom
mauro/feat/config-hook-loading
Open

feat(config): configurable loaded BPF programs#1086
Molter73 wants to merge 2 commits into
mainfrom
mauro/feat/config-hook-loading

Conversation

@Molter73

@Molter73 Molter73 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Description

This patch makes it possible to decide at runtime which BPF programs should be loaded.

To make the code as flexible as possible the configuration side stores the programs in a map, then the bpf side validates the configuration to notify if an unknown BPF program is found.

Default behavior is still loading and attaching all BPF programs.

Checklist

  • Patch has a change log entry OR does not need one.
  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

  • Test excluded programs are not loaded with bpftool
output of `bpftool prog list` with `file_open` and `inode_setxattr` disabled
41: lsm  name restrict_filesystems  tag 31efb7c56239148b  gpl
	loaded_at 2026-07-07T10:26:12+0200  uid 0
	xlated 520B  jited 294B  memlock 4096B  map_ids 22
	btf_id 67
	pids systemd(1)
7413: cgroup_device  tag 9b92522e365f8863  gpl
	loaded_at 2026-07-08T18:07:17+0200  uid 0
	xlated 616B  jited 344B  memlock 4096B  map_ids 8503
	pids virtqemud(2212115)
24824: cgroup_device  name sd_devices  tag c1591dae5f5bcd9f  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 464B  jited 298B  memlock 4096B
	pids systemd(1)
24825: cgroup_device  name sd_devices  tag 98b7b6f166b26c8a  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 184B  jited 111B  memlock 4096B
	pids systemd(1)
24826: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24827: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24828: cgroup_device  name sd_devices  tag 858f17d96476585f  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 792B  jited 490B  memlock 4096B
	pids systemd(1)
24829: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24830: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24831: cgroup_device  name sd_devices  tag feaab199760324c9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 504B  jited 319B  memlock 4096B
	pids systemd(1)
24832: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24833: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24834: cgroup_device  name sd_devices  tag c1591dae5f5bcd9f  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 464B  jited 298B  memlock 4096B
	pids systemd(1)
24835: cgroup_device  name sd_devices  tag a97c143260cd9940  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 416B  jited 268B  memlock 4096B
	pids systemd(1)
24836: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24837: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24838: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24839: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24840: cgroup_device  name sd_devices  tag c1591dae5f5bcd9f  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 464B  jited 298B  memlock 4096B
	pids systemd(1)
24841: cgroup_device  name sd_devices  tag 2faeafd5e3cce185  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 560B  jited 361B  memlock 4096B
	pids systemd(1)
24842: cgroup_device  name sd_devices  tag c1591dae5f5bcd9f  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 464B  jited 298B  memlock 4096B
	pids systemd(1)
24843: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24844: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24845: cgroup_device  name sd_devices  tag a97c143260cd9940  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 416B  jited 268B  memlock 4096B
	pids systemd(1)
24846: cgroup_device  name sd_devices  tag a97c143260cd9940  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 416B  jited 268B  memlock 4096B
	pids systemd(1)
24847: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24848: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24849: cgroup_device  name sd_devices  tag a97c143260cd9940  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 416B  jited 268B  memlock 4096B
	pids systemd(1)
24850: cgroup_device  name sd_devices  tag a97c143260cd9940  gpl
	loaded_at 2026-07-13T17:22:45+0200  uid 0
	xlated 416B  jited 268B  memlock 4096B
	pids systemd(1)
24930: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:50:51+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24931: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-13T17:50:51+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24970: cgroup_skb  name sd_fw_egress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-14T10:08:10+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24971: cgroup_skb  name sd_fw_ingress  tag 772db7720b2728e9  gpl
	loaded_at 2026-07-14T10:08:10+0200  uid 0
	xlated 64B  jited 64B  memlock 4096B
	pids systemd(1)
24973: socket_filter  tag 86d0579461d4b1e3
	loaded_at 2026-07-14T10:08:16+0200  uid 0
	xlated 848B  jited 461B  memlock 4096B  map_ids 30677
24974: socket_filter  tag 6d48e6fab26dfb6c
	loaded_at 2026-07-14T10:08:24+0200  uid 0
	xlated 848B  jited 461B  memlock 4096B  map_ids 30678
25094: lsm  name trace_inode_set_acl  tag 23c65a791e6c3807  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 6968B  jited 4457B  memlock 8192B  map_ids 30799,30804,30798,30801,30797,30796
	btf_id 13476
	pids fact(2870990)
25095: lsm  name trace_path_chmod  tag 816a9f14bc8da202  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 4240B  jited 2817B  memlock 8192B  map_ids 30799,30797,30802,30801,30804,30798,30803,30796
	btf_id 13476
	pids fact(2870990)
25096: lsm  name trace_path_rmdir  tag 2d7129a34779b8bb  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 4200B  jited 2754B  memlock 8192B  map_ids 30799,30797,30802,30801,30804,30798,30796
	btf_id 13476
	pids fact(2870990)
25097: lsm  name trace_path_chown  tag d0d1e170f16bcd54  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 4384B  jited 2899B  memlock 8192B  map_ids 30799,30797,30802,30801,30804,30798,30803,30796
	btf_id 13476
	pids fact(2870990)
25098: lsm  name trace_inode_removexattr  tag f9ef1a72a1b9fe73  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 6248B  jited 4003B  memlock 8192B  map_ids 30799,30804,30798,30801,30797,30796
	btf_id 13476
	pids fact(2870990)
25099: lsm  name trace_path_unlink  tag 5efbfd1d2a032d8c  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 4512B  jited 2922B  memlock 8192B  map_ids 30799,30797,30802,30801,30804,30798,30803,30796
	btf_id 13476
	pids fact(2870990)
25100: lsm  name trace_path_rename  tag 08ff150e408f18a2  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 7312B  jited 4598B  memlock 12288B  map_ids 30799,30797,30802,30801,30804,30798,30803,30796
	btf_id 13476
	pids fact(2870990)
25101: lsm  name trace_d_instantiate  tag 8d296658e710a937  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 5592B  jited 3673B  memlock 8192B  map_ids 30799,30800,30804,30798,30801,30797,30796
	btf_id 13476
	pids fact(2870990)
25102: lsm  name trace_path_mkdir  tag eb16e5690eecf38f  gpl
	loaded_at 2026-07-14T10:44:19+0200  uid 0
	xlated 2408B  jited 1370B  memlock 4096B  map_ids 30799,30797,30802,30801,30804,30800,30803
	btf_id 13476
	pids fact(2870990)

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added bpf.programs configuration to enable/disable specific BPF programs via enabled.
    • Configured programs are now validated against what’s available in the loaded eBPF object.
  • Bug Fixes

    • Disabled programs are skipped during load/attachment, with improved warnings.
    • Enhanced error context for eBPF loading and attachment failures.
  • Tests

    • Expanded YAML parsing, config update, and validation coverage for bpf.programs.
  • Documentation

    • Updated the changelog for the new configurable BPF program feature.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: d814cd21-9bb6-47da-a5ab-2f2ff064c232

📥 Commits

Reviewing files that changed from the base of the PR and between 9c99ec3 and 45914e6.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • CHANGELOG.md
  • fact/Cargo.toml
  • fact/src/bpf/checks.rs
  • fact/src/bpf/mod.rs
  • fact/src/config/mod.rs
  • fact/src/config/tests.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • CHANGELOG.md
  • fact/src/bpf/checks.rs
  • fact/src/config/mod.rs
  • fact/src/config/tests.rs
  • fact/src/bpf/mod.rs

📝 Walkthrough

Walkthrough

BPF configuration now supports per-program enablement, YAML parsing and merging, configuration-aware eBPF loading, validation, and structured attachment errors. Tests cover parsing, invalid configurations, updates, enablement behavior, and program validation.

Changes

BPF configuration and loading

Layer / File(s) Summary
Program configuration contract and parsing
fact/src/config/mod.rs, fact/src/config/tests.rs
BpfConfig stores per-program settings, parses bpf.programs, merges updates, initializes CLI defaults, and includes expanded parsing, validation, and update tests.
Config-driven eBPF loading and validation
fact/src/bpf/checks.rs, fact/src/bpf/mod.rs
eBPF loading uses configuration for map sizing and program selection, skips disabled or unsupported hooks, and validates configured program names.
Program attachment error handling
fact/Cargo.toml, fact/src/bpf/mod.rs, CHANGELOG.md
Program attachment uses helper functions and explicit BpfAttachError handling, with thiserror support and updated release notes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Bpf_new
  participant load_ebpf
  participant load_progs
  participant BpfConfig
  participant attach_progs
  participant EbpfObject
  Bpf_new->>load_ebpf: pass checks and BpfConfig
  load_ebpf->>EbpfObject: load configured maps and object
  Bpf_new->>load_progs: pass Btf and BpfConfig
  load_progs->>BpfConfig: query program_is_enabled
  load_progs->>EbpfObject: load enabled supported hooks
  Bpf_new->>attach_progs: attach loaded programs
  attach_progs->>EbpfObject: create LSM links
Loading

Suggested reviewers: rhacs-bot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: making loaded BPF programs configurable.
Description check ✅ Passed The description covers the change, checklist, testing, and verification steps, with only minor non-critical template items omitted.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mauro/feat/config-hook-loading

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.13675% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.51%. Comparing base (e4f6c57) to head (45914e6).

Files with missing lines Patch % Lines
fact/src/bpf/mod.rs 0.00% 49 Missing ⚠️
fact/src/config/mod.rs 93.84% 3 Missing and 1 partial ⚠️
fact/src/bpf/checks.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1086      +/-   ##
==========================================
+ Coverage   32.95%   33.51%   +0.56%     
==========================================
  Files          21       21              
  Lines        2971     3043      +72     
  Branches     2971     3043      +72     
==========================================
+ Hits          979     1020      +41     
- Misses       1989     2019      +30     
- Partials        3        4       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Molter73 Molter73 marked this pull request as ready for review July 14, 2026 08:30
@Molter73 Molter73 requested review from a team and rhacs-bot as code owners July 14, 2026 08:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fact/src/bpf/mod.rs`:
- Around line 53-56: Update the Bpf::validate_config call in the loading flow to
enforce its boolean result: continue only when validation succeeds, and return
an error through the existing load path when it returns false. Preserve the
current behavior for valid configurations while preventing startup with unknown
bpf.programs entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: db314835-ed6f-465f-9051-cb085fa2188a

📥 Commits

Reviewing files that changed from the base of the PR and between f892449 and 00b8d5f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • fact/Cargo.toml
  • fact/src/bpf/checks.rs
  • fact/src/bpf/mod.rs
  • fact/src/config/mod.rs
  • fact/src/config/tests.rs

Comment thread fact/src/bpf/mod.rs
@Molter73

Copy link
Copy Markdown
Collaborator Author

As discussed in #1049 (comment), at this time, implementing this configuration through environment variables or cli arguments will most likely require them to be expressed as JSON encoded strings, which is finicky and prone to escaping errors. So for the time being, the implementation is restricted to configuration files.

Molter73 added 2 commits July 14, 2026 12:20
This patch makes it possible to decide at runtime which BPF programs
should be loaded.

To make the code as flexible as possible the configuration side stores
the programs in a map, then the bpf side validates the configuration to
notify if an unknown BPF program is found.

Default behavior is still loading and attaching all BPF programs.
Comment thread fact/src/bpf/mod.rs
.load(fact_ebpf::EBPF_OBJ)?;
let obj = Bpf::load_ebpf(&checks, bpf_config)?;

Bpf::validate_config(&obj, bpf_config);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is done with the return value from validate_config.

Comment thread fact/src/bpf/mod.rs
u => unimplemented!("{u:?}"),
}
}
self.links = self

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need self.links.clear()? I think we don't really need it, but it would be a bit safer to keep it.

        if self.links.is_empty() {
            self.attach_progs()?;
        }

This is the only place that attach_progs is used, and it is only called if self.links is empty and errors in attach_progs are handled. I think an error would result in self.links maintaining its value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants