Skip to content

feat(sandboxpolicy): enforce the file and identity sections and export section verdicts - #1075

Open
AlonLiwsky wants to merge 179 commits into
kubescape:feat/sandbox-policy-network-gadgetfrom
AlonLiwsky:feat/sandbox-policy-file-gadget
Open

AlonLiwsky wants to merge 179 commits into
kubescape:feat/sandbox-policy-network-gadgetfrom
AlonLiwsky:feat/sandbox-policy-file-gadget

Conversation

@AlonLiwsky

@AlonLiwsky AlonLiwsky commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

This enforces the file section of SandboxPolicy with a new portable BPF LSM gadget, built the same way as the privilege and network gadgets: one node-wide instance, a cgroup → policy-slot bindings map, and the policy as frozen map data. Binding changes apply live (no pod restart); a policy change replaces the instance with overlap.

Stacked on #1073: the base is #1073's branch, so the diff shows only this PR. Merge after #1073.

Production code is about 3,800 lines: 2,800 in the gadget (BPF program and header, compiler, runtime), 1,000 in node-agent. Tests are about 3,600 lines.

1. The gadget — pkg/ebpf/gadgets/enforce_file/ (portable, no node-agent or Kubernetes concepts)

  • Hooks per access kind:

    • read / write: lsm/file_open (by f_mode; O_TRUNC is write), path_truncate
    • create: path_mknod (covers open(O_CREAT), openat2, io_uring), path_mkdir, path_symlink, path_link
    • delete: path_unlink, path_rmdir
    • rename: path_rename (both names)
    • chmod: path_chmod, path_chown, and inode_setxattr / inode_set_acl for file capabilities and POSIX ACLs (setcap, setfacl). These two hooks have no mount, so they are judged only on the task's root filesystem; elsewhere they fail closed.
    • A create is denied at path_mknod, not at file_open. A deny at file_open would leave an empty file.
  • Paths: bpf_d_path where the kernel allows it. path_mknod uses a bounded dentry walk, because bpf_d_path is refused there and bpf_path_d_path does not exist on 6.8. No kfunc is needed, so 6.8 and 6.12 run the same program.

  • Matching: a component-level shift-and NFA. There is one hash lookup per path component, against frozen per-slot bit masks. Globs: literal, * (one component), ** (any depth), and one * inside a component (cron*, *.sock, rc*.d). That covers every default path class in the CRD design. The hash is FNV-1a with a random seed per instance. A Go simulator runs the same step function, and a C harness checks that the real header agrees with it.

  • Moves: a link or rename source (and both names of RENAME_EXCHANGE) is judged for rename, read and write with the full decision. A new name is judged as create and write (or write and delete when it replaces a file). Renaming a parent directory of a protected path is denied at both ends. So ln /root/.aws/credentials /tmp/x, mv /root/.aws /tmp and mv /tmp/dir /root/.aws don't get around a rule.

  • fromImage: an overlay file with a lower-layer origin (ovl_entry has a lower stack). A copy-up by write, chmod, touch or setxattr does not change it. The runtime checks the private ovl_inode layout in the kernel BTF; if it differs, fromImage rules are reported as not enforced instead of reading a wrong field.

  • Overlay: each overlay open calls file_open twice. The second call is the backing file on an internal mount. The gadget skips it, because a deny there breaks copy-up.

  • Runtime work: the shared arming rule (common/arming.h) keeps runc init, kubectl exec setup and probes out until the workload's exec. Without it, a write default deny breaks docker exec and healthchecks (oom_score_adj).

  • Fail closed: a path the gadget can't resolve (too long, walk too deep, a task whose root is not its mount root after a chroot) gets the most limiting verdict of its access kind (unresolved-path).

  • Merge of several policies follows common/merge/CONTRACT.md per access kind and passes its shared vectors.

  • Cost for unbound containers: file_open is a hot path on every container of the node. The gadget checks the internal mount first and reads the cgroup level with plain loads (BINDINGS_DIRECT_LEVEL, opt-in in common/bindings.h; network and privilege don't change). Program time per open (bpf_stats), measured in the lab on arm64:

    unbound, cgroup depth 2 unbound, depth 4 bound, 51 rules
    6.12 80 ns 91 ns 362–366 ns
    6.8 81 ns 104 ns 440–446 ns

    On 6.8 the first program on file_open also adds about 250 ns of trampoline cost to every open on the node, when no other LSM program uses that hook.

2. The node-agent layer — pkg/sandboxpolicy/

  • The section splitter routes file to a new backend on the generic node owner. compiler.go no longer rejects the file and identity sections.
  • Translator (file.go): per-access defaults (defaultByAccess, or the old object form of default), their modes and origins, rules with access, path, pathClass, fromImage, and except on deny rules.
  • Path classes: the default classes from the CRD design (credentialStore, sshKeys, cloudConfig, shellRc, agentConfig, persistence, packageStore, containerRuntimeSocket, hostDevices), plus SandboxPolicyClasses, plus the policy's own classes.
  • Symlinked paths: the kernel sees resolved paths. So a /var/run/... pattern also gets /run/...; a pattern that ends in a file name also matches the kubelet atomic-writer form dir/..*/file (Secret, ConfigMap and projected volumes); and deny rules on /bin, /sbin, /lib, /lib64 also cover /usr/... (merged-usr images). Without this, the service-account token in credentialStore never matches.
  • Unresolved classes degrade as the design says: a deny rule goes to audit; an allow rule moves the defaults of its access kinds to audit, with Ready=False / ClassUnresolved. As in network, an audit-degraded deny keeps no paths, so it can't weaken its own policy's enforce default. An allow rule the gadget can't enforce does the same, with Ready=False / RuleNotEnforceable.
  • Built-in allows for runtime devices (/dev/null, /dev/zero, /dev/tty, /dev/pts/**, ...) and /dev/shm/**. Identical allow rules from several policies merge, so they don't count twice against the slot limit.
  • Reported as not enforced, with a reason (condition FileNotEnforced): execMap, fsType, actor on file rules, patterns the gadget can't express (?, [...], two * in one component).
  • The engine passes the runtime's mount namespace to the gadget (host-mntns-id), like privilege. Without it, runc init is judged on kind and kubectl exec fails.
  • Config key sandboxPolicyFileImage (default empty: the section reports FileNotConfigured).
  • Small refactor: the except splitting of the local mirror moved to a shared helper, used by network and file.

3. Identity section

  • identity is a readability section, as the CRD design says: the translator expands it into file and network rules. No new gadget.
  • Credential paths and pathClass (credentialStore, sshKeys, cloudConfig, agentConfig) become file read rules. A provisioned path that a deny class also covers (the service-account token) is subtracted from the class, so an identity allow is not cancelled by the deny.
  • imds: true becomes a network rule on the imds class.
  • envRead: true becomes a file read rule on /**/environ with a new gadget rule flag, otherProcess: it matches only the environ file of another process. A process can still read its own environment.
  • Verified on 6.8 and 6.17: another process's /proc/<pid>/environ (also through a second procfs mount) is denied, the task's own is allowed, cmdline and status stay readable. In kind (6.8): the CRD design's identity example denies credential reads and IMDS with the right rule and origin, and keeps the service-account token readable. No measurable cost change.

4. Start gap

  • Before, a container's first command ran before its own file binding existed. Now the file section also binds the pod cgroup before the containers start, like privilege and network: the pod plan keeps the file section when every container of the pod gets the same file policies.
  • The pod binding skips the arming, so the pause container, runc init and OCI hooks are not judged; the workload's first exec arms it. The file backend also starts an empty instance early, so the first pod finds the gadget loaded.

How to Test

  • go test ./pkg/ebpf/gadgets/... ./pkg/sandboxpolicy/...

  • Kernel test, as root on a Linux host with BPF LSM: go test -tags file_kernel ./pkg/ebpf/gadgets/enforce_file/runtime/ (see the README for the env vars). I ran it on 6.8 (Ubuntu 24.04) and 6.12 (Debian 13), arm64, at cgroup depth 2 and 4. It covers every access kind, the move guard at both ends, setfacl / setcap, fromImage after copy-up, chroot, audit, docker exec and healthchecks under a write default deny, and binding changes on a running task (bind after it opened files, moves to child cgroups and out, unbind, rebind).

  • In kind (Kubernetes 1.36, 6.8), live on running pods: write default deny with a workspace allow, credentialStore read deny including the projected service-account token, the hard-link and rename guard, fromImage, audit wouldDeny, unbind restoring access in about 3 s, kubectl exec and exec probes, ClassUnresolved and FileNotEnforced, two policies merged, an except entry, a Secret-volume file matched by **/.docker/config.json, setfacl / setcap under a chmod default deny, and one object with both network and file sections.

  • Start gap in kind (6.8), on a fresh node-agent with the policies applied first: the empty instance is loaded before any pod; a pod whose first command writes /etc is denied and still starts (also 5 pods in a burst, and an init container); an unselected pod is not affected; 0 runc verdicts. Replacing the instance for a new policy combination left no window for a running pod (about 1,150 writes tried, 0 got through).

  • Identity in kind (6.8): the CRD design's identity example in enforce mode denies credential reads and another process's /proc/1/environ, and allows the process's own environment and the service-account token.

Known limits

  • A pod whose containers get different file policies has no pod binding for file: there, a container's first command still runs before its own binding exists.
  • A hard link or bind mount that exists before the policy binds is a second name for the file. A path rule sees only the name used.
  • A bind mount made inside a new user + mount namespace renames paths. The privilege section's user-namespace deny closes this. A chroot into a mount root (for example a volume) is not detected either.
  • Renaming a parent of a floating pattern (a directory that contains .claude/) is not guarded.
  • In audit mode, an open(O_CREAT) of an existing file that is not in the dentry cache can log a false create wouldDeny. The kernel drops that error, so the open works and the enforce verdict is correct.
  • setcap, setfacl and cp -a with ACLs on a volume file (not the root filesystem) fail when the policy has any chmod deny. Removing an ACL is not judged. io_uring with registered credentials on a volume file is not judged for these two hooks.
  • Kernel issue, not caused by the gadget: on kernels without upstream fix 61df7b828204 (v6.11), the kernel skips cap_inode_setxattr whenever BPF LSM is active, so an unprivileged task can set security.* xattrs. I reproduced it on Ubuntu 6.8 with no BPF program loaded. Ubuntu 6.8 also refuses an LSM program that returns 1, so a program can't restore the check there. Where a load probe shows that the old convention works, the gadget returns the hook default when it allows.
  • On images where /lib and /usr/lib are separate directories (for example Alpine), a deny rule on /lib/** also covers /usr/lib/**, because of the merged-usr alias.
  • A Secret key with a subdirectory (items[].path: a/b/file) is not covered by the atomic-writer alias.
  • With overlay metacopy=on (not the containerd default) a data-only lower file is not tested.

Open questions

  1. execMap: not built (mmap_file / file_mprotect). The design marks it default-off because it breaks JITs. Is it needed in this ticket?

Tracking: SUB-9583.

Section verdict export (folded from #1080)

This also reports the privilege, network and file verdicts (enforced denies and audit wouldDeny) to the same receivers that exec authorizations use, so a private exporter (for example the OTLP mapping in armosec/private-node-agent#747) can pick them up. Until now these verdicts only went to the node-agent log.

Boundary (decided): the typed public section events and their queue stay here in node-agent. The private OTLP mapping lives in armosec/private-node-agent#747. Public event dispatch is not folded into the private exporter.

What changes

  • Typed section events (pkg/sandboxpolicy/section_verdict.go): one event per verdict for privilege, network and file, with its own dispatch key, the policy identity (kind, name, uid, generation, namespace) and revision, rule name, origins list, mode, wouldDeny, the target in policy words (for example read, not the C enum name) and the actor (process, container, pod).
  • Binding lookup: the event's cgroup is resolved to its container or pod binding, and the policy set comes from the judging instance's slot table (by generation and slot).
  • Own queue: section events have their own queue and worker and feed the same receivers. The exec exporter is unchanged (exporter.go is identical to feat(sandboxpolicy): enforce the file and identity sections and export section verdicts #1075), so a burst of section denies can never drop or delay an exec verdict. A test sends 1,000 section denies into a 4-entry section queue: 996 section events are dropped and counted, 0 exec verdicts.
  • Counters: kernel ring-buffer drops and section queue drops are exposed through Service.SectionVerdictStats() / SectionExporterStats(). A drop is never silent.
  • Debug receiver behind sandboxPolicyDebugExport (default off): logs one line per exported event, for local testing.
  • One verdict is one kernel check, not one syscall (an audited setns on a mount namespace gives two). The exporter does not dedupe; the doc says so.

Production code is about 950 lines (the section exporter ~150, the debug receiver ~70, the subscriber rewrite), tests about 820, docs about 35.

How to test

  • go test ./pkg/sandboxpolicy/...
  • Kernel export test on 6.8 and 6.17 (arm64): one enforced deny and one audit wouldDeny per section reach a test receiver with binding, policy identity, rule, origins, target and counters.
  • Local kind end-to-end run with the debug receiver on: every one of the 175 denied or audited actions produced its event with the right wouldDeny, rule and pod binding; for a pod with two policies, the event names the deciding policy and both in the set.

Follow-up (not in this PR)

The backend accepts only exec verdicts today. Privilege, network and file need backend changes (rule family per section with an authorization phase, a phase guard on the R-NET-1 / R-FILE-1 observation views, section defaults, target keys), plus the authorization-versus-observation mapping in the private exporter. That is a separate stacked change, not a blocker for this public typed-event PR.

Tracking: SUB-9591.

Add common/root_barrier.h: BPF LSM programs that always deny chroot,
pivot_root, new user namespaces, clone/clone3/unshare with CLONE_NEWNS,
setns into a mount or user namespace (or type 0), and mount-tree changes
for the tasks a gadget-defined predicate covers. Thread creation and setns
into other namespace types stay allowed.

Add common/rootbarrier: attestation that each barrier program has a live
LSM link and that BPF LSM is active, plus a self-test of real denials, for
the Ready step of a gadget that includes the barrier.

Add the root_barrier gadget, which uses the barrier alone with the
enforce_exec bindings shape, and an opt-in kernel test with Inspektor
Gadget alone.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
- Cover child cgroups in the root_barrier gadget (a task can move into a
  child cgroup, and clone3 can start a child in one) and state the
  requirement for gadget-defined predicates.
- Deny fsconfig with the other new mount API syscalls.
- Detect arm64 compat tasks from the saved pstate, not a TIF bit.
- Self-test: match the probe thread in its own PID namespace, prove each
  denial through a per-operation bit in the probe entry instead of the
  shared counter, send no event for probe denials, retry the probe clear,
  and explain a disabled user namespace limit.
- Kernel test: child cgroup, setns type 0, open_tree clone.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
- Record a probe denial before the covered-task branch, so a probe
  thread that the predicate also covers still proves the denial.
- Walk covered cgroups from the top of the hierarchy, so a task at any
  depth below a covered cgroup matches.
- Refuse to cover the root cgroup.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…ot-barrier

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Translate the file section of a policy into the enforce_file document and
drive one node-wide file gadget instance, like the network section.

- file.go: FilePlan and FileReport, a local mirror of defaultByAccess,
  defaultMode(ByAccess), defaultOrigin(ByAccess) and except, path classes
  (built-in, shared, policy-local), the class-unresolved degradation, the
  built-in runtime-devices allow rule, and not-enforced reporting (execMap,
  fsType, fromImage false, globs the gadget cannot match).
- The compiler accepts the file section; identity stays rejected.
- Controller, status (FileNotEnforced, combined compiled counts and
  degraded list), section backend (FileNotConfigured, WithFile).
- igbackend: FileBackend on the node owner, availability = BPF LSM. The
  native engine waits for the file runtime package (build tag
  file_runtime).
- Config key sandboxPolicyFileImage (default empty).

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Path rules for read, write, create, delete, rename and chmod with per-access
defaults, deny exceptions and an image-file (fromImage) condition.

- policy: pattern language (literal, *, **, pre*suf), per-slot compiler with
  the shared merge contract per access kind, segment bits with pattern dedup,
  guard of deny rules for move sources, literal hash table, glob table and a
  random hash seed per slot.
- file_policy.h: shift-and matcher over path components and the decision;
  a native harness test runs it against the Go simulator.
- program.bpf.c: file_open, path_truncate/chmod/chown/mknod/mkdir/symlink/
  link/unlink/rmdir/rename; overlay internal opens skipped; dentry walk for
  path_mknod and the hard link old name; unresolved paths fail closed;
  arming as in enforce_privilege.
- runtime: enforce-file operator (slots and frozen literal map, arming maps)
  and an opt-in kernel test.
- Registered in the portability test, the library README and the gadget list.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
The file engine started enforce_file without operator.oci.ebpf.host-mntns-id,
so the gadget armed tasks against the init task's mount namespace. Where the
container runtime runs in another mount namespace (kind), runc init was armed
and judged: under a write default deny, kubectl exec and exec probes failed on
runc's write to /proc/self/oom_score_adj. Pass the same value as the privilege
engine.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…ot-barrier

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
… after copy-up, fail closed in a chroot

- A move source (old name of a rename or a hard link, both names of
  RENAME_EXCHANGE) is judged as rename, read and write with the full
  decision (rules, except, fromImage, defaults, merge rule 5). The guard
  is now only the parent directories in the patterns of deny rules of
  read or write; a chmod or delete deny no longer blocks every rename.
  Both names of RENAME_EXCHANGE are also judged as write and delete.
- fromImage means the overlay file has a lower-layer origin
  (ovl_entry.__numlower > 0), so a copy-up by touch, setxattr, chmod or
  an allowed write keeps it. The runtime checks the ovl_inode and
  ovl_entry layout in the kernel's BTF and sets FILE_SLOT_FROM_IMAGE
  only when it holds (6.8 and 6.12 do); otherwise no file is an image
  file.
- A task whose root is not the root of its mount (chroot to a
  directory) gets every path judged as unresolved.
- The compiler merges identical allow rules across the documents of a
  slot, so the owner's built-in rules count once.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
… file section

- Every file glob also gets the names the kernel shows for the file: a
  /var/run/... pattern also as /run/..., and an exact file /dir/file
  also as /dir/..*/file (kubelet atomic-writer volumes, such as the
  service account token). Deny and allow rules and except entries.
- A second built-in allow rule, runtime-shm: read, write, create and
  delete in /dev/shm/**.
- A fromImage rule is reported as not enforced when the file gadget
  cannot read this node's overlay inode layout.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Check overlayfs' internal backing open before the binding lookup, so the
second file_open call of every overlay open no longer walks the cgroup
parents. Read f_path.mnt directly and mnt_ns with one kernel read.

bindings.h gets an opt-in BINDINGS_DIRECT_LEVEL: the cgroup level is read
with plain loads, and only when the task's own cgroup is not bound. Gadgets
that do not define it are unchanged.

Program time per unbound open, 6.8 and 6.12: 118-151 -> 75-78 ns at cgroup
level 2, 154-183 -> 100-102 ns at level 4.

Add TestGadgetBindingChanges: a task that already opened files is enforced
right after a bind, stays enforced when it moves into child cgroups of the
bound container, is free outside it and after unbind.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

# Conflicts:
#	pkg/ebpf/gadgets/enforce_file/program.bpf.c
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
… names

- inode_setxattr (security.capability, POSIX ACL names) and inode_set_acl are judged as chmod. A dentry on the task's root super block is walked to the root; overlayfs' inner call on the upper file system (mounter credentials) is skipped; any other dentry is an unresolved path.
- New names of a rename, hard link or symbolic link (both names of RENAME_EXCHANGE) are judged against a new-name guard: the parents written in deny rules of write or create.
- A new name that does not exist yet (rename, hard link) is judged as create and write.
- The event path is dropped when another task wrote the per-CPU event path meanwhile.
- Remove dead code (guard any_path, a bound check the verifier does not need).

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…ded deny, not-enforceable allow

- The atomic-writer alias (..* before the last segment) applies to every glob whose last two segments are not **, so **/.docker/config.json also matches a Secret volume file. Deny rules also get the /usr form of /bin, /sbin, /lib and /lib64 globs.
- A deny rule degraded by an unresolved class keeps no path, as in the network translator, so it cannot hide its own policy's enforce default deny.
- An allow rule the gadget cannot enforce makes the policy not ready (RuleNotEnforceable).

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…op dead ACL names

Before Linux 6.11 (61df7b828204) security_inode_setxattr runs
cap_inode_setxattr only when the inode_setxattr hooks return 1. The owner
now probes the kernel (no bpf_lsm_inode_xattr_skipcap in BTF, and an
inode_setxattr program that returns 1 loads) and sets the new
setxattr-allow-one parameter; the program then returns 1 on an allow.
On 6.11+ and on kernels with the LSM return range check (6.12, Ubuntu
6.8) it stays 0, so the verifier never sees a return of 1.

POSIX ACLs go to inode_set_acl on every supported kernel (6.2+), so
inode_setxattr judges only security.capability.

Kernel test: unprivileged security.test setxattr (bound container,
unbound container, host uid 65534) is EPERM where the kernel can keep
the check; skipped with the reason where it cannot.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
A write to /bin/sh is judged on /usr/bin/sh. The deny already had the
/usr form; the except now has it too, so 'deny write /bin/**' except
/bin/sh keeps /bin/sh writable. README known limits: the alias also
widens a deny on images that are not merged-usr (Alpine), and nested
Secret keys are not covered.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
A file section that does not translate also refuses the pod plan, like network.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…e_setxattr only before 6.9

PrepareScheduled lost the file section in the merge of the network branch.
From 6.9 IMA and EVM run after BPF LSM, so a return of 1 would skip them.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

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: 95177b2d-7d90-46da-ac5b-63e817ce73fb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@AlonLiwsky

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
@AlonLiwsky
AlonLiwsky force-pushed the feat/sandbox-policy-file-gadget branch from ee7bd76 to 44f5997 Compare November 4, 2026 20:37
Attach a BPF LSM program that denies chroot with EACCES after the
barrier (the trampoline runs the newest program first) and check that
chroot still fails with EACCES, not the barrier's EPERM.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…ch budget

The barrier adds one LSM link on each of its 8 hooks, and every
including gadget adds its own. The README gives the per-hook total for
the standalone gadget and N including gadgets, against 38 links per
trampoline (AL2023 6.12.113-138.209 and 6.18.56-125.164), at most 8 per
family and 8 reserved for third parties.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Bring the files the drift test compares to the fork head: root_barrier.h
reads the previous verdict as a signed 64-bit word (ROOT_BARRIER_PRIOR)
and the rb_* programs return long; Hook.ID and WithProgramID let
attestation match a program by its kernel ID; attest_linux.go matches
by ID when set. links_linux.go keeps its own name-and-map matcher, since
barrierHook now takes the LSM hook.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…Attest

The ported Attest matches a hook's program by its kernel ID when
Hook.ID is set, which is what CheckLinks did. Drop CheckLinks: Health
now runs rootbarrier.Attest with the hooks from ProgramIDs. ProgramIDs
stays for what the fork lacks: reading the IDs from the instance's
counter map when the gadget has no *ebpf.Program to pass to
WithProgramID (Inspektor Gadget does not expose LSM programs).

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…olicy-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

# Conflicts:
#	cmd/main.go
#	pkg/ebpf/gadgets/common/README.md
#	pkg/ebpf/gadgets/common/enforcement/bindings.go
#	pkg/sandboxpolicy/igbackend/nodeowner.go
#	pkg/sandboxpolicy/igbackend/privilege_native.go
#	pkg/sandboxpolicy/integration/service.go
#	pkg/sandboxpolicy/status.go
…-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

# Conflicts:
#	pkg/ebpf/gadgets/common/README.md
The file runtime now passes Config.FaultInjection to the binding
controller, like privilege: an instance with an arming test switch set is
refused unless a kernel test admits fault injection. The kernel fixture
gets startConfig with extra parameters, and TestTestSwitchesRefused checks
the refusal.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Every check of an armed task in a bound slot, and every fork of an armed
task in a bound cgroup (before the child's mark can fail), counts an
attempt in arming_attempts. A judgement an Audit binding loses (a
structural fault: missing slot policy, outside scope, missing scratch; or
a lost child mark) counts in arming_unevaluated. The runtime sets
AttemptsMap and UnevaluatedMap, so the owner's fail-closed rate covers the
file section. Kernel test: TestForkMarkFaultInjection.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
A failed exec mark left the task unarmed, and Strict then allowed every
access of it. ig_file_exec_check (bprm_check_security) now creates the
mark storage through arming_prepare_exec, where the exec can still fail:
a Strict binding refuses the exec with -ENOMEM and counts a slot fault;
an Audit binding runs it and counts an unevaluated judgement. ig_file_exec
(bprm_committed_creds) only sets the mark. The root barrier's task_alloc
body stays first in ig_file_alloc.

The arming-fail-exec-marks parameter (test only) is exposed, and
TestExecMarkFaultInjection checks both modes.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
runtime.Programs maps every LSM program of the gadget, the root barrier's
included, to its hook; a test keeps it equal to program.bpf.c and
BarrierHooks. The runtime sets Config.Programs, so Bindings.Attached
checks a live link per program, and the native file engine wraps its start
error with enforcement.AsAttachCapacity, so an E2BIG attach names the hook.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
The support claim is Linux 6.12 and later, where the kernel checks the
capability of security.* names before the hooks. Remove
setxattr_allow_one, its gadget parameter, the user-space probe
(runtime/setxattr.go) and its callers in the node engine and the kernel
tests. inode_setxattr keeps its normal judging and returns 0 on an allow.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
An unresolved class no longer degrades a rule to audit: a deny keeps its
resolved paths, an allow leaves the defaults, an unresolved except is
disabled, and each makes the policy not ready (ClassUnresolved). Only an
allow rule the gadget cannot enforce degrades its defaults to audit.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
file_slot_get treated a missing slot header as "not judged" and had no
caller in program.bpf.c. file_slot_header returns the header of a storage
index, or NULL when it holds none (generation 0), which a bound slot
treats as a structural fault. file_bound uses it, and the native matcher
harness now looks a slot up the same way (an unpublished slot prints
"unpublished", an off slot "off").

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…8089); compare it in the drift test

A hook that already has an ID keeps it; an unreadable map ID of a matching
program is an error.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

# Conflicts:
#	pkg/ebpf/gadgets/common/README.md
…olicy-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

# Conflicts:
#	Makefile
#	cmd/main.go
#	pkg/ebpf/gadgets/common/README.md
#	pkg/sandboxpolicy/integration/service.go
#	pkg/sandboxpolicy/status.go
#	pkg/utils/events.go
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…olicy-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…ce name

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…BTF digest

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
… file slots

Any barrier predicate fault makes the file policies Degraded for 60 s; with
no attempts of their own they never count toward NotReady; an unreadable
fault map is unknown.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…olicy-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Before 6.9, inode_setxattr gives 1 to mean "run the capability check";
since the return-1 path is gone, an allow (0) would skip it there.

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…olicy-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

# Conflicts:
#	pkg/sandboxpolicy/igbackend/rates.go
…-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…olicy-file-gadget

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
…et context

Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

2 participants