From 0e7ca9aedb2cf4ed792303c86b0598a43e773aa1 Mon Sep 17 00:00:00 2001 From: Matisse Hack Date: Tue, 21 Mar 2023 12:04:50 -0700 Subject: [PATCH] Fix JIT configurations on Windows (#2497) * Fix JIT configurations on Windows * Update src/Runner.Listener/Runner.cs --- src/Runner.Listener/Runner.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Runner.Listener/Runner.cs b/src/Runner.Listener/Runner.cs index 30d60b2fc..c727f1b38 100644 --- a/src/Runner.Listener/Runner.cs +++ b/src/Runner.Listener/Runner.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; +using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -210,10 +211,16 @@ namespace GitHub.Runner.Listener foreach (var config in jitConfig) { var configFile = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), config.Key); - var configContent = Encoding.UTF8.GetString(Convert.FromBase64String(config.Value)); - File.WriteAllText(configFile, configContent, Encoding.UTF8); + var configContent = Convert.FromBase64String(config.Value); +#if OS_WINDOWS + if (configFile == HostContext.GetConfigFile(WellKnownConfigFile.RSACredentials)) + { + configContent = ProtectedData.Protect(configContent, null, DataProtectionScope.LocalMachine); + } +#endif + File.WriteAllBytes(configFile, configContent); File.SetAttributes(configFile, File.GetAttributes(configFile) | FileAttributes.Hidden); - Trace.Info($"Save {configContent.Length} chars to '{configFile}'."); + Trace.Info($"Saved {configContent.Length} bytes to '{configFile}'."); } } catch (Exception ex)