Skip to content

Commit 6ceb498

Browse files
authored
feat: mknod intercepts now configurable from LXDProvider (#717)
* feat: mknod intercepts now configurable from LXDProvider * fix: unit test * fix: lint * docs: update changelog (also includes item from #710)
1 parent 5bbaf39 commit 6ceb498

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

craft_providers/lxd/lxd_instance.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import shutil
2525
import subprocess
2626
import tempfile
27+
import warnings
2728
from typing import Any, Dict, List, Optional
2829

2930
from craft_providers.const import TIMEOUT_SIMPLE
@@ -54,6 +55,7 @@ def __init__(
5455
project: str = "default",
5556
remote: str = "local",
5657
lxc: Optional[LXC] = None,
58+
intercept_mknod: bool = True,
5759
) -> None:
5860
"""Create an LXD executor.
5961
@@ -65,6 +67,7 @@ def __init__(
6567
:param project: The name of the LXD project.
6668
:param remote: The name of the LXD remote.
6769
:param lxc: The LXC wrapper to use.
70+
:param intercept_mknod: If the host can, tell LXD instance to intercept mknod
6871
6972
:raises LXDError: If the name is invalid.
7073
"""
@@ -79,6 +82,7 @@ def __init__(
7982
self.instance_name = get_instance_name(name, LXDError)
8083
self.project = project
8184
self.remote = remote
85+
self._intercept_mknod = intercept_mknod
8286

8387
if lxc is None:
8488
self.lxc = LXC()
@@ -363,8 +367,14 @@ def launch(
363367
uid = os.getuid()
364368
config_keys["raw.idmap"] = f"both {uid!s} 0"
365369

366-
if self._host_supports_mknod():
367-
config_keys["security.syscalls.intercept.mknod"] = "true"
370+
if self._intercept_mknod:
371+
if not self._host_supports_mknod():
372+
warnings.warn(
373+
"Application configured to intercept guest mknod calls, "
374+
"but the host OS does not support intercepting mknod."
375+
)
376+
else:
377+
config_keys["security.syscalls.intercept.mknod"] = "true"
368378

369379
self.lxc.launch(
370380
config_keys=config_keys,

craft_providers/lxd/lxd_provider.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class LXDProvider(Provider):
4545
:param lxc: Optional lxc client to use.
4646
:param lxd_project: LXD project to use (default is default).
4747
:param lxd_remote: LXD remote to use (default is local).
48+
:param intercept_mknod: If the host can, tell LXD instance to intercept mknod
4849
"""
4950

5051
def __init__(
@@ -53,10 +54,12 @@ def __init__(
5354
lxc: LXC = LXC(),
5455
lxd_project: str = "default",
5556
lxd_remote: str = "local",
57+
intercept_mknod: bool = True,
5658
) -> None:
5759
self.lxc = lxc
5860
self.lxd_project = lxd_project
5961
self.lxd_remote = lxd_remote
62+
self._intercept_mknod = intercept_mknod
6063

6164
@property
6265
def name(self) -> str:
@@ -98,6 +101,7 @@ def create_environment(self, *, instance_name: str) -> Executor:
98101
name=instance_name,
99102
project=self.lxd_project,
100103
remote=self.lxd_remote,
104+
intercept_mknod=self._intercept_mknod,
101105
)
102106

103107
@contextlib.contextmanager

docs/reference/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Changelog
44
See the `Releases page`_ on GitHub for a complete list of commits that are
55
included in each version.
66

7+
2.2.0 (2025-Jan-16)
8+
-------------------
9+
- ``hookutil.py`` now available for dependent projects to clean up lxd
10+
instances.
11+
- Dependent projects can now disable lxd ``mknod`` interception via
12+
``LXDProvider``'s ``__init__``.
13+
714
2.1.0 (2025-Jan-10)
815
-------------------
916
- Require Multipass>=1.14.1

tests/unit/lxd/test_lxd_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_create_environment(mocker):
121121
provider.create_environment(instance_name="test-name")
122122

123123
mock_lxd_instance.assert_called_once_with(
124-
name="test-name", project="default", remote="local"
124+
name="test-name", project="default", remote="local", intercept_mknod=True
125125
)
126126

127127

0 commit comments

Comments
 (0)