Fixes #838. xattrs were historically disabled in 2017, since then, NFS v4.2 gained support for xattrs and almost all filesystems support xattrs. In addition, moving the build directory to a xattrs-supporting filesystem is always an option. Programs may exploit xattrs (including ACLs) during their build process and testing phase, to better serve these programs, we will remove this limitation. Lix will use POSIX ACLs for its UNIX domain sockets in the future and be one of these programs which will run tests making use of xattrs, while not writing any xattrs in the derivation outputs themselves. xattrs are still scrubbed from derivation outputs so it is not possible to obtain an advantage by writing a security-related xattr to a well chosen file. Tests were added to test these scenarios on Linux. Darwin is carefully excluded because of #1008 and #1090, solving that is welcome. In the meantime, they are marked xfail. Change-Id: Ia3255eeb8442e83db4f10dcb5a51cbc368a2550d Signed-off-by: Raito Bezarius <raito@lix.systems>
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import xattr
|
|
import pytest
|
|
|
|
from pathlib import Path
|
|
from functional2.testlib.fixtures.env import ManagedEnv
|
|
|
|
|
|
def has_xattrs(path: Path) -> bool:
|
|
"""
|
|
Check if a file or directory has any extended attributes.
|
|
"""
|
|
try:
|
|
xattrs_list = xattr.list(str(path), nofollow=True)
|
|
return bool(xattrs_list)
|
|
except OSError:
|
|
# If an error occurs, either because the file doesn't exist or no xattrs, return False
|
|
return False
|
|
|
|
|
|
def verify_no_xattrs_in_tree(root_dir: Path) -> None:
|
|
"""
|
|
Traverse a directory tree and verify no file or directory has xattrs.
|
|
"""
|
|
if root_dir.is_file():
|
|
assert not has_xattrs(root_dir)
|
|
return
|
|
|
|
for entry in root_dir.iterdir():
|
|
assert not has_xattrs(entry)
|
|
if entry.is_dir():
|
|
verify_no_xattrs_in_tree(entry)
|
|
|
|
|
|
def test_set_clear_xattrs_in(dir_: Path) -> bool:
|
|
try:
|
|
xattr.set(dir_, "user.test", "1", nofollow=True)
|
|
xattr.remove(dir_, "user.test", nofollow=True)
|
|
return True
|
|
except OSError:
|
|
return False
|
|
|
|
|
|
def skip_if_xattrs_are_unsupported(env: ManagedEnv) -> None:
|
|
"""
|
|
Skip the current test if xattrs are unsupported in, either:
|
|
- the test root
|
|
- the fixture root
|
|
"""
|
|
if not test_set_clear_xattrs_in(env.dirs.test_root):
|
|
pytest.skip("xattrs cannot be used in the test root")
|
|
|
|
if not test_set_clear_xattrs_in(env.dirs.home):
|
|
pytest.skip("xattrs cannot be used in the fixture directory")
|