From f5eda6a31819e61d9c1d5756c3c1f4bdfbd13fa1 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 20 Jan 2024 10:34:29 -0500 Subject: [PATCH] Fix `HardLinkDmbProvider` using the minimum security level rather than the active one Fixes #1773 --- .../Deployment/HardLinkDmbProvider.cs | 23 +++++++++++++------ .../Components/Watchdog/PosixWatchdog.cs | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Deployment/HardLinkDmbProvider.cs b/src/Tgstation.Server.Host/Components/Deployment/HardLinkDmbProvider.cs index 98a8361e34..09cdfb31d5 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/HardLinkDmbProvider.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/HardLinkDmbProvider.cs @@ -46,12 +46,14 @@ namespace Tgstation.Server.Host.Components.Deployment /// The for the . /// The value of . /// The for the . + /// The launch level. public HardLinkDmbProvider( IDmbProvider baseProvider, IIOManager ioManager, IFilesystemLinkFactory linkFactory, ILogger logger, - GeneralConfiguration generalConfiguration) + GeneralConfiguration generalConfiguration, + DreamDaemonSecurity securityLevel) : base( baseProvider, ioManager, @@ -61,7 +63,7 @@ namespace Tgstation.Server.Host.Components.Deployment cancellationTokenSource = new CancellationTokenSource(); try { - mirroringTask = MirrorSourceDirectory(generalConfiguration.GetCopyDirectoryTaskThrottle(), cancellationTokenSource.Token); + mirroringTask = MirrorSourceDirectory(generalConfiguration.GetCopyDirectoryTaskThrottle(), securityLevel, cancellationTokenSource.Token); } catch { @@ -143,9 +145,10 @@ namespace Tgstation.Server.Host.Components.Deployment /// Mirror the . /// /// The optional maximum number of simultaneous tasks allowed to execute. + /// The launch level. /// The for the operation. /// A resulting in the full path to the mirrored directory. - async Task MirrorSourceDirectory(int? taskThrottle, CancellationToken cancellationToken) + async Task MirrorSourceDirectory(int? taskThrottle, DreamDaemonSecurity securityLevel, CancellationToken cancellationToken) { var stopwatch = Stopwatch.StartNew(); var mirrorGuid = Guid.NewGuid(); @@ -157,7 +160,12 @@ namespace Tgstation.Server.Host.Components.Deployment var dest = IOManager.ResolvePath(mirrorGuid.ToString()); using var semaphore = taskThrottle.HasValue ? new SemaphoreSlim(taskThrottle.Value) : null; - await Task.WhenAll(MirrorDirectoryImpl(src, dest, semaphore, cancellationToken)); + await Task.WhenAll(MirrorDirectoryImpl( + src, + dest, + semaphore, + securityLevel, + cancellationToken)); stopwatch.Stop(); logger.LogDebug( @@ -175,14 +183,15 @@ namespace Tgstation.Server.Host.Components.Deployment /// The source directory path. /// The destination directory path. /// Optional used to limit degree of parallelism. + /// The launch level. /// The for the operation. /// A of s representing the running operations. The first returned is always the necessary call to . /// I genuinely don't know how this will work with symlinked files. Waiting for the issue report I guess. - IEnumerable MirrorDirectoryImpl(string src, string dest, SemaphoreSlim? semaphore, CancellationToken cancellationToken) + IEnumerable MirrorDirectoryImpl(string src, string dest, SemaphoreSlim? semaphore, DreamDaemonSecurity securityLevel, CancellationToken cancellationToken) { var dir = new DirectoryInfo(src); Task? subdirCreationTask = null; - var dreamDaemonWillAcceptOutOfDirectorySymlinks = CompileJob.MinimumSecurityLevel == DreamDaemonSecurity.Trusted; + var dreamDaemonWillAcceptOutOfDirectorySymlinks = securityLevel == DreamDaemonSecurity.Trusted; foreach (var subDirectory in dir.EnumerateDirectories()) { var mirroredName = Path.Combine(dest, subDirectory.Name); @@ -216,7 +225,7 @@ namespace Tgstation.Server.Host.Components.Deployment logger.LogDebug("Recreating symlinked directory {name} as hard links...", subDirectory.Name); var checkingSubdirCreationTask = true; - foreach (var copyTask in MirrorDirectoryImpl(subDirectory.FullName, mirroredName, semaphore, cancellationToken)) + foreach (var copyTask in MirrorDirectoryImpl(subDirectory.FullName, mirroredName, semaphore, securityLevel, cancellationToken)) { if (subdirCreationTask == null) { diff --git a/src/Tgstation.Server.Host/Components/Watchdog/PosixWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/PosixWatchdog.cs index 27874178af..b4c7a74229 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/PosixWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/PosixWatchdog.cs @@ -95,6 +95,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// protected override SwappableDmbProvider CreateSwappableDmbProvider(IDmbProvider dmbProvider) - => new HardLinkDmbProvider(dmbProvider, GameIOManager, LinkFactory, Logger, generalConfiguration); + => new HardLinkDmbProvider(dmbProvider, GameIOManager, LinkFactory, Logger, generalConfiguration, ActiveLaunchParameters.SecurityLevel!.Value); } }