Repository navigation
feat(sandboxpolicy): enforce the file and identity sections and export section verdicts - #1075
Open
AlonLiwsky wants to merge 179 commits into
Open
AlonLiwsky wants to merge 179 commits into
AlonLiwsky wants to merge 179 commits into
Conversation
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>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Signed-off-by: Alon Liwsky <40373481+AlonLiwsky@users.noreply.github.com>
AlonLiwsky
force-pushed
the
feat/sandbox-policy-file-gadget
branch
from
November 4, 2026 20:37
ee7bd76 to
44f5997
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This enforces the
filesection 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:
lsm/file_open(byf_mode; O_TRUNC is write),path_truncatepath_mknod(coversopen(O_CREAT), openat2, io_uring),path_mkdir,path_symlink,path_linkpath_unlink,path_rmdirpath_rename(both names)path_chmod,path_chown, andinode_setxattr/inode_set_aclfor 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.path_mknod, not atfile_open. A deny atfile_openwould leave an empty file.Paths:
bpf_d_pathwhere the kernel allows it.path_mknoduses a bounded dentry walk, becausebpf_d_pathis refused there andbpf_path_d_pathdoes 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. Soln /root/.aws/credentials /tmp/x,mv /root/.aws /tmpandmv /tmp/dir /root/.awsdon't get around a rule.fromImage: an overlay file with a lower-layer origin (ovl_entryhas a lower stack). A copy-up by write, chmod, touch or setxattr does not change it. The runtime checks the privateovl_inodelayout in the kernel BTF; if it differs,fromImagerules are reported as not enforced instead of reading a wrong field.Overlay: each overlay open calls
file_opentwice. 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 execsetup and probes out until the workload's exec. Without it, a write default deny breaksdocker execand 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.mdper access kind and passes its shared vectors.Cost for unbound containers:
file_openis 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 incommon/bindings.h; network and privilege don't change). Program time per open (bpf_stats), measured in the lab on arm64:On 6.8 the first program on
file_openalso 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/fileto a new backend on the generic node owner.compiler.gono longer rejects thefileandidentitysections.file.go): per-access defaults (defaultByAccess, or the old object form ofdefault), their modes and origins, rules withaccess,path,pathClass,fromImage, andexcepton deny rules./var/run/...pattern also gets/run/...; a pattern that ends in a file name also matches the kubelet atomic-writer formdir/..*/file(Secret, ConfigMap and projected volumes); and deny rules on/bin,/sbin,/lib,/lib64also cover/usr/...(merged-usr images). Without this, the service-account token in credentialStore never matches./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.FileNotEnforced):execMap,fsType,actoron file rules, patterns the gadget can't express (?,[...], two*in one component).host-mntns-id), like privilege. Without it, runc init is judged on kind andkubectl execfails.sandboxPolicyFileImage(default empty: the section reportsFileNotConfigured).exceptsplitting of the local mirror moved to a shared helper, used by network and file.3. Identity section
identityis a readability section, as the CRD design says: the translator expands it intofileandnetworkrules. No new gadget.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: truebecomes a network rule on theimdsclass.envRead: truebecomes a file read rule on/**/environwith a new gadget rule flag,otherProcess: it matches only the environ file of another process. A process can still read its own environment./proc/<pid>/environ(also through a second procfs mount) is denied, the task's own is allowed,cmdlineandstatusstay 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
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,fromImageafter copy-up, chroot, audit,docker execand 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 execand exec probes, ClassUnresolved and FileNotEnforced, two policies merged, an except entry, a Secret-volume file matched by**/.docker/config.json,setfacl/setcapunder a chmod default deny, and one object with bothnetworkandfilesections.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
/etcis 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
chrootinto a mount root (for example a volume) is not detected either..claude/) is not guarded.open(O_CREAT)of an existing file that is not in the dentry cache can log a false createwouldDeny. The kernel drops that error, so the open works and the enforce verdict is correct.setcap,setfaclandcp -awith 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.cap_inode_setxattrwhenever BPF LSM is active, so an unprivileged task can setsecurity.*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./liband/usr/libare separate directories (for example Alpine), a deny rule on/lib/**also covers/usr/lib/**, because of the merged-usr alias.items[].path: a/b/file) is not covered by the atomic-writer alias.metacopy=on(not the containerd default) a data-only lower file is not tested.Open questions
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
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 exampleread, not the C enum name) and the actor (process, container, pod).exporter.gois 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.Service.SectionVerdictStats()/SectionExporterStats(). A drop is never silent.sandboxPolicyDebugExport(default off): logs one line per exported event, for local testing.setnson 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/...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.