Skip to content

feat(cel): expose the executed file as event.file - #1065

Merged
matthyx merged 1 commit into
mainfrom
feat/cel-exec-file
Nov 2, 2026
Merged

matthyx merged 1 commit into
mainfrom
feat/cel-exec-file

Conversation

@matthyx

@matthyx matthyx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Expose the file the kernel executed as the CEL field event.file. With Inspektor Gadget v0.57 (#1062), rules have no field that holds a shebang script's path: exepath is the interpreter and argv[0] is the interpreter as written in the shebang. trace_exec already emits file (d_path(bprm->file)), and #1062 uses it for alert paths; this makes it available to rules.

Overview

Exec event.file event.exepath event.args[0]
ELF /bin/ls /usr/bin/ls /usr/bin/ls ls
Shebang /run/x.pid (#!/bin/sh) /run/x.pid /usr/bin/dash /bin/sh
  • pkg/utils/cel.go: a new file string field with IsSet: presenceOf("file"), so has(event.file) reports whether the gadget emits it, as for ttyMajor.
  • pkg/utils/struct_event.go: FieldPresent("file") is true when File is non-empty (ptrace and test events).
  • docs/features/exec-file-cel-field.md: the field, how it differs from exepath, the (event.file != "" ? event.file : event.exepath) fallback, and the version gate.

First user: armosec R1161 (execution of runtime-state files such as /run/*.pid). Its shebang legs matched argv[0], which is now the interpreter. The team agreed to move it to event.file, gated with agentVersionRequirement at the first release that includes this. Older agents don't register the field, so an ungated rule would fail to compile there; the rules watcher skips gated rules before compiling them.

How to Test

  • go test ./pkg/rulemanager/cel/ ./pkg/utils/: pass. TestCELExecFile covers:
    • a shebang StructEvent: file is the script while exepath is the interpreter;
    • a missing file (has() is false, and the fallback picks exepath);
    • a synthetic exec datasource with and without the gadget's file field.
  • The test fails if the field is not registered: I checked by renaming the field, which makes the expression fail to compile.
  • go vet is clean.

Related issues/PRs:

🤖 Generated with Claude Code

AI-skills: oh-my-claudecode:plan,oh-my-claudecode:ralph,notify,armosec-shared-rules:open_pr | cmds: /oh-my-claudecode:deep-interview,/gh-review

Summary by CodeRabbit

  • New Features
    • CEL rules can now reference event.file to identify the file associated with an exec event. The field is available when provided by the event source; otherwise, rules can fall back to event.exepath. Rules using this field are skipped on agents that do not meet the required version.
  • Documentation
    • Added guidance on how event.file differs from event.exepath and event.args[0], when it is present, and how to handle events where it is empty.

trace_exec v0.57 emits file, d_path(bprm->file): the file the kernel
executed. For a shebang script it is the script, while exepath is the
interpreter and argv[0] is the interpreter as written in the shebang, so
no existing CEL field gives rules the script path. Register it as
event.file with presence tracking, so has(event.file) reports whether
the gadget emits it. Rules use it with an exepath fallback and an agent
version gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx matthyx added the ai-assisted Created through Armosec AI tooling (armosec-shared-rules plugin) label Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 44ba8491-a069-49c2-8435-cc4b7c657adb
Commits

Reviewing files that changed from the base of the PR and between 0ad6adb and e38bf4f.

Files selected for processing: 4
  • docs/features/exec-file-cel-field.md
  • pkg/rulemanager/cel/cel_file_test.go
  • pkg/utils/cel.go
  • pkg/utils/struct_event.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change adds event.file to CEL fields for exec events, defines when the field is present, and adds tests and documentation for its behavior, including shebang events, missing values, and fallback to event.exepath.

Changes: Exec file CEL field

Layer / File(s) Summary
Register and validate event.file
pkg/utils/cel.go, pkg/utils/struct_event.go, pkg/rulemanager/cel/cel_file_test.go, docs/features/exec-file-cel-field.md
CEL reads the exec file path, and StructEvent reports the field present when its value is non-empty. Tests and documentation cover shebang events, missing fields, fallback expressions, and agent version requirements.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related issues

Possibly related PRs

Suggested reviewers: slashben

Merge Risk: Minimal · up to e38bf

No actionable merge-blocking issue is identified for event.file. The change appears ready to merge subject to normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: exposing the executed file as the CEL field event.file.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change exposing the executed file path as event.file in CEL rules.

No open issues 🎉

What changed in this PR

Exposes the executed file path as event.file in CEL rules, allowing rules to distinguish shebang scripts from their interpreters following the Inspektor Gadget v0.57 upgrade.

Changes:

  • Registers event.file with presence detection for datasource and struct-backed events.
  • Adds tests for shebang paths, missing fields, and fallback behavior.
  • Documents field semantics, fallback expressions, and agent-version gating.
File Description
pkg/​utils/​struct_event.go Reports file as present when non-empty.
pkg/​utils/​cel.go Registers the CEL string field and its presence check.
pkg/​rulemanager/​cel/​cel_file_test.go Tests path access, presence detection, and fallbacks.
docs/​features/​exec-file-cel-field.md Explains field usage and version requirements.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.035 0.037 +7.1%
Peak CPU (cores) 0.040 0.040 +1.4%
Peak CPU p95 (cores) 0.039 0.040 +3.2%
Avg Memory (MiB) 269.308 185.135 -31.3%
Peak Memory (MiB) 273.340 188.934 -30.9%
Dedup Effectiveness

No data available.

@matthyx matthyx added the release Create release label Nov 2, 2026
@matthyx matthyx moved this to WIP in KS PRs tracking Nov 2, 2026
@matthyx
matthyx merged commit bf3d50a into main Nov 2, 2026
40 checks passed
@matthyx matthyx moved this from WIP to To Archive in KS PRs tracking Nov 2, 2026
matthyx added a commit to kubescape/rulelibrary that referenced this pull request Nov 5, 2026
Since Inspektor Gadget v0.57, event.args is the real argv, and argv[0]
is chosen by the caller: for a shebang script it's the interpreter, and
exec -a sets it to anything. So R1000 missed shebang scripts in
/dev/shm and fired on a spoofed argv[0].

The third leg now checks event.file, the file the kernel executed
(kubescape/node-agent#1065). The message and uniqueId report event.file,
falling back to exepath when it's empty.

event.file only exists from node-agent v0.3.307 and private-node-agent
v0.0.598, and older agents would fail to compile the rule. It's gated
with agentVersionRequirement ">=0.0.598, <0.1.0 || >=0.3.307": one
constraint covering both version lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Docs-exempt: rule docs are in pkg/rules/r1000-exec-from-malicious-source/README.md, updated here
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit to kubescape/rulelibrary that referenced this pull request Nov 5, 2026
Since Inspektor Gadget v0.57, event.args is the real argv, and argv[0]
is chosen by the caller: for a shebang script it's the interpreter, and
exec -a sets it to anything. So R1000 missed shebang scripts in
/dev/shm and fired on a spoofed argv[0].

The third leg now checks event.file, the file the kernel executed
(kubescape/node-agent#1065). The message and uniqueId report event.file,
falling back to exepath when it's empty.

event.file only exists from node-agent v0.3.307, and older agents would
fail to compile the rule, so it's gated with agentVersionRequirement
">=0.3.307".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Docs-exempt: rule docs are in pkg/rules/r1000-exec-from-malicious-source/README.md, updated here
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit to kubescape/rulelibrary that referenced this pull request Nov 5, 2026
…54)

Since Inspektor Gadget v0.57, event.args is the real argv, and argv[0]
is chosen by the caller: for a shebang script it's the interpreter, and
exec -a sets it to anything. So R1000 missed shebang scripts in
/dev/shm and fired on a spoofed argv[0].

The third leg now checks event.file, the file the kernel executed
(kubescape/node-agent#1065). The message and uniqueId report event.file,
falling back to exepath when it's empty.

event.file only exists from node-agent v0.3.307, and older agents would
fail to compile the rule, so it's gated with agentVersionRequirement
">=0.3.307".



Docs-exempt: rule docs are in pkg/rules/r1000-exec-from-malicious-source/README.md, updated here

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Created through Armosec AI tooling (armosec-shared-rules plugin) release Create release

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

2 participants