Skip to content

Commit 127df13

Browse files
committed
Use statically linked coreutils for OCI hook chroot execution
Replace /usr/bin/env chroot with statically linked coreutils binary to support Kind clusters in CI where /usr/bin/env may not be available in the OCI hook context. The OCI runtime doesn't properly set argv[0] for hooks, so coreutils falls back to checking argv[1] for the program name ('chroot'), making this invocation method reliable across different container environments. - Add COREUTILS_STATIC environment variable pointing to static coreutils - Convert HOST_MOUNT_PATH to Path object for consistent path handling - Update NRI hook to invoke coreutils with 'chroot' as first argument
1 parent 3eeba8a commit 127df13

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

environments/node/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ let
2626
env-file.variables = {
2727
PYTHONUNBUFFERED = "1"; # If something ends up print logging
2828
NIXPKGS_ALLOW_UNFREE = "1"; # Allow building anything
29+
COREUTILS_STATIC = toString pkgs.pkgsStatic.coreutils;
2930
};
3031
# Umbrella service for CSI
3132
services.csi = {

python/nix_csi/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353

5454
# NRI host mount path for bind mounts (default: /var/lib/nix-csi)
5555
# Set via HOST_MOUNT_PATH environment variable from kubenix
56-
HOST_MOUNT_PATH = os.environ.get("HOST_MOUNT_PATH", "/var/lib/nix-csi")
56+
HOST_MOUNT_PATH = Path(os.environ.get("HOST_MOUNT_PATH", "/var/lib/nix-csi"))
57+
58+
# Statically linked chroot binary used to execute OCI hooks from HOST_MOUNT_PATH
59+
COREUTILS_STATIC = Path(os.environ.get("COREUTILS_STATIC", "coreutils"))
5760

5861
# Host /proc mounted into the daemonset for accessing container namespaces.
5962
# Set via HOST_PROC_PATH environment variable from kubenix.

python/nix_csi/nriplugin.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
NRI_PLUGIN_IDX,
2828
NRI_PLUGIN_NAME,
2929
NRI_RUNTIME_SOCKET,
30+
COREUTILS_STATIC,
3031
)
3132
from .nix import build_packages, get_build_args, get_closure_paths
3233
from .ns_mount import mount_in_container
@@ -226,9 +227,18 @@ async def CreateContainer(self, stream) -> None:
226227
assert self.nri_wait_bin is not None, (
227228
"nri-wait binary not found on PATH, wait hook won't be able to execute"
228229
)
230+
coreutils_binary = (
231+
HOST_MOUNT_PATH
232+
/ COREUTILS_STATIC.relative_to("/")
233+
/ "bin/coreutils"
234+
)
229235
hook = api_pb2.Hook(
230-
path="/usr/bin/env", # This is POSIX
231-
args=["chroot", HOST_MOUNT_PATH, self.nri_wait_bin],
236+
path=str(coreutils_binary),
237+
args=[
238+
"chroot", # somehow this works in OCI hooks but not --coreutils-prog=chroot....
239+
str(HOST_MOUNT_PATH),
240+
self.nri_wait_bin,
241+
],
232242
env=[
233243
"NRI_QUERY_SOCKET=/nix/var/nix-csi/wait-req.sock",
234244
"NRI_PUB_SOCKET=/nix/var/nix-csi/wait-pub.sock",
@@ -237,9 +247,10 @@ async def CreateContainer(self, stream) -> None:
237247
)
238248
adjust.hooks.create_runtime.append(hook)
239249
logger.info(
240-
"[CreateContainer] Injected createRuntime hook for container=%r (binary=%r)",
250+
"[CreateContainer] Injected createRuntime hook for container=%r (binary=%r) (chroot binary:%r)",
241251
container_id,
242252
self.nri_wait_bin,
253+
coreutils_binary,
243254
)
244255

245256
# Spawn build task to build store paths and namespace-mount them into the container

0 commit comments

Comments
 (0)