From 0e4ed8590959a14e283d4c9bcb2200d81f4f9a08 Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Tue, 25 Jul 2017 03:39:06 +0530 Subject: [PATCH 1/3] feat: Pass group id (GID) in --user flag when calling docker run minor: builder.py: remove commented avro code --- cwltool/builder.py | 3 --- cwltool/{docker_uid.py => docker_id.py} | 33 ++++++++++++++----------- cwltool/job.py | 13 +++++----- 3 files changed, 24 insertions(+), 25 deletions(-) rename cwltool/{docker_uid.py => docker_id.py} (74%) diff --git a/cwltool/builder.py b/cwltool/builder.py index 36159f326..c74e2e688 100644 --- a/cwltool/builder.py +++ b/cwltool/builder.py @@ -18,9 +18,6 @@ from .stdfsaccess import StdFsAccess from .utils import aslist, get_feature, docker_windows_path_adjust, onWindows -# if six.PY3: -# AvroSchemaFromJSONData = avro.schema.SchemaFromJSONData -# else: AvroSchemaFromJSONData = avro.schema.make_avsc_object CONTENT_LIMIT = 64 * 1024 diff --git a/cwltool/docker_uid.py b/cwltool/docker_id.py similarity index 74% rename from cwltool/docker_uid.py rename to cwltool/docker_id.py index 90452a2e4..6a9360c90 100644 --- a/cwltool/docker_uid.py +++ b/cwltool/docker_id.py @@ -2,23 +2,23 @@ from __future__ import absolute_import import subprocess -from typing import List, Text +from typing import List, Text, Tuple -def docker_vm_uid(): # type: () -> int +def docker_vm_id(): # type: () -> Tuple[int, int] """ - Returns the UID of the default docker user inside the VM + Returns the User ID and Group ID of the default docker user inside the VM When a host is using boot2docker or docker-machine to run docker with boot2docker.iso (As on Mac OS X), the UID that mounts the shared filesystem inside the VirtualBox VM is likely different than the user's UID on the host. - :return: The numeric UID (as a string) of the docker account inside + :return: A tuple containing numeric User ID and Group ID (as a string) of the docker account inside the boot2docker VM """ if boot2docker_running(): - return boot2docker_uid() + return boot2docker_id() elif docker_machine_running(): - return docker_machine_uid() + return docker_machine_id() else: return None @@ -95,23 +95,26 @@ def cmd_output_to_int(cmd): # type: (List[Text]) -> int return None -def boot2docker_uid(): # type: () -> int +def boot2docker_id(): # type: () -> Tuple[int, int] """ - Gets the UID of the docker user inside a running boot2docker vm - :return: the UID, or None if error (e.g. boot2docker not present or stopped) + Gets the UID and GID of the docker user inside a running boot2docker vm + :return: tuple (UID, GID), or (None, None) if error (e.g. boot2docker not present or stopped) """ - return cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u']) + uid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u']) + gid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-g']) + return (uid, gid) - -def docker_machine_uid(): # type: () -> int +def docker_machine_id(): # type: () -> Tuple[int, int] """ Asks docker-machine for active machine and gets the UID of the docker user inside the vm - :return: the UID, or None if error (e.g. docker-machine not present or stopped) + :return: tuple (UID, GID), or (None, None) if error (e.g. docker-machine not present or stopped) """ machine_name = docker_machine_name() - return cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -u"]) + uid = cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -u"]) + gid = cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -g"]) + return (uid, gid) if __name__ == '__main__': - print(docker_vm_uid()) + print(docker_vm_id()) diff --git a/cwltool/job.py b/cwltool/job.py index b5108e3a3..7227e99f9 100644 --- a/cwltool/job.py +++ b/cwltool/job.py @@ -19,7 +19,7 @@ from .utils import copytree_with_merge, docker_windows_path_adjust, onWindows from . import docker from .builder import Builder -from .docker_uid import docker_vm_uid +from .docker_id import docker_vm_id from .errors import WorkflowException from .pathmapper import PathMapper from .process import (UnsupportedRequirement, empty_subtree, get_feature, @@ -391,13 +391,12 @@ def run(self, pull_image=True, rm_container=True, if self.stdout: runtime.append("--log-driver=none") - if onWindows(): # windows os dont have getuid or geteuid functions - euid = docker_vm_uid() - else: - euid = docker_vm_uid() or os.geteuid() + euid, egid = docker_vm_id() + if not onWindows(): # MS Windows does not have getuid() or geteuid() functions + euid, egid = euid or os.geteuid(), egid or os.getgid() - if kwargs.get("no_match_user", None) is False and euid is not None: - runtime.append(u"--user=%s" % (euid)) + if kwargs.get("no_match_user", None) is False and (euid, egid) != (None, None): + runtime.append(u"--user=%d:%d" % (euid, egid)) if rm_container: runtime.append(u"--rm") From fa3c129835830c7e8971b990f148f8bade53a5ec Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Tue, 25 Jul 2017 22:50:45 +0530 Subject: [PATCH 2/3] docker_id.py: remove `return as string` from docstring. return type is int --- cwltool/docker_id.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cwltool/docker_id.py b/cwltool/docker_id.py index 6a9360c90..ed701aae9 100644 --- a/cwltool/docker_id.py +++ b/cwltool/docker_id.py @@ -12,7 +12,7 @@ def docker_vm_id(): # type: () -> Tuple[int, int] When a host is using boot2docker or docker-machine to run docker with boot2docker.iso (As on Mac OS X), the UID that mounts the shared filesystem inside the VirtualBox VM is likely different than the user's UID on the host. - :return: A tuple containing numeric User ID and Group ID (as a string) of the docker account inside + :return: A tuple containing numeric User ID and Group ID of the docker account inside the boot2docker VM """ if boot2docker_running(): @@ -98,7 +98,7 @@ def cmd_output_to_int(cmd): # type: (List[Text]) -> int def boot2docker_id(): # type: () -> Tuple[int, int] """ Gets the UID and GID of the docker user inside a running boot2docker vm - :return: tuple (UID, GID), or (None, None) if error (e.g. boot2docker not present or stopped) + :return: Tuple (UID, GID), or (None, None) if error (e.g. boot2docker not present or stopped) """ uid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u']) gid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-g']) From 9b53b986b1350d27e97e4f4ffe538d232ec846ce Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Tue, 25 Jul 2017 23:17:05 +0530 Subject: [PATCH 3/3] docker_id: always return a tuple --- cwltool/docker_id.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cwltool/docker_id.py b/cwltool/docker_id.py index ed701aae9..b570f9374 100644 --- a/cwltool/docker_id.py +++ b/cwltool/docker_id.py @@ -20,7 +20,7 @@ def docker_vm_id(): # type: () -> Tuple[int, int] elif docker_machine_running(): return docker_machine_id() else: - return None + return (None, None) def check_output_and_strip(cmd): # type: (List[Text]) -> Text