Skip to content

Commit 9c9ee45

Browse files
committed
feat: Pass group id (GID) in --user flag when calling docker run
1 parent 63db4dd commit 9c9ee45

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

cwltool/docker_uid.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
from typing import List, Text
66

77

8-
def docker_vm_uid(): # type: () -> int
8+
def docker_vm_id(): # type: () -> 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 (as a string) 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:
2323
return None
2424

@@ -97,21 +97,24 @@ def cmd_output_to_int(cmd): # type: (List[Text]) -> int
9797

9898
def boot2docker_uid(): # type: () -> 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

106107
def docker_machine_uid(): # type: () -> 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: 4 additions & 4 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_uid import docker_vm_id
2323
from .errors import WorkflowException
2424
from .pathmapper import PathMapper
2525
from .process import (UnsupportedRequirement, empty_subtree, get_feature,
@@ -392,12 +392,12 @@ def run(self, pull_image=True, rm_container=True,
392392
runtime.append("--log-driver=none")
393393

394394
if onWindows(): # windows os dont have getuid or geteuid functions
395-
euid = docker_vm_uid()
395+
euid, egid = docker_vm_id()
396396
else:
397-
euid = docker_vm_uid() or os.geteuid()
397+
euid, egid = docker_vm_id() or (os.geteuid(), os.getegid())
398398

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

402402
if rm_container:
403403
runtime.append(u"--rm")

0 commit comments

Comments
 (0)