1414 * limitations under the License.
1515 */
1616
17+ using System . Diagnostics ;
1718using System . Globalization ;
18- using Amazon . Runtime . Internal . Transform ;
1919using Ardalis . GuardClauses ;
2020using Docker . DotNet ;
2121using Docker . DotNet . Models ;
@@ -364,9 +364,14 @@ private CreateContainerParameters BuildContainerSpecification(IList<ContainerVol
364364 {
365365 Runtime = Strings . RuntimeNvidia ,
366366 Mounts = volumeMounts ,
367- }
367+ } ,
368368 } ;
369369
370+ if ( Event . TaskPluginArguments . ContainsKey ( Keys . User ) )
371+ {
372+ parameters . User = Event . TaskPluginArguments [ Keys . User ] ;
373+ }
374+
370375 return parameters ;
371376 }
372377
@@ -406,6 +411,7 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
406411 // eg: /monai/input
407412 var volumeMount = new ContainerVolumeMount ( input , Event . TaskPluginArguments [ input . Name ] , inputHostDirRoot , inputContainerDirRoot ) ;
408413 volumeMounts . Add ( volumeMount ) ;
414+ _logger . InputVolumeMountAdded ( inputHostDirRoot , inputContainerDirRoot ) ;
409415
410416 // For each file, download from bucket and store in Task Manager Container.
411417 foreach ( var obj in objects )
@@ -424,6 +430,8 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
424430 }
425431 }
426432
433+ SetPermission ( containerPath ) ;
434+
427435 return volumeMounts ;
428436 }
429437
@@ -436,7 +444,10 @@ private ContainerVolumeMount SetupIntermediateVolume()
436444
437445 Directory . CreateDirectory ( containerPath ) ;
438446
439- return new ContainerVolumeMount ( Event . IntermediateStorage , Event . TaskPluginArguments [ Keys . WorkingDirectory ] , hostPath , containerPath ) ;
447+ var volumeMount = new ContainerVolumeMount ( Event . IntermediateStorage , Event . TaskPluginArguments [ Keys . WorkingDirectory ] , hostPath , containerPath ) ;
448+ _logger . IntermediateVolumeMountAdded ( hostPath , containerPath ) ;
449+ SetPermission ( containerPath ) ;
450+ return volumeMount ;
440451 }
441452
442453 return default ! ;
@@ -465,11 +476,32 @@ private List<ContainerVolumeMount> SetupOutputs()
465476 Directory . CreateDirectory ( containerPath ) ;
466477
467478 volumeMounts . Add ( new ContainerVolumeMount ( output , Event . TaskPluginArguments [ output . Name ] , hostPath , containerPath ) ) ;
479+ _logger . OutputVolumeMountAdded ( hostPath , containerPath ) ;
468480 }
469481
482+ SetPermission ( containerRootPath ) ;
483+
470484 return volumeMounts ;
471485 }
472486
487+ private void SetPermission ( string path )
488+ {
489+ if ( Event . TaskPluginArguments . ContainsKey ( Keys . User ) )
490+ {
491+ if ( ! System . OperatingSystem . IsWindows ( ) )
492+ {
493+ var process = Process . Start ( "chown" , $ "-R { Event . TaskPluginArguments [ Keys . User ] } { path } ") ;
494+ process . WaitForExit ( ) ;
495+
496+ if ( process . ExitCode != 0 )
497+ {
498+ _logger . ErrorSettingDirectoryPermission ( path , Event . TaskPluginArguments [ Keys . User ] ) ;
499+ throw new SetPermissionException ( $ "chown command exited with code { process . ExitCode } ") ;
500+ }
501+ }
502+ }
503+ }
504+
473505 protected override void Dispose ( bool disposing )
474506 {
475507 if ( ! DisposedValue && disposing )
0 commit comments