feat(python): ergonomic layer — read_path + 4 presets + dedicated docs page#54
Open
dzerik wants to merge 12 commits into
Open
feat(python): ergonomic layer — read_path + 4 presets + dedicated docs page#54dzerik wants to merge 12 commits into
dzerik wants to merge 12 commits into
Conversation
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.
Third and final PR of RFC #43. Builds on the already-merged C ABI (#44) and
Python wrapper (#46) — no C ABI or Rust core changes, Python and docs
only.
The minimal audit recipe now fits in five lines:
What's added
HandlerCtx.read_path(arg=None, max_len=4096) -> str | None— resolves apath-bearing syscall argument. With
arg=None(default), the path-argumentindex is inferred from
ctx.syscall_nrvia a name-keyed table. Multi-pathsyscalls (
renameat2,rename,linkat,link,symlinkat,symlink)and unknown syscalls raise
ValueError— passarg=explicitly in thosecases. Architecture-agnostic: the table is keyed by name and resolved at
first use via
sandlock_syscall_nr()from the C ABI.sandlock.presets— new module, imported explicitly (root surface staysminimal):
COMMON_PATH_SYSCALLS— the nine modern path-bearing syscalls a genericfile-operation handler is typically registered against.
AuditPathsHandler(callback, max_len=4096)—on_exception=CONTINUE,calls
callback(path, ctx)on every intercepted syscall and returnsContinue.PathDenyHandler(deny: list[str], errno=EPERM, max_len=4096)—on_exception=KILL, fnmatch patterns;path is None → continue_()(adeny-list does not claim "everything else is allowed").
PathAllowListHandler(allow: list[str], errno=EACCES, max_len=4096)—on_exception=KILL, fnmatch patterns;path is None → errno()(anallow-list fails closed when the path cannot be classified).
LogSyscallsHandler(logger=None)—on_exception=CONTINUE, defaultlogger is
logging.getLogger("sandlock.audit").info.The deliberate asymmetry between
PathDenyHandlerandPathAllowListHandleronpath is Noneis documented in both class-leveldocstrings and in the doc page — each class explains the security rationale.
docs/python-handlers.md— new page, single source of truth for thePython wrapper. The Python section in
docs/extension-handlers.mdisreduced to a one-line pointer; the Threading & safety and Ownership rules
subsections are moved verbatim. The Rust/C ABI sections in
extension-handlers.mdare untouched.Out of scope (by RFC #43)
read_path(arg=...)— callersspell the two args themselves.
COMMON_PATH_SYSCALLS+ list comprehension isenough.
read_buf) — added if a concreteneed appears.
Test plan
PR 3.
python3 -c "..."child opens a unique probe file 3 times, theAuditPathsHandlercallback observes exactly 3 matching paths.LogSyscallsHandleragainst the live trampoline.class-level claim (e.g.
on_exception=KILLfor security handlers,path is Noneasymmetry, defaulterrno, customerrno), a singlemutation of the production code makes the corresponding test fail.
sandlock_syscall_nr()rather than a hard-coded constant.Commit organization
Seven feature commits (read_path, four presets in order, e2e test, docs)
plus five polish commits addressing the deep self-review:
Closes the RFC #43 three-PR chain.