From e3da789dc489a716e9c1937a4b75e9cfb0f2f680 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Tue, 24 Sep 2024 17:00:01 -0400 Subject: [PATCH 1/3] fix missing default user-agent for jitconfig runner. --- src/Runner.Common/HostContext.cs | 20 ++++++++++++++------ src/Runner.Listener/Runner.cs | 4 ++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Runner.Common/HostContext.cs b/src/Runner.Common/HostContext.cs index 46ea7042d8b..0b2ae0ae979 100644 --- a/src/Runner.Common/HostContext.cs +++ b/src/Runner.Common/HostContext.cs @@ -36,6 +36,7 @@ public interface IHostContext : IDisposable event EventHandler Unloading; void ShutdownRunner(ShutdownReason reason); void WritePerfCounter(string counter); + void LoadDefaultUserAgents(); } public enum StartupType @@ -67,6 +68,7 @@ public sealed class HostContext : EventListener, IObserver, private StartupType _startupType; private string _perfFile; private RunnerWebProxy _webProxy = new(); + private string _hostType = string.Empty; public event EventHandler Unloading; public CancellationToken RunnerShutdownToken => _runnerShutdownTokenSource.Token; @@ -78,6 +80,7 @@ public HostContext(string hostType, string logFile = null) { // Validate args. ArgUtil.NotNullOrEmpty(hostType, nameof(hostType)); + _hostType = hostType; _loadContext = AssemblyLoadContext.GetLoadContext(typeof(HostContext).GetTypeInfo().Assembly); _loadContext.Unloading += LoadContext_Unloading; @@ -196,6 +199,16 @@ public HostContext(string hostType, string logFile = null) } } + if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY"))) + { + _trace.Warning($"Runner is running under insecure mode: HTTPS server certificate validation has been turned off by GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY environment variable."); + } + + LoadDefaultUserAgents(); + } + + public void LoadDefaultUserAgents() + { if (string.IsNullOrEmpty(WebProxy.HttpProxyAddress) && string.IsNullOrEmpty(WebProxy.HttpsProxyAddress)) { _trace.Info($"No proxy settings were found based on environmental variables (http_proxy/https_proxy/HTTP_PROXY/HTTPS_PROXY)"); @@ -205,11 +218,6 @@ public HostContext(string hostType, string logFile = null) _userAgents.Add(new ProductInfoHeaderValue("HttpProxyConfigured", bool.TrueString)); } - if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY"))) - { - _trace.Warning($"Runner is running under insecure mode: HTTPS server certificate validation has been turned off by GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY environment variable."); - } - var credFile = GetConfigFile(WellKnownConfigFile.Credentials); if (File.Exists(credFile)) { @@ -248,7 +256,7 @@ public HostContext(string hostType, string logFile = null) var currentProcess = Process.GetCurrentProcess(); _userAgents.Add(new ProductInfoHeaderValue("Pid", currentProcess.Id.ToString())); _userAgents.Add(new ProductInfoHeaderValue("CreationTime", Uri.EscapeDataString(DateTime.UtcNow.ToString("O")))); - _userAgents.Add(new ProductInfoHeaderValue($"({hostType})")); + _userAgents.Add(new ProductInfoHeaderValue($"({_hostType})")); } public string GetDirectory(WellKnownDirectory directory) diff --git a/src/Runner.Listener/Runner.cs b/src/Runner.Listener/Runner.cs index e2f638522b8..8649af7354f 100644 --- a/src/Runner.Listener/Runner.cs +++ b/src/Runner.Listener/Runner.cs @@ -237,6 +237,10 @@ public async Task ExecuteCommand(CommandSettings command) File.SetAttributes(configFile, File.GetAttributes(configFile) | FileAttributes.Hidden); Trace.Info($"Saved {configContent.Length} bytes to '{configFile}'."); } + + // make sure we have the right user agent data added from the jitconfig + HostContext.LoadDefaultUserAgents(); + VssUtil.InitializeVssClientSettings(HostContext.UserAgents, HostContext.WebProxy); } catch (Exception ex) { From 2f798c255eee794203d2395d670b63938f5d722f Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Tue, 24 Sep 2024 17:06:01 -0400 Subject: [PATCH 2/3] yml --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7eabfb9cfe2..c041cf336a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,7 +75,7 @@ jobs: # Upload runner package tar.gz/zip as artifact - name: Publish Artifact if: github.event_name != 'pull_request' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: runner-package-${{ matrix.runtime }} path: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de94bcc4b26..73dc6477759 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -120,7 +120,7 @@ jobs: # Since each package name is unique, so we don't need to put ${{matrix}} info into artifact name - name: Publish Artifact if: github.event_name != 'pull_request' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: runner-packages path: | @@ -135,7 +135,7 @@ jobs: # Download runner package tar.gz/zip produced by 'build' job - name: Download Artifact - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v4 with: name: runner-packages path: ./ From 8e5dbb42d2c5a45e9591e44857cad945fe1e5609 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Tue, 24 Sep 2024 18:23:15 -0400 Subject: [PATCH 3/3] . --- src/Test/L0/TestHostContext.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Test/L0/TestHostContext.cs b/src/Test/L0/TestHostContext.cs index c44f13f1c4a..124bcd5bd06 100644 --- a/src/Test/L0/TestHostContext.cs +++ b/src/Test/L0/TestHostContext.cs @@ -370,6 +370,11 @@ private void LoadContext_Unloading(AssemblyLoadContext obj) Unloading(this, null); } } + + public void LoadDefaultUserAgents() + { + return; + } } public class DelayEventArgs : EventArgs