Skip to content

Commit b4aa8d5

Browse files
authored
Merge pull request #496 from common-workflow-language/docker_job_fix
feat: Pass group id (GID) in --user flag when calling docker run
2 parents 63db4dd + 9b53b98 commit b4aa8d5

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

cwltool/builder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
from .stdfsaccess import StdFsAccess
1919
from .utils import aslist, get_feature, docker_windows_path_adjust, onWindows
2020

21-
# if six.PY3:
22-
# AvroSchemaFromJSONData = avro.schema.SchemaFromJSONData
23-
# else:
2421
AvroSchemaFromJSONData = avro.schema.make_avsc_object
2522

2623
CONTENT_LIMIT = 64 * 1024

cwltool/docker_uid.py renamed to cwltool/docker_id.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
from __future__ import absolute_import
33

44
import subprocess
5-
from typing import List, Text
5+
from typing import List, Text, Tuple
66

77

8-
def docker_vm_uid(): # type: () -> int
8+
def docker_vm_id(): # type: () -> Tuple[int, int]
99
"""
10-
Returns the UID of the default docker user inside the VM
10+
Returns the User ID and Group ID of the default docker user inside the VM
1111
1212
When a host is using boot2docker or docker-machine to run docker with
1313
boot2docker.iso (As on Mac OS X), the UID that mounts the shared filesystem
1414
inside the VirtualBox VM is likely different than the user's UID on the host.
15-
:return: The numeric UID (as a string) of the docker account inside
15+
:return: A tuple containing numeric User ID and Group ID of the docker account inside
1616
the boot2docker VM
1717
"""
1818
if boot2docker_running():
19-
return boot2docker_uid()
19+
return boot2docker_id()
2020
elif docker_machine_running():
21-
return docker_machine_uid()
21+
return docker_machine_id()
2222
else:
23-
return None
23+
return (None, None)
2424

2525

2626
def check_output_and_strip(cmd): # type: (List[Text]) -> Text
@@ -95,23 +95,26 @@ def cmd_output_to_int(cmd): # type: (List[Text]) -> int
9595
return None
9696

9797

98-
def boot2docker_uid(): # type: () -> int
98+
def boot2docker_id(): # type: () -> Tuple[int, int]
9999
"""
100-
Gets the UID of the docker user inside a running boot2docker vm
101-
:return: the UID, or None if error (e.g. boot2docker not present or stopped)
100+
Gets the UID and GID of the docker user inside a running boot2docker vm
101+
:return: Tuple (UID, GID), or (None, None) if error (e.g. boot2docker not present or stopped)
102102
"""
103-
return cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u'])
104-
103+
uid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u'])
104+
gid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-g'])
105+
return (uid, gid)
105106

106-
def docker_machine_uid(): # type: () -> int
107+
def docker_machine_id(): # type: () -> Tuple[int, int]
107108
"""
108109
Asks docker-machine for active machine and gets the UID of the docker user
109110
inside the vm
110-
:return: the UID, or None if error (e.g. docker-machine not present or stopped)
111+
:return: tuple (UID, GID), or (None, None) if error (e.g. docker-machine not present or stopped)
111112
"""
112113
machine_name = docker_machine_name()
113-
return cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -u"])
114+
uid = cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -u"])
115+
gid = cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -g"])
116+
return (uid, gid)
114117

115118

116119
if __name__ == '__main__':
117-
print(docker_vm_uid())
120+
print(docker_vm_id())

cwltool/job.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .utils import copytree_with_merge, docker_windows_path_adjust, onWindows
2020
from . import docker
2121
from .builder import Builder
22-
from .docker_uid import docker_vm_uid
22+
from .docker_id import docker_vm_id
2323
from .errors import WorkflowException
2424
from .pathmapper import PathMapper
2525
from .process import (UnsupportedRequirement, empty_subtree, get_feature,
@@ -391,13 +391,12 @@ def run(self, pull_image=True, rm_container=True,
391391
if self.stdout:
392392
runtime.append("--log-driver=none")
393393

394-
if onWindows(): # windows os dont have getuid or geteuid functions
395-
euid = docker_vm_uid()
396-
else:
397-
euid = docker_vm_uid() or os.geteuid()
394+
euid, egid = docker_vm_id()
395+
if not onWindows(): # MS Windows does not have getuid() or geteuid() functions
396+
euid, egid = euid or os.geteuid(), egid or os.getgid()
398397

399-
if kwargs.get("no_match_user", None) is False and euid is not None:
400-
runtime.append(u"--user=%s" % (euid))
398+
if kwargs.get("no_match_user", None) is False and (euid, egid) != (None, None):
399+
runtime.append(u"--user=%d:%d" % (euid, egid))
401400

402401
if rm_container:
403402
runtime.append(u"--rm")

0 commit comments

Comments
 (0)