3"""Authenticate executable and plugin trees before fleet control-plane use."""
5from __future__
import annotations
7from pathlib
import Path
10def confined_link_errors(root: Path) -> list[str]:
11 """Return every broken, absolute, or escaping symlink below ``root``."""
13 authority = root.resolve(strict=
True)
14 except OSError
as exc:
15 return [f
"collection tree is unavailable: {exc}"]
16 if root.absolute() != authority
or root.is_symlink()
or not root.is_dir():
17 return [
"collection tree root is not a real owned directory"]
18 errors: list[str] = []
19 for entry
in sorted(root.rglob(
"*")):
22 except OSError
as exc:
23 errors.append(f
"cannot lstat {entry}: {exc}")
25 if not entry.is_symlink():
27 target_text = entry.readlink()
29 target = entry.resolve(strict=
True)
30 except (OSError, RuntimeError)
as exc:
31 errors.append(f
"broken collection link {entry}: {exc}")
33 if target_text.is_absolute()
or not target.is_relative_to(authority):
34 errors.append(f
"collection link escapes its root: {entry}")
35 if not (target.is_file()
or target.is_dir()):
36 errors.append(f
"collection link target is not a file or directory: {entry}")