From fa3fbeacc9b3810cee397dfa8933cc4aa3252f43 Mon Sep 17 00:00:00 2001 From: Jason Kai Date: Wed, 17 Jul 2024 08:30:20 -0400 Subject: [PATCH 1/2] Add uid to command - Should the default uid be overwritable? --- src/styxdocker/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/styxdocker/__init__.py b/src/styxdocker/__init__.py index c15fb52..2c800ed 100644 --- a/src/styxdocker/__init__.py +++ b/src/styxdocker/__init__.py @@ -58,6 +58,7 @@ def __init__( output_dir: pathlib.Path, metadata: Metadata, container_tag: str, + docker_userid: str, docker_executable: str, ) -> None: """Create DockerExecution.""" @@ -69,6 +70,7 @@ def __init__( self.output_dir = output_dir self.metadata = metadata self.container_tag = container_tag + self.docker_userid = docker_userid self.docker_executable = docker_executable def input_file(self, host_file: InputPathType) -> str: @@ -118,6 +120,7 @@ def run(self, cargs: list[str]) -> None: self.docker_executable, "run", "--rm", + *(["-u", self.docker_userid] if self.docker_userid else []), "-w", "/styx_output", *mounts, @@ -171,6 +174,7 @@ def __init__( self.data_dir = pathlib.Path(data_dir or "styx_tmp") self.uid = os.urandom(8).hex() self.execution_counter = 0 + self.userid = os.getuid() if os.name == "posix" else None self.docker_executable = docker_executable self.image_overrides = image_overrides or {} @@ -198,5 +202,6 @@ def start_execution(self, metadata: Metadata) -> Execution: / f"{self.uid}_{self.execution_counter - 1}_{metadata.name}", metadata=metadata, container_tag=container_tag, + docker_userid=f"{self.userid}", docker_executable=self.docker_executable, ) From 1de866e30556cede0a17570aee04810079cdcca0 Mon Sep 17 00:00:00 2001 From: Jason Kai Date: Wed, 17 Jul 2024 10:43:30 -0400 Subject: [PATCH 2/2] Expose user_id top Runner constructor --- src/styxdocker/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/styxdocker/__init__.py b/src/styxdocker/__init__.py index 2c800ed..525566c 100644 --- a/src/styxdocker/__init__.py +++ b/src/styxdocker/__init__.py @@ -58,7 +58,7 @@ def __init__( output_dir: pathlib.Path, metadata: Metadata, container_tag: str, - docker_userid: str, + docker_user_id: str | None, docker_executable: str, ) -> None: """Create DockerExecution.""" @@ -70,7 +70,7 @@ def __init__( self.output_dir = output_dir self.metadata = metadata self.container_tag = container_tag - self.docker_userid = docker_userid + self.docker_user_id = docker_user_id self.docker_executable = docker_executable def input_file(self, host_file: InputPathType) -> str: @@ -120,7 +120,7 @@ def run(self, cargs: list[str]) -> None: self.docker_executable, "run", "--rm", - *(["-u", self.docker_userid] if self.docker_userid else []), + *(["-u", self.docker_user_id] if self.docker_user_id else []), "-w", "/styx_output", *mounts, @@ -168,13 +168,16 @@ def __init__( self, image_overrides: dict[str, str] | None = None, docker_executable: str = "docker", + user_id: int | None = None, data_dir: InputPathType | None = None, ) -> None: """Create a new DockerRunner.""" self.data_dir = pathlib.Path(data_dir or "styx_tmp") self.uid = os.urandom(8).hex() self.execution_counter = 0 - self.userid = os.getuid() if os.name == "posix" else None + self.user_id = ( + user_id if user_id else (os.getuid() if os.name == "posix" else None) + ) self.docker_executable = docker_executable self.image_overrides = image_overrides or {} @@ -202,6 +205,6 @@ def start_execution(self, metadata: Metadata) -> Execution: / f"{self.uid}_{self.execution_counter - 1}_{metadata.name}", metadata=metadata, container_tag=container_tag, - docker_userid=f"{self.userid}", + docker_user_id=f"{self.user_id}", docker_executable=self.docker_executable, )