Beispiel #1
0
        public Container(
            string id,
            string handle,
            IContainerUser user,
            IContainerDirectory directory,
            IContainerPropertyService propertyService,
            ILocalTcpPortManager tcpPortManager,
            JobObject jobObject,
            DiskQuotaControl diskQuotaControl,
            IProcessRunner processRunner,
            IProcessRunner constrainedProcessRunner,
            ProcessHelper processHelper,
            Dictionary<string, string> defaultEnvironment,
            ContainerHostDependencyHelper dependencyHelper
            )
        {
            this.id = id;
            this.handle = handle;
            this.user = user;
            this.directory = directory;
            this.propertyService = propertyService;
            this.tcpPortManager = tcpPortManager;
            this.jobObject = jobObject;
            this.diskQuotaControl = diskQuotaControl;
            this.processRunner = processRunner;
            this.constrainedProcessRunner = constrainedProcessRunner;
            this.processHelper = processHelper;
            this.dependencyHelper = dependencyHelper;
            this.defaultEnvironment = defaultEnvironment ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            this.currentState = ContainerState.Active;
        }
Beispiel #2
0
        public Container(
            string id,
            string handle,
            IContainerUser user,
            IContainerDirectory directory,
            IContainerPropertyService propertyService,
            ILocalTcpPortManager tcpPortManager,
            JobObject jobObject,
            DiskQuotaControl diskQuotaControl,
            IProcessRunner processRunner,
            IProcessRunner constrainedProcessRunner,
            ProcessHelper processHelper,
            Dictionary <string, string> defaultEnvironment,
            ContainerHostDependencyHelper dependencyHelper
            )
        {
            this.id                       = id;
            this.handle                   = handle;
            this.user                     = user;
            this.directory                = directory;
            this.propertyService          = propertyService;
            this.tcpPortManager           = tcpPortManager;
            this.jobObject                = jobObject;
            this.diskQuotaControl         = diskQuotaControl;
            this.processRunner            = processRunner;
            this.constrainedProcessRunner = constrainedProcessRunner;
            this.processHelper            = processHelper;
            this.dependencyHelper         = dependencyHelper;
            this.defaultEnvironment       = defaultEnvironment ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            this.currentState = ContainerState.Active;
        }
        public void CreateBindMounts(BindMount[] bindMounts, IContainerUser containerUser)
        {
            foreach (var bindMount in bindMounts)
            {
                var mappedDestinationPath = MapUserPath(bindMount.DestinationPath);
                var parentDir             = Directory.GetParent(mappedDestinationPath).FullName;

                if (CanonicalizePath(parentDir, ensureTrailingSlash: true) != MapUserPath(""))
                {
                    fileSystem.CreateDirectory(parentDir, GetContainerUserAccess(containerUser.UserName, FileAccess.ReadWrite));
                }

                var cleanedSourcePath = bindMount.SourcePath.Replace("/", "\\");
                fileSystem.Symlink(mappedDestinationPath, cleanedSourcePath);
                fileSystem.AddDirectoryAccess(mappedDestinationPath, FileAccess.Read, containerUser.UserName);

                fileSystem.AddDirectoryAccess(cleanedSourcePath, FileAccess.Read, containerUser.UserName);

                while (fileSystem.DirIsSymlink(cleanedSourcePath))
                {
                    var symlinkDest = fileSystem.GetSymlinkTarget(cleanedSourcePath);
                    fileSystem.AddDirectoryAccess(symlinkDest, FileAccess.Read, containerUser.UserName);
                    cleanedSourcePath = symlinkDest;
                }
            }
        }
Beispiel #4
0
 public IContainer CreateContainer(string id,
                                   string handle,
                                   IContainerUser user,
                                   IContainerDirectory directory,
                                   IContainerPropertyService propertyService,
                                   ILocalTcpPortManager tcpPortManager,
                                   JobObject jobObject,
                                   IContainerDiskQuota containerDiskQuota,
                                   IProcessRunner processRunner,
                                   IProcessRunner constrainedProcessRunner,
                                   ProcessHelper processHelper,
                                   Dictionary <string, string> defaultEnvironment,
                                   ContainerHostDependencyHelper dependencyHelper,
                                   BindMount[] bindMounts)
 {
     return(new Container(
                id,
                handle,
                user,
                directory,
                propertyService,
                tcpPortManager,
                jobObject,
                containerDiskQuota,
                processRunner,
                constrainedProcessRunner,
                processHelper,
                defaultEnvironment,
                dependencyHelper,
                bindMounts
                ));
 }
 public void CreateBindMounts(BindMount[] bindMounts, IContainerUser containerUser)
 {
     foreach (var bindMount in bindMounts)
     {
         var mappedDestinationPath = MapUserPath(bindMount.DestinationPath);
         fileSystem.CreateDirectory(mappedDestinationPath, GetContainerUserAccess(containerUser.UserName, FileAccess.ReadWrite));
         fileSystem.Copy(bindMount.SourcePath, mappedDestinationPath);
     }
 }
Beispiel #6
0
 public void CreateBindMounts(BindMount[] bindMounts, IContainerUser containerUser)
 {
     foreach (var bindMount in bindMounts)
     {
         var mappedDestinationPath = MapUserPath(bindMount.DestinationPath);
         fileSystem.CreateDirectory(mappedDestinationPath, GetContainerUserAccess(containerUser.UserName, FileAccess.ReadWrite));
         fileSystem.Copy(bindMount.SourcePath, mappedDestinationPath);
     }
 }
        public void CreateSubdirectories(IContainerUser containerUser)
        {
            var containerPrivatePath = Path.Combine(containerPath, PrivateRelativePath);
            var containerUserPath = Path.Combine(containerPath, UserRelativePath);
            var containerBinPath = Path.Combine(containerPath, BinRelativePath);

            fileSystem.CreateDirectory(containerPath, GetContainerUserAccess(containerUser.UserName, FileAccess.Read));
            fileSystem.CreateDirectory(containerPrivatePath, GetContainerDefaultAccess());
            fileSystem.CreateDirectory(containerBinPath, GetContainerUserAccess(containerUser.UserName, FileAccess.Read));
            fileSystem.CreateDirectory(containerUserPath, GetContainerUserAccess(containerUser.UserName, FileAccess.ReadWrite));
        }
Beispiel #8
0
        public void CreateSubdirectories(IContainerUser containerUser)
        {
            var containerPrivatePath = Path.Combine(containerPath, PrivateRelativePath);
            var containerUserPath    = Path.Combine(containerPath, UserRelativePath);
            var containerBinPath     = Path.Combine(containerPath, BinRelativePath);

            fileSystem.CreateDirectory(containerPath, GetContainerUserAccess(containerUser.UserName, FileAccess.Read));
            fileSystem.CreateDirectory(containerPrivatePath, GetContainerDefaultAccess());
            fileSystem.CreateDirectory(containerBinPath, GetContainerUserAccess(containerUser.UserName, FileAccess.Read));
            fileSystem.CreateDirectory(containerUserPath, GetContainerUserAccess(containerUser.UserName, FileAccess.ReadWrite));
        }
        public void DeleteBindMounts(BindMount[] bindMounts, IContainerUser containerUser)
        {
            foreach (var bindMount in bindMounts)
            {
                var cleanedSourcePath = bindMount.SourcePath.Replace("/", "\\");
                fileSystem.RemoveDirectoryAccess(cleanedSourcePath, containerUser.UserName);

                while (fileSystem.DirIsSymlink(cleanedSourcePath))
                {
                    var symlinkDest = fileSystem.GetSymlinkTarget(cleanedSourcePath);
                    fileSystem.RemoveDirectoryAccess(symlinkDest, containerUser.UserName);
                    cleanedSourcePath = symlinkDest;
                }
            }
        }
        public ProcessCommandTests()
        {
            // Create a temporary directory to use as the container root
            tempDir = CreateTempDir();

            handle = new ContainerHandle("TestContainerHandle");
            user   = Substitute.For <IContainerUser>();
            user.UserName.Returns("TestUser");
            user.GetCredential().ReturnsForAnyArgs(new System.Net.NetworkCredential("TestUser", "TestUserPassword"));

            directory = Substitute.For <IContainerDirectory>();
            process   = Substitute.For <IProcess>();
            container = Substitute.For <IContainer>();

            container.ContainerDirectoryPath.Returns(tempDir);
        }
            public IContainer CreateContainer(string id,
                                              string handle,
                                              IContainerUser user,
                                              IContainerDirectory directory,
                                              IContainerPropertyService propertyService,
                                              ILocalTcpPortManager tcpPortManager,
                                              JobObject jobObject,
                                              IContainerDiskQuota containerDiskQuota,
                                              IProcessRunner processRunner,
                                              IProcessRunner constrainedProcessRunner,
                                              ProcessHelper processHelper,
                                              Dictionary <string, string> defaultEnvironment,
                                              ContainerHostDependencyHelper dependencyHelper,
                                              BindMount[] bindMounts)
            {
                if (handle == "KnownBadHandle")
                {
                    var badContainer = Substitute.For <IContainer>();
                    badContainer.Handle.Returns("KnownBadHandle");
                    badContainer.When(x => x.Destroy()).Do(x => { if (destroyCount++ == 0)
                                                                  {
                                                                      throw new Exception();
                                                                  }
                                                           });

                    return(badContainer);
                }
                else
                {
                    return(new Container(
                               id,
                               handle,
                               user,
                               directory,
                               propertyService,
                               tcpPortManager,
                               jobObject,
                               containerDiskQuota,
                               processRunner,
                               constrainedProcessRunner,
                               processHelper,
                               defaultEnvironment,
                               dependencyHelper,
                               bindMounts
                               ));
                }
            }
 public CreateSubdirectories()
 {
     ContainerUser = Substitute.For <IContainerUser>();
     ContainerUser.UserName.Returns("username");
 }
 public Destroy()
 {
     ContainerUser = Substitute.For <IContainerUser>();
     ContainerUser.UserName.Returns("username");
 }