Skip to content

go: expose rulesets, passwd/group lookups and sock established - #386

Closed
nicholasberlin wants to merge 1 commit into
mainfrom
go-ruleset-lookups
Closed

go: expose rulesets, passwd/group lookups and sock established#386
nicholasberlin wants to merge 1 commit into
mainfrom
go-ruleset-lookups

Conversation

@nicholasberlin

Copy link
Copy Markdown
Contributor

Closes the three gaps Go consumers are currently working around:

  • Rule DSL: QueueAttr.RuleText installs a ruleset on the queue. It's parsed with quark_ruleset_parse() inside OpenQueue() — before any privileged operation, so parse errors surface without root — via an fmemopen shim borrowed from quark-test's ruleset_from_string1(). The C ruleset is owned by the Queue and released on Close() (the queue only borrows the pointer). Processes matched by poison rules carry the tag in the new Process.PoisonTag (set unconditionally, zero = no match, same semantics as quark_process.poison_tag). Until now the DSL — including file.exec_change — was unusable from Go.
  • User/group names: PasswdLookup() and GroupLookup() mirror quark_passwd_lookup(3) and quark_group_lookup(3). The otel quark receiver currently skips user.name/group.name in its ECS output with a comment noting the binding doesn't exist.
  • QUARK_EV_SOCK_CONN_ESTABLISHED: the only event bit missing from the bindings (..._CLOSED was there); the otel receiver hand-rolls uint64(1) << 5 today.

Tests: TestRuleText covers parse success/failure without root; TestQuark gains PasswdGroupLookup (uid/gid 0 resolve to root, unknown ids miss) and RulePoison, a Go port of t_rule_poison (poison children by ppid, pass only poisoned, drop the rest — every surviving event must carry the tag). RulePoison uses /bin/true rather than /bin/echo so it also runs in the initramfs VM.

Verified: full Go suite passes as root on real hardware (sudo ./quark-go-test -test.v, all 7 TestQuark subtests + TestRuleText); the new subtests also pass under krun with an initramfs augmented with glibc and /etc/passwd. go vet and gofmt clean.

Next tier of exposure candidates (entity_id, change_mask, taints, id_change, packet payload) deliberately left out to keep this reviewable; container metadata is already in flight in #373/#380–383.

Close the gaps Go consumers are currently working around:

- QueueAttr.RuleText installs a ruleset on the queue: parsed with
  quark_ruleset_parse() inside OpenQueue(), before any privileged
  operation, owned by the Queue and released on Close(). Processes
  matched by poison rules carry the tag in the new Process.PoisonTag.
- PasswdLookup() and GroupLookup() mirror quark_passwd_lookup(3) and
  quark_group_lookup(3), so ECS-style consumers can resolve user and
  group names instead of skipping them.
- QUARK_EV_SOCK_CONN_ESTABLISHED was the only event bit missing from
  the bindings; downstream hand-rolled the constant.

TestRuleText checks parsing without root, TestQuark gains
PasswdGroupLookup and RulePoison, the latter mirroring t_rule_poison.
All Go tests pass as root, the full suite is unchanged.
@nicholasberlin

Copy link
Copy Markdown
Contributor Author

Superseded by single-concern PRs, one per concern:

The code in those PRs is identical to this one.

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.

1 participant