Skip to content

Commit 07a0a2b

Browse files
committed
installer: Only mount configured state subdirs into sandbox
This got lost somewhere with the countless refactorings. Let's not mount a state directory to /var/lib unless one is configured. Most package managers don't actually store anything there that we care about and if we use PackageCacheDirectory=/var, we might end up mounting too much state there, such as the pacman host db lock file. Fixes #3985
1 parent d5efbf6 commit 07a0a2b

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

mkosi/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4726,6 +4726,10 @@ def sync_repository_metadata(
47264726
for d in ("cache", "lib"):
47274727
(metadata_dir / d / subdir).mkdir(parents=True, exist_ok=True)
47284728

4729+
src = metadata_dir / "lib" / subdir
4730+
for p in last.distribution.installer.package_manager(last).state_subdirs():
4731+
(src / p).mkdir(parents=True, exist_ok=True)
4732+
47294733
(last.package_cache_dir_or_default() / "cache" / subdir).mkdir(parents=True, exist_ok=True)
47304734

47314735
# Sync repository metadata unless explicitly disabled.
@@ -4753,7 +4757,6 @@ def sync_repository_metadata(
47534757
context,
47544758
force=context.args.force > 1 or context.config.cacheonly == Cacheonly.never,
47554759
)
4756-
47574760
src = metadata_dir / "cache" / subdir
47584761
dst = last.package_cache_dir_or_default() / "cache" / subdir
47594762

mkosi/installer/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def package_globs(cls) -> list[str]:
3030
return []
3131

3232
@classmethod
33-
def state_subdirs(cls, state: Path) -> list[Path]:
33+
def state_subdirs(cls) -> list[Path]:
3434
return []
3535

3636
@classmethod
@@ -85,7 +85,12 @@ def mounts(cls, context: Context) -> list[PathString]:
8585
subdir = context.config.distribution.installer.package_manager(context.config).subdir(context.config)
8686

8787
src = context.metadata_dir / "lib" / subdir
88-
mounts += ["--bind", src, Path("/var/lib") / subdir]
88+
mounts += flatten(
89+
("--bind", src / state_subdir, Path("/var/lib") / subdir / state_subdir)
90+
for state_subdir in context.config.distribution.installer.package_manager(
91+
context.config
92+
).state_subdirs()
93+
)
8994

9095
src = context.metadata_dir / "cache" / subdir
9196
caches = context.config.distribution.installer.package_manager(context.config).package_subdirs(src)

mkosi/installer/apt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def package_globs(cls) -> list[str]:
6464
return ["*.deb", "*.ddeb"]
6565

6666
@classmethod
67-
def state_subdirs(cls, state: Path) -> list[Path]:
68-
return [state / "lists"]
67+
def state_subdirs(cls) -> list[Path]:
68+
return [Path("lists")]
6969

7070
@classmethod
7171
def dpkg_cmd(cls, command: str) -> list[PathString]:

mkosi/installer/pacman.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def package_globs(cls) -> list[str]:
4343
return ["*.pkg.tar*"]
4444

4545
@classmethod
46-
def state_subdirs(cls, state: Path) -> list[Path]:
47-
return [state / "sync"]
46+
def state_subdirs(cls) -> list[Path]:
47+
return [Path("sync")]
4848

4949
@classmethod
5050
def scripts(cls, context: Context) -> dict[str, list[PathString]]:

0 commit comments

Comments
 (0)