arvados-cli 0.1.20151015194711 → 0.1.20151023190001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/crunch-job +54 -5
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecb7ca2ad7208acc3fadfb4e90752a224ba36c95
4
- data.tar.gz: 55ea27943c76698d5bf316914fc332b171e475e5
3
+ metadata.gz: ba224c6c0738da9111348f7b9bbefa056cc146c1
4
+ data.tar.gz: cce922c27376ab4477fa5cdd4158d88bdd16414b
5
5
  SHA512:
6
- metadata.gz: 9471f8ffba3ace95bc12d3c1c1feb67133da3b61609c2d2c3abb389189c372d86f189ec9100e0bf61820bc6bd122c29435da19c0cdc58a5f8ddc176efc381991
7
- data.tar.gz: 231055e48f5a21ec91e1f4ac7e834801afcf829125ec391ee2518d9632d877eca4f2abf48ed91a845dfdc4f847db8fcb73007e15c2583c7e85870f2ae97bbcc2
6
+ metadata.gz: 1770331e2ae4aba0bafb44b7ad6f9de4b0655f7e7bb30781339c8395bfbcd9ff37cd5d878790784b1be27dd360c72c15311f1ae803b25d28b2685c2290dc7390
7
+ data.tar.gz: 35c40d6695d4081ab0b6307d23e6edffe9bcab88805dc529262fcef85900b2e4e5bd2f3f383cffc97d563c9ecbc2e5a36f2132fa54969ef2e7d6eaa1ddfbb7a2
data/bin/crunch-job CHANGED
@@ -411,7 +411,7 @@ if (!defined $no_clear_tmp) {
411
411
  }
412
412
 
413
413
  # If this job requires a Docker image, install that.
414
- my ($docker_locator, $docker_stream, $docker_hash, $docker_limitmem);
414
+ my ($docker_locator, $docker_stream, $docker_hash, $docker_limitmem, $dockeruserarg);
415
415
  if ($docker_locator = $Job->{docker_image_locator}) {
416
416
  ($docker_stream, $docker_hash) = find_docker_image($docker_locator);
417
417
  if (!$docker_hash)
@@ -449,6 +449,42 @@ fi
449
449
  {fork => 1});
450
450
  $docker_limitmem = ($? == 0);
451
451
 
452
+ # Find a non-root Docker user to use.
453
+ # Tries the default user for the container, then 'crunch', then 'nobody',
454
+ # testing for whether the actual user id is non-zero. This defends against
455
+ # mistakes but not malice, but we intend to harden the security in the future
456
+ # so we don't want anyone getting used to their jobs running as root in their
457
+ # Docker containers.
458
+ my @tryusers = ("", "crunch", "nobody");
459
+ foreach my $try_user (@tryusers) {
460
+ my $try_user_arg;
461
+ if ($try_user eq "") {
462
+ Log(undef, "Checking if container default user is not UID 0");
463
+ $try_user_arg = "";
464
+ } else {
465
+ Log(undef, "Checking if user '$try_user' is not UID 0");
466
+ $try_user_arg = "--user=$try_user";
467
+ }
468
+ srun(["srun", "--nodelist=" . $node[0]],
469
+ ["/bin/sh", "-ec",
470
+ "a=`$docker_bin run --rm $try_user_arg $docker_hash id --user` && " .
471
+ " test \$a -ne 0"],
472
+ {fork => 1});
473
+ if ($? == 0) {
474
+ $dockeruserarg = $try_user_arg;
475
+ if ($try_user eq "") {
476
+ Log(undef, "Container will run with default user");
477
+ } else {
478
+ Log(undef, "Container will run with $dockeruserarg");
479
+ }
480
+ last;
481
+ }
482
+ }
483
+
484
+ if (!defined $dockeruserarg) {
485
+ croak("Could not find a user in container that is not UID 0 (tried default user, @tryusers) or there was a problem running 'id' in the container.");
486
+ }
487
+
452
488
  if ($Job->{arvados_sdk_version}) {
453
489
  # The job also specifies an Arvados SDK version. Add the SDKs to the
454
490
  # tar file for the build script to install.
@@ -844,6 +880,9 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
844
880
  qw(-n1 -c1 -N1 -D), $ENV{'TMPDIR'},
845
881
  "--job-name=$job_id.$id.$$",
846
882
  );
883
+
884
+ my $stdbuf = " stdbuf --output=0 --error=0 ";
885
+
847
886
  my $command =
848
887
  "if [ -e $ENV{TASK_WORK} ]; then rm -rf $ENV{TASK_WORK}; fi; "
849
888
  ."mkdir -p $ENV{CRUNCH_TMP} $ENV{JOB_WORK} $ENV{TASK_WORK} $ENV{TASK_KEEPMOUNT} "
@@ -859,7 +898,7 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
859
898
  {
860
899
  my $cidfile = "$ENV{CRUNCH_TMP}/$Jobstep->{arvados_task}->{uuid}-$Jobstep->{failures}.cid";
861
900
  $command .= "crunchstat -cgroup-root=/sys/fs/cgroup -cgroup-parent=docker -cgroup-cid=$cidfile -poll=10000 ";
862
- $command .= "$docker_bin run --rm=true --attach=stdout --attach=stderr --attach=stdin -i --user=crunch --cidfile=$cidfile --sig-proxy ";
901
+ $command .= "$docker_bin run --rm=true --attach=stdout --attach=stderr --attach=stdin -i \Q$dockeruserarg\E --cidfile=$cidfile --sig-proxy ";
863
902
  # We only set memory limits if Docker lets us limit both memory and swap.
864
903
  # Memory limits alone have been supported longer, but subprocesses tend
865
904
  # to get SIGKILL if they exceed that without any swap limit set.
@@ -917,12 +956,22 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
917
956
  }
918
957
  $command .= "--env=\QHOME=$ENV{HOME}\E ";
919
958
  $command .= "\Q$docker_hash\E ";
920
- $command .= "stdbuf --output=0 --error=0 ";
921
- $command .= "perl - $ENV{CRUNCH_SRC}/crunch_scripts/" . $Job->{"script"};
959
+
960
+ if ($Job->{arvados_sdk_version}) {
961
+ $command .= $stdbuf;
962
+ $command .= "perl - \Q$ENV{CRUNCH_SRC}/crunch_scripts/$Job->{script}\E";
963
+ } else {
964
+ $command .= "/bin/sh -c \'mkdir -p \"$ENV{JOB_WORK}\" \"$ENV{TASK_WORK}\" && " .
965
+ "if which stdbuf >/dev/null ; then " .
966
+ " exec $stdbuf \Q$ENV{CRUNCH_SRC}/crunch_scripts/$Job->{script}\E ;" .
967
+ " else " .
968
+ " exec \Q$ENV{CRUNCH_SRC}/crunch_scripts/$Job->{script}\E ;" .
969
+ " fi\'";
970
+ }
922
971
  } else {
923
972
  # Non-docker run
924
973
  $command .= "crunchstat -cgroup-root=/sys/fs/cgroup -poll=10000 ";
925
- $command .= "stdbuf --output=0 --error=0 ";
974
+ $command .= $stdbuf;
926
975
  $command .= "perl - $ENV{CRUNCH_SRC}/crunch_scripts/" . $Job->{"script"};
927
976
  }
928
977
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvados-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20151015194711
4
+ version: 0.1.20151023190001
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arvados Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arvados
@@ -178,7 +178,7 @@ dependencies:
178
178
  - - "<"
179
179
  - !ruby/object:Gem::Version
180
180
  version: 1.0.0
181
- description: Arvados command line tools, git commit ce30948199736d45112ee9103642c22f59f84997
181
+ description: Arvados command line tools, git commit dbf51c6ab20fab93c3f71910c13de9d4a0501bad
182
182
  email: gem-dev@curoverse.com
183
183
  executables:
184
184
  - arv