Report restrictive storage ancestors with unmapped host owners or groups.
One bounded Podman info query identifies the relevant local rootless store.
Modes, numeric IDs, mapping status and ACL presence are observations, not
a cause or repair recommendation. Unavailable fields stay unknown; probe
failures leave the original error alone. Never inspect or launch a container.
Source code in src/terok_sandbox/runtime/storage_diagnostics.py
| def storage_permission_diagnostics(stderr: str) -> str:
"""Report restrictive storage ancestors with unmapped host owners or groups.
One bounded Podman info query identifies the relevant local rootless store.
Modes, numeric IDs, mapping status and ACL presence are observations, not
a cause or repair recommendation. Unavailable fields stay unknown; probe
failures leave the original error alone. Never inspect or launch a container.
"""
match = _ROOTFS_DENIED.search(stderr)
if match is None:
return ""
try:
result = subprocess.run( # nosec B603 - fixed read-only Podman command
[require_host_tool("podman"), "info", "--format", "json"],
capture_output=True,
text=True,
check=True,
timeout=_PROBE_TIMEOUT,
)
info = json.loads(result.stdout)
host = info["host"]
if host["security"]["rootless"] is not True or host["serviceIsRemote"] is not False:
return ""
root = Path(info["store"]["graphRoot"])
if not root.is_absolute():
return ""
root = root.resolve(strict=True)
if root not in Path(match[1]).resolve().parents:
return ""
mappings = host["idMappings"]
if not isinstance(mappings, dict):
return ""
observations = []
for directory in (root, *root.parents):
try:
metadata = directory.stat()
except OSError:
continue
if not stat.S_ISDIR(metadata.st_mode) or metadata.st_mode & stat.S_IXOTH:
continue
owner = _mapping_status(metadata.st_uid, mappings.get("uidmap"))
group = _mapping_status(metadata.st_gid, mappings.get("gidmap"))
if "unmapped" in (owner, group):
observations.append(
f" {sanitize_tty(str(directory))}: mode={stat.S_IMODE(metadata.st_mode):04o}, "
f"owner UID={metadata.st_uid} ({owner}), group GID={metadata.st_gid} ({group}), "
f"access ACL={_acl_status(directory)}"
)
if observations:
return (
"\n\nStorage diagnostics (host IDs vs Podman's rootless mappings):\n"
+ "\n".join(observations)
)
except (OSError, subprocess.SubprocessError, ValueError, KeyError, TypeError, RuntimeError):
# Diagnostics must never replace the launch error with a probe error.
return ""
return ""
|