From fabb509316ac67a25928ed18a7786b0609678dce Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 23 Apr 2020 04:24:20 -0400 Subject: [PATCH] Argh --- src/DMAPI/tgs/v5/api.dm | 2 +- .../Components/Instance.cs | 21 ++++++++------- .../Interop/Bridge/RuntimeInformation.cs | 14 +++------- .../Watchdog/ReattachInformation.cs | 12 ++++++--- .../Components/Watchdog/SessionController.cs | 4 +++ .../Watchdog/SessionControllerFactory.cs | 26 ++++++++++++++----- 6 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/DMAPI/tgs/v5/api.dm b/src/DMAPI/tgs/v5/api.dm index 0a6d5aebc8..f1a5c2dea6 100644 --- a/src/DMAPI/tgs/v5/api.dm +++ b/src/DMAPI/tgs/v5/api.dm @@ -83,7 +83,7 @@ return TRUE /datum/tgs_api/v5/OnInitializationComplete() - Bridge(TGS4_COMM_SERVER_PRIMED) + Bridge(DMAPI5_BRIDGE_COMMAND_PRIME) var/tgs4_secret_sleep_offline_sauce = 29051994 var/old_sleep_offline = world.sleep_offline diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs index 2358a73569..f721f9f3ba 100644 --- a/src/Tgstation.Server.Host/Components/Instance.cs +++ b/src/Tgstation.Server.Host/Components/Instance.cs @@ -168,12 +168,16 @@ namespace Tgstation.Server.Host.Components if (progressReporter == null) throw new ArgumentNullException(nameof(progressReporter)); - var ddSettingsTask = databaseContext.DreamDaemonSettings.Where(x => x.InstanceId == metadata.Id).Select(x => new DreamDaemonSettings - { - StartupTimeout = x.StartupTimeout, - }).FirstOrDefaultAsync(cancellationToken); + var ddSettings = await databaseContext.DreamDaemonSettings.Where(x => x.InstanceId == metadata.Id).Select(x => new DreamDaemonSettings + { + StartupTimeout = x.StartupTimeout, + }) + .FirstOrDefaultAsync(cancellationToken) + .ConfigureAwait(false); + if (ddSettings == default) + throw new JobException("Missing DreamDaemonSettings in DB!"); - var compileJobsTask = databaseContext.CompileJobs + var previousCompileJobs = await databaseContext.CompileJobs .Where(x => x.Job.Instance.Id == metadata.Id) .OrderByDescending(x => x.Job.StoppedAt) .Select(x => new Job @@ -182,14 +186,12 @@ namespace Tgstation.Server.Host.Components StartedAt = x.Job.StartedAt }) .Take(10) - .ToListAsync(cancellationToken); + .ToListAsync(cancellationToken) + .ConfigureAwait(false); var dreamMakerSettings = await databaseContext.DreamMakerSettings.Where(x => x.InstanceId == metadata.Id).FirstAsync(cancellationToken).ConfigureAwait(false); if (dreamMakerSettings == default) throw new JobException("Missing DreamMakerSettings in DB!"); - var ddSettings = await ddSettingsTask.ConfigureAwait(false); - if (ddSettings == default) - throw new JobException("Missing DreamDaemonSettings in DB!"); Task repositorySettingsTask = null; string repoOwner = null; @@ -232,7 +234,6 @@ namespace Tgstation.Server.Host.Components } TimeSpan? averageSpan = null; - var previousCompileJobs = await compileJobsTask.ConfigureAwait(false); if(previousCompileJobs.Count != 0) { var totalSpan = TimeSpan.Zero; diff --git a/src/Tgstation.Server.Host/Components/Interop/Bridge/RuntimeInformation.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/RuntimeInformation.cs index 686c0f3af4..284f1cdcb1 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Bridge/RuntimeInformation.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/RuntimeInformation.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using Tgstation.Server.Api.Models; using Tgstation.Server.Host.Core; -using Tgstation.Server.Host.Security; using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Interop.Bridge @@ -13,11 +12,6 @@ namespace Tgstation.Server.Host.Components.Interop.Bridge /// public sealed class RuntimeInformation : ChatUpdate { - /// - /// The code used by the server to authenticate command Topics - /// - public string AccessIdentifier { get; } - /// /// The . /// @@ -57,31 +51,31 @@ namespace Tgstation.Server.Host.Components.Interop.Bridge /// Initializes a new instance of the . /// /// The to use. - /// The used to generate the value of . /// The used to set the value of . /// An used to construct the value of . /// The s for the . /// The used to set . /// The value of . /// The value of . + /// The value of . public RuntimeInformation( IAssemblyInformationProvider assemblyInformationProvider, - ICryptographySuite cryptographySuite, IServerPortProvider serverPortProvider, IEnumerable testMerges, IEnumerable chatChannels, Api.Models.Instance instance, Api.Models.Internal.RevisionInformation revision, - DreamDaemonSecurity? securityLevel) + DreamDaemonSecurity? securityLevel, + bool apiValidateOnly) : base(chatChannels) { ServerVersion = assemblyInformationProvider?.Version ?? throw new ArgumentNullException(nameof(assemblyInformationProvider)); - AccessIdentifier = cryptographySuite?.GetSecureString() ?? throw new ArgumentNullException(nameof(cryptographySuite)); ServerPort = serverPortProvider?.HttpApiPort ?? throw new ArgumentNullException(nameof(serverPortProvider)); TestMerges = testMerges?.ToList() ?? throw new ArgumentNullException(nameof(testMerges)); InstanceName = instance?.Name ?? throw new ArgumentNullException(nameof(instance)); Revision = revision ?? throw new ArgumentNullException(nameof(revision)); SecurityLevel = securityLevel; + ApiValidateOnly = apiValidateOnly; } } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs b/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs index bffdfa976d..fde826dc75 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs @@ -23,16 +23,16 @@ namespace Tgstation.Server.Host.Components.Watchdog public RuntimeInformation RuntimeInformation { get; private set; } /// - public override string AccessIdentifier + public override DreamDaemonSecurity? LaunchSecurityLevel { - get => RuntimeInformation.AccessIdentifier ?? base.AccessIdentifier; + get => RuntimeInformation.SecurityLevel ?? base.LaunchSecurityLevel; set => throw new NotSupportedException(); } /// - public override DreamDaemonSecurity? LaunchSecurityLevel + public override string AccessIdentifier { - get => RuntimeInformation.SecurityLevel ?? base.LaunchSecurityLevel; + get => base.AccessIdentifier; set => throw new NotSupportedException(); } @@ -47,12 +47,14 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The value of . /// The used to get the . /// The value of . + /// The value of . /// The value of . /// The value of . internal ReattachInformation( IDmbProvider dmb, IProcess process, RuntimeInformation runtimeInformation, + string accessIdentifier, ushort port, bool isPrimary) { @@ -62,6 +64,8 @@ namespace Tgstation.Server.Host.Components.Watchdog if (!runtimeInformation.SecurityLevel.HasValue) throw new ArgumentException("runtimeInformation must have a valid SecurityLevel!", nameof(runtimeInformation)); + base.AccessIdentifier = accessIdentifier ?? throw new ArgumentNullException(nameof(accessIdentifier)); + base.LaunchSecurityLevel = runtimeInformation.SecurityLevel.Value; Port = port; IsPrimary = isPrimary; diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs index 193ceef691..c38616f24c 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs @@ -497,6 +497,7 @@ namespace Tgstation.Server.Host.Components.Watchdog parameters.AccessIdentifier = reattachInformation.AccessIdentifier; var json = JsonConvert.SerializeObject(parameters, DMApiConstants.SerializerSettings); + logger.LogTrace("Topic request: {0}", json); try { var commandString = String.Format(CultureInfo.InvariantCulture, @@ -512,6 +513,9 @@ namespace Tgstation.Server.Host.Components.Watchdog commandString, cancellationToken).ConfigureAwait(false); + if (topicReturn != null) + logger.LogTrace("Topic response: {0}", topicReturn); + try { var result = JsonConvert.DeserializeObject(topicReturn, DMApiConstants.SerializerSettings); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs index 577472cabb..1614ec1f11 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs @@ -192,11 +192,11 @@ namespace Tgstation.Server.Host.Components.Watchdog if (launchParameters.SecurityLevel == DreamDaemonSecurity.Trusted) await byondLock.TrustDmbPath(ioManager.ConcatPath(basePath, dmbProvider.DmbName), cancellationToken).ConfigureAwait(false); - var runtimeInformation = CreateRuntimeInformation(dmbProvider, chatTrackingContext, launchParameters.SecurityLevel.Value); + var accessIdentifier = cryptographySuite.GetSecureString(); // set command line options // more sanitization here cause it uses the same scheme - var parameters = $"{DMApiConstants.ParamApiVersion}={byondTopicSender.SanitizeString(DMApiConstants.Version.Semver())}&{byondTopicSender.SanitizeString(DMApiConstants.ParamServerPort)}={serverPortProvider.HttpApiPort}&{byondTopicSender.SanitizeString(DMApiConstants.ParamAccessIdentifier)}={runtimeInformation.AccessIdentifier}"; + var parameters = $"{DMApiConstants.ParamApiVersion}={byondTopicSender.SanitizeString(DMApiConstants.Version.Semver())}&{byondTopicSender.SanitizeString(DMApiConstants.ParamServerPort)}={serverPortProvider.HttpApiPort}&{byondTopicSender.SanitizeString(DMApiConstants.ParamAccessIdentifier)}={accessIdentifier}"; var visibility = apiValidate ? "invisible" : "public"; @@ -218,11 +218,17 @@ namespace Tgstation.Server.Host.Components.Watchdog { networkPromptReaper.RegisterProcess(process); - // return the session controller for it + var runtimeInformation = CreateRuntimeInformation( + dmbProvider, + chatTrackingContext, + launchParameters.SecurityLevel.Value, + apiValidate); + var reattachInformation = new ReattachInformation( dmbProvider, process, runtimeInformation, + accessIdentifier, portToUse.Value, primaryDirectory); @@ -283,7 +289,11 @@ namespace Tgstation.Server.Host.Components.Watchdog try { networkPromptReaper.RegisterProcess(process); - var runtimeInformation = CreateRuntimeInformation(reattachInformation.Dmb, chatTrackingContext, null); + var runtimeInformation = CreateRuntimeInformation( + reattachInformation.Dmb, + chatTrackingContext, + null, + false); reattachInformation.SetRuntimeInformation(runtimeInformation); var controller = new SessionController( @@ -329,11 +339,13 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The . /// The . /// The level if any. + /// The value of . /// A new . RuntimeInformation CreateRuntimeInformation( IDmbProvider dmbProvider, IChatTrackingContext chatTrackingContext, - DreamDaemonSecurity? securityLevel) + DreamDaemonSecurity? securityLevel, + bool apiValidateOnly) { var revisionInfo = new Api.Models.Internal.RevisionInformation { @@ -350,13 +362,13 @@ namespace Tgstation.Server.Host.Components.Watchdog return new RuntimeInformation( assemblyInformationProvider, - cryptographySuite, serverPortProvider, testMerges, chatTrackingContext.Channels, instance, revisionInfo, - securityLevel); + securityLevel, + apiValidateOnly); } } }