Feature/landlock provider - #337
Draft
drscrewdriver wants to merge 7 commits into
Draft
Conversation
added 7 commits
July 29, 2026 21:25
- Add LandlockCodeExecutionResource with bundle/manifest/grant validation - Add LandlockExecutionResourceProvider conforming to 4.1.4.2 contract - provider_id=landlock, supported_kinds=(code_execution,) - Implements async_probe/async_ensure/async_health_check/async_release - Linux-only conditional import in __init__.py - Uses ctypes syscall wrappers for landlock_create_ruleset/add_rule/restrict_self - Fork-based isolation to handle irreversible landlock_restrict_self - Supports ABI version auto-detection and configurable read/write dirs
- Landlock ABI 版本检测 - 文件系统写隔离:非白名单路径写入被阻止 - 文件系统读隔离:非白名单文件读取被阻止 - 不可逆性验证:fork 后父进程不受影响 注意:Landlock enforcement 依赖内核配置,某些环境可能不生效
关键修复: - restrict_self 前必须调用 prctl(PR_SET_NO_NEW_PRIVS) - 使用 preexec_fn 在子进程中应用 Landlock 限制 - 移除 placeholder 注释,实现真正的文件系统隔离 验证结果 (ABI v8): - WRITE /tmp: BLOCKED - READ /etc/passwd: BLOCKED - EXEC /bin/echo: BLOCKED - CREATE /tmp/file: BLOCKED - READDIR /usr: ALLOWED (whitelisted) - MKDIR /tmp: BLOCKED - REMOVE /tmp/file: BLOCKED - SYMLINK /tmp: BLOCKED - TRUNCATE /tmp/file: BLOCKED - NETWORK: 不受 Landlock 控制
P0 (必须修复): - _apply_landlock 静默失败 → os._exit(125/126/127) 显式报错 父进程检测 exit code 并在 stderr 中输出诊断信息 - 默认无法执行命令 → 自动注入 _BASE_READ_DIRS (/usr, /lib, /lib64, /dev/null, /dev/urandom 等) 同时自动注入 cwd 为只读路径 P1 (应该修复): - 路径逃逸校验: __init__ 中 Path.resolve() 防止 ../ 和 symlink 泄露 - /tmp 可选写入: async_ensure 自动创建 tempfile.mkdtemp() 作为可写目录 async_close 时自动清理 P2 (可以改进): - async_health_check 增加 landlock_probe_abi_version() 检查 - async_probe capabilities 增加 filesystem_only/auto_base_paths/landlock_version 测试更新: - test_provider_probe: 验证 probe 返回 enhanced capabilities - test_base_read_dirs_defined: 验证 _BASE_READ_DIRS 包含必要路径 - test_path_resolution_in_init: 验证路径解析防逃逸 - test_build_rules_includes_base_paths: 验证自动注入逻辑 - test_landlock_exit_codes_defined: 验证退出码定义 12 passed, 0 failed
- _BASE_READ_DIRS 添加 /proc/self/exe(spec 明确要求) - _add() 对 /proc/ 路径不做 resolve(内核虚拟路径) - 测试名对齐 spec: - test_default_base_paths_included - test_silent_failure_no_longer_silent - test_path_escape_validation 11 passed, 0 failed
新增 capabilities 字段: - configurable_restrictions: 描述可配置的限制范围 - config_params: allowed_read_dirs, allowed_write_dirs, abi_version - supported_access_rights: 15 种 Landlock 访问权限 - access_rights_by_abi: ABI v1/v2/v3 各版本支持的权限 - auto_injected_base_paths: 自动注入的路径说明 - read_only: _BASE_READ_DIRS 列表 - cwd: 执行目录自动只读 - temp_write: 无配置时自动创建临时可写目录 - meta: 增加 base_read_dirs 和 supported_abi_range 11 passed, 0 failed
This was referenced Jul 31, 2026
Merged
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.
No description provided.