Skip to content

Commit 0b03dab

Browse files
Defining the full path of the Docker binary
This is a security fix, to avoid the user replacing the docker binary in PATH
1 parent 6935169 commit 0b03dab

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

socker.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def main(argv):
107107
#print 'current UID: ',os.getuid(),'\t Current GID: ',os.getgid()
108108

109109
# Checking for docker on the system
110-
p = subprocess.Popen('docker --version',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
110+
p = subprocess.Popen('/usr/bin/docker --version',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
111111
out,err = p.communicate()
112112
#print 'return out and err',out,err
113113
if p.returncode !=0:
@@ -184,7 +184,7 @@ def main(argv):
184184
sys.exit(2)
185185

186186
# Compose the docker command
187-
dockercmd = 'docker run --name='+cid+' -d -u '+str(user)+':'+str(group)
187+
dockercmd = '/usr/bin/docker run --name='+cid+' -d -u '+str(user)+':'+str(group)
188188
if slurm_job_id:
189189
dockercmd += ' -v $SCRATCH:$SCRATCH -e SCRATCH=$SCRATCH'
190190
dockercmd += ' -v /work/:/work/ -v '+PWD+':'+PWD+' -v '+home+':'+home+' -w '+PWD+' -e HOME='+home+' '+img
@@ -211,7 +211,7 @@ def main(argv):
211211

212212
if slurm_job_id:
213213
# Get the container's PID
214-
cpid = int(subprocess.Popen("docker inspect -f '{{ .State.Pid }}' "+cid,\
214+
cpid = int(subprocess.Popen("/usr/bin/docker inspect -f '{{ .State.Pid }}' "+cid,\
215215
shell=True, stdout=subprocess.PIPE).stdout.read().strip())
216216
#print 'container PID: ', cpid
217217
# Classify the container process (and all of it's children) to the Slurm's cgroups assigned to the job
@@ -223,10 +223,10 @@ def main(argv):
223223

224224
if verbose:
225225
print 'waiting for the container to exit...\n'
226-
subprocess.Popen('docker wait '+cid, shell=True, stdout=subprocess.PIPE).stdout.read()
226+
subprocess.Popen('/usr/bin/docker wait '+cid, shell=True, stdout=subprocess.PIPE).stdout.read()
227227

228228
# After the container exit's, capture it's output
229-
clog = subprocess.Popen("docker inspect -f '{{.LogPath}}' "+str(cid), shell=True, stdout=subprocess.PIPE).stdout.read().rstrip()
229+
clog = subprocess.Popen("/usr/bin/docker inspect -f '{{.LogPath}}' "+str(cid), shell=True, stdout=subprocess.PIPE).stdout.read().rstrip()
230230
with open(clog,'r') as f:
231231
if verbose:
232232
print 'container output:\n'
@@ -238,7 +238,7 @@ def main(argv):
238238
sys.stdout.write(d['log'])
239239
if verbose:
240240
print '\nremoving the container...\n'
241-
subprocess.Popen('docker rm '+cid, shell=True, stdout=subprocess.PIPE).stdout.read()
241+
subprocess.Popen('/usr/bin/docker rm '+cid, shell=True, stdout=subprocess.PIPE).stdout.read()
242242

243243
if __name__ == "__main__":
244244
main(sys.argv[1:])

0 commit comments

Comments
 (0)