mount_security
mount_security
¶
Mount validation and security for container sandboxes.
Port of NanoClaw's mount-security.ts — validates bind mounts
against an allowlist and blocks paths containing sensitive files.
Classes¶
AllowedRoot
dataclass
¶
An allowed mount root with optional read-only constraint.
MountAllowlist
dataclass
¶
MountAllowlist(roots: List[AllowedRoot] = list(), blocked_patterns: List[str] = (lambda: list(DEFAULT_BLOCKED_PATTERNS))())
Allowlist for container mounts.
Functions¶
load_mount_allowlist
¶
load_mount_allowlist(path: str) -> MountAllowlist
Load a mount allowlist from a JSON file.
Expected format::
{
"roots": [
{"path": "/home/user/projects", "read_only": false},
{"path": "/data", "read_only": true}
],
"blocked_patterns": [".ssh", ".env", "*.pem"]
}
If blocked_patterns is omitted, :data:DEFAULT_BLOCKED_PATTERNS
is used.
Source code in src/openjarvis/sandbox/mount_security.py
validate_mount
¶
validate_mount(mount_path: str, allowlist: MountAllowlist) -> bool
Validate a single mount path against the allowlist.
Returns True if the mount is allowed, False otherwise.
Source code in src/openjarvis/sandbox/mount_security.py
validate_mounts
¶
validate_mounts(mounts: List[str], allowlist: MountAllowlist) -> List[str]
Validate a list of mount paths. Returns only valid mounts.
Raises :class:ValueError for any blocked mount.