From 88ee16fb021312d282d5207a5585e46d2eefe7b5 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Mon, 23 May 2022 12:07:38 +0200 Subject: [PATCH] Save original, pre-parsed string from workflow input for the user's custom volume mounts (#1889) * Save pre parsed string from workflow input for volume mounts that have one * Use property * Use named params --- src/Runner.Worker/Container/ContainerInfo.cs | 35 ++++++++++++------- .../ContainerOperationProvider.cs | 7 ++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Runner.Worker/Container/ContainerInfo.cs b/src/Runner.Worker/Container/ContainerInfo.cs index 2173922b1..3b1b46609 100644 --- a/src/Runner.Worker/Container/ContainerInfo.cs +++ b/src/Runner.Worker/Container/ContainerInfo.cs @@ -1,16 +1,16 @@ using System; using System.Collections.Generic; using System.IO; -using GitHub.Runner.Common.Util; using GitHub.Runner.Common; using GitHub.Runner.Sdk; using Pipelines = GitHub.DistributedTask.Pipelines; +using System.Collections.ObjectModel; +using System.Linq; namespace GitHub.Runner.Worker.Container { public class ContainerInfo { - private IDictionary _userMountVolumes; private List _mountVolumes; private IDictionary _userPortMappings; private List _portMappings; @@ -68,8 +68,7 @@ namespace GitHub.Runner.Worker.Container { foreach (var volume in container.Volumes) { - UserMountVolumes[volume] = volume; - MountVolumes.Add(new MountVolume(volume)); + MountVolumes.Add(new MountVolume(volume, isUserProvided: true)); } } @@ -104,19 +103,20 @@ namespace GitHub.Runner.Worker.Container return _environmentVariables; } } - - public IDictionary UserMountVolumes + public ReadOnlyCollection UserMountVolumes { get { - if (_userMountVolumes == null) - { - _userMountVolumes = new Dictionary(); - } - return _userMountVolumes; + return MountVolumes.Where(v => !string.IsNullOrEmpty(v.UserProvidedValue)).ToList().AsReadOnly(); + } + } + public ReadOnlyCollection SystemMountVolumes + { + get + { + return MountVolumes.Where(v => string.IsNullOrEmpty(v.UserProvidedValue)).ToList().AsReadOnly(); } } - public List MountVolumes { get @@ -260,18 +260,27 @@ namespace GitHub.Runner.Worker.Container public class MountVolume { + public string UserProvidedValue { get; set; } public MountVolume(string sourceVolumePath, string targetVolumePath, bool readOnly = false) { this.SourceVolumePath = sourceVolumePath; this.TargetVolumePath = targetVolumePath; this.ReadOnly = readOnly; } - public MountVolume(string fromString) { ParseVolumeString(fromString); } + public MountVolume(string fromString, bool isUserProvided) + { + ParseVolumeString(fromString); + if (isUserProvided) + { + UserProvidedValue = fromString; + } + } + private void ParseVolumeString(string volume) { var volumeSplit = volume.Split(":"); diff --git a/src/Runner.Worker/ContainerOperationProvider.cs b/src/Runner.Worker/ContainerOperationProvider.cs index 62ef1df47..a44b2547d 100644 --- a/src/Runner.Worker/ContainerOperationProvider.cs +++ b/src/Runner.Worker/ContainerOperationProvider.cs @@ -192,13 +192,12 @@ namespace GitHub.Runner.Worker { Trace.Info($"User provided port: {port.Value}"); } - foreach (var volume in container.UserMountVolumes) + foreach (var mount in container.UserMountVolumes) { - Trace.Info($"User provided volume: {volume.Value}"); - var mount = new MountVolume(volume.Value); + Trace.Info($"User provided volume: {mount.UserProvidedValue}"); if (string.Equals(mount.SourceVolumePath, "/", StringComparison.OrdinalIgnoreCase)) { - executionContext.Warning($"Volume mount {volume.Value} is going to mount '/' into the container which may cause file ownership change in the entire file system and cause Actions Runner to lose permission to access the disk."); + executionContext.Warning($"Volume mount {mount.UserProvidedValue} is going to mount '/' into the container which may cause file ownership change in the entire file system and cause Actions Runner to lose permission to access the disk."); } }