Skip to content

Preliminary Rule System#283

Merged
haesbaert merged 3 commits into
mainfrom
rules
Nov 21, 2025
Merged

Preliminary Rule System#283
haesbaert merged 3 commits into
mainfrom
rules

Conversation

@haesbaert
Copy link
Copy Markdown
Collaborator

@haesbaert haesbaert commented Nov 20, 2025

This implements the barebones of a rule system for filtering events.

A ruleset is a collection of rules.
A rule has zero or more rule_fields. Each rule_field expresses one attribute
that must match, for example process.pid is one field, and file.path is another.
A rule matches when _all_ its fields match.
A rule with no fields always matches (can be a catch-all as the last rule).
A ruleset matches the first rule it matches, meaning this is a match-first scheme.

Currently we have only two actions RA_PASS and RA_DROP, if nothinig matches,
it's PASS.
For now, only 4 rule_fields, process.pid, process.ppid, process.filename and
file.path.

The next step is to design a proper DSL ala pf.conf(5), that then compiles an
ascii line-based ruleset into a quark_ruleset.

Note that two minor changes were piggy backed in different commits (gc_collect + re-align)

We garbage collect things after 4 seconds, this is to allow lookups from the
user to still work.

Previously we were garbage collecting after the cycle, meaning we could
theoretically end up doing a lookup for a quark_process
mid-quark_queue_get_event(), then stash it into qev->process, and then free the
memory in gc_collect(). This would be very unlikely since we would need an event
that references the soon-to-be-collected process to arrive 4 seconds later.

Give me back my sleep, make it impossible by collecting everything before we
have a chance of referencing it.
I don't love this, the problem is that const and quark_ makes our function
prototypes too long, try to improve things a little.
@haesbaert haesbaert requested a review from a team as a code owner November 20, 2025 22:05
@haesbaert haesbaert force-pushed the rules branch 3 times, most recently from 845ed44 to b101612 Compare November 21, 2025 11:02
@haesbaert
Copy link
Copy Markdown
Collaborator Author

I've added simple * matching in pathnames, once I profile this and realize it's good enough, I'll switch to fnmatch(3) and see if it's still good enough, than we can have "full" glob matching.

Copy link
Copy Markdown
Contributor

@nicholasberlin nicholasberlin left a comment

Choose a reason for hiding this comment

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

Nice.

Comment thread quark.c
Comment thread quark.c
Comment thread quark.c Outdated
This implements the barebones of a rule system for filtering events.

A ruleset is a collection of rules.
A rule has zero or more rule_fields. Each rule_field expresses one attribute
that must match, for example process.pid is one field, and file.path is another.
A rule matches when _all_ its fields match.
A rule with no fields always matches (can be a catch-all as the last rule).
A ruleset matches the first rule it matches, meaning this is a match-first scheme.

Currently we have only two actions RA_PASS and RA_DROP, if nothinig matches,
it's PASS.
For now, only 4 rule_fields, process.pid, process.ppid, process.filename and
file.path.

The next step is to design a proper DSL ala pf.conf(5), that then compiles an
ascii line-based ruleset into a quark_ruleset.

Co-authored-by: Nicholas Berlin <56366649+nicholasberlin@users.noreply.github.com>
@haesbaert haesbaert merged commit 058423c into main Nov 21, 2025
2 checks passed
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.

2 participants