fix: parse ls output with SELinux security-context marker#3904
Conversation
`parse_ls_la` passes the raw mode field from `ls -la` straight into `Permissions.from_str`, which strips a trailing alternate-access marker only for "+" (ACL) and "@" (macOS extended attributes). On SELinux-enabled systems (RHEL, Fedora, and most Linux containers) coreutils appends "." instead — e.g. `drwxr-xr-x.` — so the 11-char string is not stripped, fails the `len != 10` check, and raises `ValueError`, crashing `ls()` on those hosts. Add "." to the recognized trailing markers and cover it with a regression test alongside the existing "+"/"@" cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks for maintaining this SDK, @seratch 🙏 Small, self-contained fix for Locally verified: added a regression test that fails without the fix and passes with it, and |
Summary
SandboxSession.ls()crashes on SELinux-enabled hosts because thels -lapermission-string parser does not recognize the SELinux security-context marker (.) that GNU coreutils appends to the mode field.Problem
parse_ls_latakes the raw mode field (parts[0]) fromls -laoutput and passes it toPermissions.from_str.from_strstrips a trailing 11th "alternate access method" marker, but only for"+"(ACL) and"@"(macOS extended attributes):On SELinux-enabled systems — RHEL, Fedora, CentOS, and the majority of Linux container base images — coreutils appends
"."instead:That string is 11 chars but does not end in
+/@, so it is not stripped, fails thelen(perms) != 10guard, and raises:The result is that
ls()(and anything built on it) fails on any SELinux host, even though the permission bits are perfectly parseable.Solution
Add
"."to the set of recognized trailing markers, so the SELinux context marker is stripped exactly like the existing+/@markers:One-line behavioral change, plus a clarifying comment. No public API change.
Testing performed
test_parse_ls_la_strips_trailing_alternate_access_markers, covering the.(SELinux),+(ACL), and@(xattr) markers together. Confirmed it fails without the fix (ValueError: invalid permissions string length: 'drwxr-xr-x.') and passes with it.uv run pytest tests/sandbox/test_parse_utils.py— 11 passed.uv run ruff format --checkanduv run ruff check— clean on both changed files.uv run mypy— no issues;uv run pyright— 0 errors.🤖 Generated with Claude Code