From ac31fd10b26b89b21e6294c0ef7050fce1c498bf Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Wed, 19 Jan 2022 10:31:17 -0500 Subject: [PATCH] Introduce GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY=1 to skip SSL cert verification for the runner. (#1616) --- src/Runner.Common/HostContext.cs | 7 ++++++- src/Runner.Common/HttpClientHandlerFactory.cs | 10 +++++++++- src/Runner.Sdk/Util/VssUtil.cs | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Runner.Common/HostContext.cs b/src/Runner.Common/HostContext.cs index ff3ddf8e6..643c61c81 100644 --- a/src/Runner.Common/HostContext.cs +++ b/src/Runner.Common/HostContext.cs @@ -193,6 +193,11 @@ namespace GitHub.Runner.Common _trace.Info($"No proxy settings were found based on environmental variables (http_proxy/https_proxy/HTTP_PROXY/HTTPS_PROXY)"); } + if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY"))) + { + _trace.Warning($"Runner is running under insecure mode: HTTPS server certifcate validation has been turned off by GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY environment variable."); + } + var credFile = GetConfigFile(WellKnownConfigFile.Credentials); if (File.Exists(credFile)) { @@ -350,7 +355,7 @@ namespace GitHub.Runner.Common GetDirectory(WellKnownDirectory.Root), ".setup_info"); break; - + case WellKnownConfigFile.Telemetry: path = Path.Combine( GetDirectory(WellKnownDirectory.Diag), diff --git a/src/Runner.Common/HttpClientHandlerFactory.cs b/src/Runner.Common/HttpClientHandlerFactory.cs index f507dd7af..010bb0396 100644 --- a/src/Runner.Common/HttpClientHandlerFactory.cs +++ b/src/Runner.Common/HttpClientHandlerFactory.cs @@ -1,3 +1,4 @@ +using System; using System.Net.Http; using GitHub.Runner.Sdk; @@ -13,7 +14,14 @@ namespace GitHub.Runner.Common { public HttpClientHandler CreateClientHandler(RunnerWebProxy webProxy) { - return new HttpClientHandler() { Proxy = webProxy }; + var client = new HttpClientHandler() { Proxy = webProxy }; + + if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY"))) + { + client.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; + } + + return client; } } } \ No newline at end of file diff --git a/src/Runner.Sdk/Util/VssUtil.cs b/src/Runner.Sdk/Util/VssUtil.cs index 3b4e1b3ed..e6b6f9f83 100644 --- a/src/Runner.Sdk/Util/VssUtil.cs +++ b/src/Runner.Sdk/Util/VssUtil.cs @@ -27,6 +27,11 @@ namespace GitHub.Runner.Sdk VssClientHttpRequestSettings.Default.UserAgent = headerValues; VssHttpMessageHandler.DefaultWebProxy = proxy; + + if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TLS_NO_VERIFY"))) + { + VssClientHttpRequestSettings.Default.ServerCertificateValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; + } } public static VssConnection CreateConnection(Uri serverUri, VssCredentials credentials, IEnumerable additionalDelegatingHandler = null, TimeSpan? timeout = null)