# Ensure /etc exists in the sandbox
(dst / "etc").mkdir(exist_ok=True)
- if Path("/etc/passwd").exists():
- shutil.copy("/etc/passwd", dst / "etc/passwd")
- if Path("/etc/group").exists():
- shutil.copy("/etc/passwd", dst / "etc/group")
-
if (p := config.tools() / "etc/crypto-policies").exists():
copy_tree(
p,
sandbox=config.sandbox,
) # fmt: skip
- if not config.sandbox_trees:
- return
+ if config.sandbox_trees:
+ with complete_step("Copying in sandbox trees…"):
+ for tree in config.sandbox_trees:
+ install_tree(config, tree.source, dst, target=tree.target, preserve=False)
- with complete_step("Copying in sandbox trees…"):
- for tree in config.sandbox_trees:
- install_tree(config, tree.source, dst, target=tree.target, preserve=False)
+ if Path("/etc/passwd").exists():
+ shutil.copy("/etc/passwd", dst / "etc/passwd")
+ if Path("/etc/group").exists():
+ shutil.copy("/etc/passwd", dst / "etc/group")
+
+ if not (dst / "etc/mtab").is_symlink():
+ (dst / "etc/mtab").symlink_to("../proc/self/mounts")
+
+ Path(dst / "etc/resolv.conf").unlink(missing_ok=True)
+ Path(dst / "etc/resolv.conf").touch()
+
+ Path(dst / "etc/static").unlink(missing_ok=True)
+ if (config.tools() / "etc/static").is_symlink():
+ (dst / "etc/static").symlink_to((config.tools() / "etc/static").readlink())
+
+ # Create various mountpoints in /etc as /etc from the sandbox tree is mounted read-only into the sandbox.
+
+ for d in (
+ "etc/pki",
+ "etc/ssl",
+ "etc/ca-certificates",
+ "var/lib/ca-certificates",
+ "etc/pacman.d/gnupg",
+ "etc/alternatives",
+ ):
+ (dst / d).mkdir(parents=True, exist_ok=True)
+
+ for f in (
+ "etc/passwd",
+ "etc/group",
+ "etc/shadow",
+ "etc/gshadow",
+ "etc/ld.so.cache",
+ ):
+ (dst / f).touch(exist_ok=True)
def install_package_directories(context: Context, directories: Sequence[Path]) -> None:
Path("etc/pki"),
Path("etc/ssl"),
Path("etc/ca-certificates"),
- Path("etc/static"),
Path("var/lib/ca-certificates"),
)
if (root / subdir).exists()
if (config.tools() / "etc/pacman.d/gnupg").exists():
mounts += [(config.tools() / "etc/pacman.d/gnupg", Path("/etc/pacman.d/gnupg"))]
- return flatten(
- ("--symlink", src.readlink(), target) if src.is_symlink() else ("--ro-bind", src, target)
- for src, target in sorted(set(mounts), key=lambda s: s[1])
- )
+ return flatten(("--ro-bind", src, target) for src, target in sorted(set(mounts), key=lambda s: s[1]))
"--dir", "/var/tmp",
"--dir", "/var/log",
"--unshare-ipc",
- "--symlink", "../proc/self/mounts", "/etc/mtab",
] # fmt: skip
if devices:
yield [*cmdline, "--bind", tmp, "/var/tmp", *options, "--"]
return
- for d in ("etc", "opt", "srv", "media", "mnt", "var", "run", "tmp"):
+ for d in ("etc", "opt"):
+ if overlay and (overlay / d).exists():
+ cmdline += ["--ro-bind", overlay / d, Path("/") / d]
+ else:
+ cmdline += ["--dir", Path("/") / d]
+
+ for d in ("srv", "media", "mnt", "var", "run", "tmp"):
tmp = None
if d not in ("run", "tmp"):
with umask(~0o755):