diff --git a/.env.example b/.env.example index 109f75a..90f1d1a 100644 --- a/.env.example +++ b/.env.example @@ -57,6 +57,12 @@ WEBUI_PORT=13080 BACKEND_PORT=19080 NATS_WS_PORT=19222 +# ── Container user ───────────────────────────────────────────────────────── +# The backend/webui containers run as this user; remap when bind-mount +# ownership needs it. +PUID=1000 +PGID=1000 + # ── Public edge ──────────────────────────────────────────────────────────── # The single public https URL served by your existing reverse proxy. PUBLIC_SERVER_URL=https://control.example.com diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 0a995d2..e0d219a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -241,10 +241,21 @@ jobs: env: VERSION: ${{ steps.ver.outputs.version }} PREFIX: ${{ steps.ver.outputs.prefix }} + SOURCE_URL: ${{ github.server_url }}/${{ github.repository }} run: | set -e - docker build -f src/Infra/backend/Dockerfile --build-arg UNIFIED_VERSION="$VERSION" -t "${PREFIX}-backend:$VERSION" . - docker build -f src/Infra/webui/Dockerfile --build-arg UNIFIED_VERSION="$VERSION" -t "${PREFIX}-webui:$VERSION" . + GIT_COMMIT="$(git rev-parse HEAD)" + GIT_COMMIT_SHORT="$(git rev-parse --short HEAD)" + BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + for svc in backend webui; do + docker build -f "src/Infra/${svc}/Dockerfile" \ + --build-arg UNIFIED_VERSION="$VERSION" \ + --build-arg GIT_COMMIT="$GIT_COMMIT" \ + --build-arg GIT_COMMIT_SHORT="$GIT_COMMIT_SHORT" \ + --build-arg BUILD_DATE="$BUILD_DATE" \ + --build-arg SOURCE_URL="$SOURCE_URL" \ + -t "${PREFIX}-${svc}:$VERSION" . + done - name: Tag and push env: diff --git a/README.md b/README.md index 7f928a6..f2f464e 100644 --- a/README.md +++ b/README.md @@ -452,16 +452,19 @@ Caddy / Nginx UI / nginx can bind or trust the files directly and stay current. On **Linux/macOS/containers** the PEM files are the primary store (`TLS_CERT_DIR` overrides; keep it on a persisted volume in containers). -**Agents** follow automatically: when the server serves the self-signed -chain directly (no proxy in between), the Add-Device one-liners and install -scripts include TLS skip-verify and set the agent's `TlsSkipVerify` registry -value (`/etc/executer/agent.json` on unix) so enrollment and the persistent -connection work out of the box — still fully encrypted. The value is +**Agents** skip verification only when the operator says so — a +self-signed server that later gains a proxy with a real certificate must +not leave agents skipping validation needlessly. The Add-Device modal (and +the Settings token panel) carry a **Skip TLS verification** checkbox, +pre-selected only while the server is serving its self-signed chain +directly; when ticked, the one-liner and the served install script include +the skip bits and set the agent's `TlsSkipVerify` registry value +(`/etc/executer/agent.json` on unix) — still fully encrypted. The value is GPO-manageable (`Skip TLS certificate verification` in the ADMX template, policy key beats local config), `configure --skip-tls-verify` sets it by hand, and the agent MSI wizard has a matching checkbox — unchecked by -default (`SKIPTLSVERIFY=1` silently). Behind a proxy with a real -certificate none of this engages — agents validate normally. +default (`SKIPTLSVERIFY=1` silently). Left unticked, agents validate +normally. --- @@ -550,6 +553,7 @@ msiexec /i Agent.msi /qn SERVERURL=https://control.example.com BOOTSTRAPTOKEN= [--token ] [--skip-tls-verify]"); + Console.Error.WriteLine("Usage: configure --url [--token ] [--proxy ] [--skip-tls-verify]"); return 1; } @@ -148,6 +152,13 @@ public static class AgentCli registry.WriteString(Branding.AgentRegistryKey, Agent.Configuration.AgentConfigurationKeys.BootstrapToken, token); } + if (proxy is not null) + { + // Explicit outbound proxy; without it the system/environment + // proxy is honored — default credentials either way. + registry.WriteString(Branding.AgentRegistryKey, Agent.Configuration.AgentConfigurationKeys.ProxyUrl, proxy); + } + if (skipTlsVerify) { // For servers on the managed self-signed chain without a proxy: diff --git a/src/Agent/Configuration/AgentConfiguration.cs b/src/Agent/Configuration/AgentConfiguration.cs index a683a21..8e3e824 100644 --- a/src/Agent/Configuration/AgentConfiguration.cs +++ b/src/Agent/Configuration/AgentConfiguration.cs @@ -19,6 +19,7 @@ public sealed class AgentConfiguration public required ConfigurationValue AllowRemoteShell { get; init; } public required ConfigurationValue AllowScriptExecution { get; init; } public required ConfigurationValue TlsSkipVerify { get; init; } + public required ConfigurationValue ProxyUrl { get; init; } /// Parsed ServerURL; null when unset or invalid. public ServerUrl? ServerUrl => @@ -48,6 +49,7 @@ public sealed class AgentConfigurationLoader(IRegistryStore registry, bool allow AllowRemoteShell = ResolveBool(AgentConfigurationKeys.AllowRemoteShell, defaultValue: false), AllowScriptExecution = ResolveBool(AgentConfigurationKeys.AllowScriptExecution, defaultValue: true), TlsSkipVerify = ResolveBool(AgentConfigurationKeys.TlsSkipVerify, defaultValue: false), + ProxyUrl = ResolveString(AgentConfigurationKeys.ProxyUrl, AgentConfigurationKeys.EnvironmentNames.ProxyUrl, null), }; } diff --git a/src/Agent/Configuration/AgentConfigurationKeys.cs b/src/Agent/Configuration/AgentConfigurationKeys.cs index 796368f..819389a 100644 --- a/src/Agent/Configuration/AgentConfigurationKeys.cs +++ b/src/Agent/Configuration/AgentConfigurationKeys.cs @@ -20,12 +20,20 @@ public static class AgentConfigurationKeys /// public const string TlsSkipVerify = "TlsSkipVerify"; + /// + /// Explicit outbound proxy URL (http://proxy:8080). Unset, the agent + /// honors the system/environment proxy; either way it authenticates to + /// the proxy with the process account's default credentials. + /// + public const string ProxyUrl = "ProxyUrl"; + /// Development-only environment variable names (never override GPO). public static class EnvironmentNames { public const string ServerUrl = "AGENT_SERVER_URL"; public const string BootstrapToken = "AGENT_BOOTSTRAP_TOKEN"; public const string LogLevel = "AGENT_LOG_LEVEL"; + public const string ProxyUrl = "AGENT_PROXY_URL"; } } diff --git a/src/Agent/Configuration/ProxySetup.cs b/src/Agent/Configuration/ProxySetup.cs new file mode 100644 index 0000000..717bc60 --- /dev/null +++ b/src/Agent/Configuration/ProxySetup.cs @@ -0,0 +1,32 @@ +using System.Net; + +namespace Agent.Configuration; + +/// +/// Process-wide outbound proxy. The system/environment proxy is honored by +/// default (HTTP_PROXY / HTTPS_PROXY / NO_PROXY, or the Windows system +/// proxy), and the agent authenticates to it with the process account's +/// default credentials — so corporate NTLM/Negotiate proxies work +/// unattended under the service account. ProxyUrl (registry/GPO) forces an +/// explicit proxy instead. Applies to every HttpClient and, via +/// HttpClient.DefaultProxy, to the NATS WebSocket connection. +/// +public static class ProxySetup +{ + public static void Apply(AgentConfiguration configuration) + { + if (configuration.ProxyUrl.Value is { Length: > 0 } proxyUrl + && Uri.TryCreate(proxyUrl, UriKind.Absolute, out var proxyUri)) + { + HttpClient.DefaultProxy = new WebProxy(proxyUri) + { + BypassProxyOnLocal = true, + Credentials = CredentialCache.DefaultCredentials, + }; + } + else + { + HttpClient.DefaultProxy.Credentials = CredentialCache.DefaultCredentials; + } + } +} diff --git a/src/Agent/Messaging/AgentNatsOptionsFactory.cs b/src/Agent/Messaging/AgentNatsOptionsFactory.cs index bffaaf9..53f64c6 100644 --- a/src/Agent/Messaging/AgentNatsOptionsFactory.cs +++ b/src/Agent/Messaging/AgentNatsOptionsFactory.cs @@ -37,23 +37,34 @@ public static class AgentNatsOptionsFactory LoggerFactory = loggerFactory, }; - // TlsSkipVerify (registry/GPO): accept the managed self-signed chain - // on the wss connection — the traffic stays TLS-encrypted. - if (configuration.TlsSkipVerify.Value) + var skipTlsVerify = configuration.TlsSkipVerify.Value; + if (skipTlsVerify) { - options = options with + options = options with { TlsOpts = NatsTlsOpts.Default with { InsecureSkipVerify = true } }; + } + + options = options with + { + WebSocketOpts = NatsWebSocketOpts.Default with { - TlsOpts = NatsTlsOpts.Default with { InsecureSkipVerify = true }, - WebSocketOpts = NatsWebSocketOpts.Default with + ConfigureClientWebSocketOptions = (_, clientOptions, _) => { - ConfigureClientWebSocketOptions = (_, clientOptions, _) => + // System/override proxy (ProxySetup) with default + // credentials — ClientWebSocket does not inherit + // HttpClient.DefaultProxy on its own. + clientOptions.Proxy = System.Net.Http.HttpClient.DefaultProxy; + + // TlsSkipVerify (registry/GPO): accept the managed + // self-signed chain — the traffic stays TLS-encrypted. + if (skipTlsVerify) { clientOptions.RemoteCertificateValidationCallback = (_, _, _, _) => true; - return ValueTask.CompletedTask; - }, + } + + return ValueTask.CompletedTask; }, - }; - } + }, + }; return options; } diff --git a/src/Agent/Service/AgentHost.cs b/src/Agent/Service/AgentHost.cs index b79bf09..d8cf7c9 100644 --- a/src/Agent/Service/AgentHost.cs +++ b/src/Agent/Service/AgentHost.cs @@ -30,6 +30,10 @@ public static class AgentHost var registry = Platform.PlatformServices.CreateRegistryStore(); var agentConfiguration = new AgentConfigurationLoader(registry, allowEnvironment: !runAsService).Load(); + // System/override proxy with default credentials for all outbound + // traffic (enrollment HTTP and the NATS WebSocket alike). + ProxySetup.Apply(agentConfiguration); + var logSettings = LogSettings.FromConfiguration( builder.Configuration, LogDefaults.Agent, diff --git a/src/Backend/Enrollment/InstallEndpoints.cs b/src/Backend/Enrollment/InstallEndpoints.cs index 581bdb3..d75ed6a 100644 --- a/src/Backend/Enrollment/InstallEndpoints.cs +++ b/src/Backend/Enrollment/InstallEndpoints.cs @@ -27,7 +27,7 @@ public static class InstallEndpoints } private static IResult GetInstallScript( - HttpContext context, IConfiguration configuration, Backend.Tls.TlsSettings tls, string? token, string? type) + HttpContext context, IConfiguration configuration, string? token, string? type, string? skipVerify) { if (string.IsNullOrWhiteSpace(token)) { @@ -36,19 +36,21 @@ public static class InstallEndpoints var baseUrl = ResolveBaseUrl(context, configuration); - // Direct self-signed serving: the roots aren't distributed, so the - // installer must skip verification and configure the agent to do the - // same (TlsSkipVerify — the hop stays encrypted either way). - var skipVerify = tls.IsSelfSignedDirect(context); + // Skip-verify is an OPERATOR CHOICE (&skipVerify=1), never inferred: + // a self-signed server that later gains a proxy with a real + // certificate must not leave agents skipping validation needlessly. + // The Add Device modal pre-selects it only while serving the + // self-signed chain directly. + var skipTlsVerify = skipVerify is "1" or "true"; // Token is embedded so the operator can paste one command; knowledge of a // valid token is itself the enrollment gate. var script = type?.ToLowerInvariant() switch { - "linux" => BuildUnixScript(baseUrl, token!, "linux", skipVerify), - "osx" or "mac" or "macos" or "darwin" => BuildUnixScript(baseUrl, token!, "osx", skipVerify), - "zip" => BuildZipScript(baseUrl, token!, $"{baseUrl}{ApiRoutes.AgentPackage}?type=zip", skipVerify), - _ => BuildMsiScript(baseUrl, token!, $"{baseUrl}{ApiRoutes.AgentPackage}?type=msi", skipVerify), + "linux" => BuildUnixScript(baseUrl, token!, "linux", skipTlsVerify), + "osx" or "mac" or "macos" or "darwin" => BuildUnixScript(baseUrl, token!, "osx", skipTlsVerify), + "zip" => BuildZipScript(baseUrl, token!, $"{baseUrl}{ApiRoutes.AgentPackage}?type=zip", skipTlsVerify), + _ => BuildMsiScript(baseUrl, token!, $"{baseUrl}{ApiRoutes.AgentPackage}?type=msi", skipTlsVerify), }; return Results.Text(script, "text/plain; charset=utf-8"); @@ -88,10 +90,13 @@ public static class InstallEndpoints private static string ResolveBaseUrl(HttpContext context, IConfiguration configuration) => Backend.Proxy.PublicUrl.Resolve(context, configuration); - // The PS5.1-safe global callback is used instead of -SkipCertificateCheck - // (PowerShell 7 only) so the same script works everywhere. + // Covers both PowerShell generations: 7+ ignores ServicePointManager + // (iwr/irm ride HttpClient and need -SkipCertificateCheck, applied here + // as a wildcard default so the whole script inherits it), while 5.1 + // needs the global callback. private const string PsSkipVerify = - "[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }"; + "if ($PSVersionTable.PSVersion.Major -ge 6) { $PSDefaultParameterValues['*:SkipCertificateCheck'] = $true } " + + "else { [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } }"; // NOTE: $$""" — interpolations are {{ }}, single braces are literal PowerShell. private static string BuildMsiScript(string baseUrl, string token, string packageUrl, bool skipVerify) => $$""" diff --git a/src/Backend/Program.cs b/src/Backend/Program.cs index 4534ea5..050a887 100644 --- a/src/Backend/Program.cs +++ b/src/Backend/Program.cs @@ -23,6 +23,12 @@ using Shared.Contracts.Serialization; using Shared.Infrastructure.Logging; using Shared.Infrastructure.Versioning; +// Corporate proxies: all outbound HTTP (S3, OIDC, secrets providers, the +// nats-server download) honors the system/environment proxy and +// authenticates to it with the process account's default credentials. +// Harmless when no proxy is configured. +System.Net.Http.HttpClient.DefaultProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; + // CLI mode: NATS operator/account key generation for the resolver. if (args.Length > 0 && args[0] == "nats-auth") { diff --git a/src/Infra/backend/Dockerfile b/src/Infra/backend/Dockerfile index 6e3aab1..f26c91a 100644 --- a/src/Infra/backend/Dockerfile +++ b/src/Infra/backend/Dockerfile @@ -20,8 +20,22 @@ RUN dotnet publish src/Backend/Backend.csproj -c Release -o /app --no-restore \ FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime ARG UNIFIED_VERSION=0.0.0.0 -LABEL org.opencontainers.image.title="Control Plane Backend" \ - org.opencontainers.image.version="${UNIFIED_VERSION}" +# CI supplies these at image build time (empty on plain local builds). +ARG GIT_COMMIT="" +ARG GIT_COMMIT_SHORT="" +ARG BUILD_DATE="" +ARG SOURCE_URL="https://prod.git.gracesolution.info/gsadmin/ExecuteR" +LABEL org.opencontainers.image.title="ExecuteR Control Plane Backend" \ + org.opencontainers.image.description="ExecuteR control plane: REST API, enrollment, messaging workers and job dispatch" \ + org.opencontainers.image.version="${UNIFIED_VERSION}" \ + org.opencontainers.image.revision="${GIT_COMMIT}" \ + executer.revision.short="${GIT_COMMIT_SHORT}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.source="${SOURCE_URL}" \ + org.opencontainers.image.url="${SOURCE_URL}" \ + org.opencontainers.image.documentation="${SOURCE_URL}/wiki" \ + org.opencontainers.image.vendor="ExecuteR" \ + org.opencontainers.image.licenses="AGPL-3.0" # curl is used by the compose health check. RUN apt-get update \ diff --git a/src/Infra/webui/Dockerfile b/src/Infra/webui/Dockerfile index 8b38627..1896e23 100644 --- a/src/Infra/webui/Dockerfile +++ b/src/Infra/webui/Dockerfile @@ -14,8 +14,22 @@ RUN npm run build && npm prune --omit=dev FROM node:24-alpine ARG UNIFIED_VERSION=0.0.0.0 -LABEL org.opencontainers.image.title="Control Plane WebUI" \ - org.opencontainers.image.version="${UNIFIED_VERSION}" +# CI supplies these at image build time (empty on plain local builds). +ARG GIT_COMMIT="" +ARG GIT_COMMIT_SHORT="" +ARG BUILD_DATE="" +ARG SOURCE_URL="https://prod.git.gracesolution.info/gsadmin/ExecuteR" +LABEL org.opencontainers.image.title="ExecuteR Control Plane WebUI" \ + org.opencontainers.image.description="ExecuteR web console: SvelteKit UI for devices, scripts, jobs and settings" \ + org.opencontainers.image.version="${UNIFIED_VERSION}" \ + org.opencontainers.image.revision="${GIT_COMMIT}" \ + executer.revision.short="${GIT_COMMIT_SHORT}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.source="${SOURCE_URL}" \ + org.opencontainers.image.url="${SOURCE_URL}" \ + org.opencontainers.image.documentation="${SOURCE_URL}/wiki" \ + org.opencontainers.image.vendor="ExecuteR" \ + org.opencontainers.image.licenses="AGPL-3.0" WORKDIR /app COPY --from=build /app/build ./build diff --git a/src/Installer/Policies/ExecuteR.admx b/src/Installer/Policies/ExecuteR.admx index 8a009e9..82de60b 100644 --- a/src/Installer/Policies/ExecuteR.admx +++ b/src/Installer/Policies/ExecuteR.admx @@ -130,5 +130,17 @@ + + + + + + + + + diff --git a/src/Installer/Policies/en-US/ExecuteR.adml b/src/Installer/Policies/en-US/ExecuteR.adml index 2de76b8..ecd6225 100644 --- a/src/Installer/Policies/en-US/ExecuteR.adml +++ b/src/Installer/Policies/en-US/ExecuteR.adml @@ -111,6 +111,15 @@ If you disable or do not configure this policy, the agent uses the locally confi Do not enable this for servers reached through a proxy with a publicly trusted certificate — leave validation on there. Always follow your organization's security standards. +The agent reads configuration at service start; restart the "ExecuteR Agent" service (ExecuteRAgent) to apply a change immediately. + + Outbound proxy URL + Routes the agent's outbound traffic (enrollment HTTPS and the persistent WebSocket connection) through an explicit proxy, for example http://proxy.example.com:8080. + +If you enable this policy, the agent uses the configured proxy for all outbound connections, authenticating to it with the machine account's default credentials (NTLM/Negotiate). + +If you disable or do not configure this policy, the agent honors the system or environment proxy configuration (HTTP_PROXY/HTTPS_PROXY/NO_PROXY, or the Windows system proxy) — still authenticating with default credentials when the proxy challenges. + The agent reads configuration at service start; restart the "ExecuteR Agent" service (ExecuteRAgent) to apply a change immediately. @@ -138,6 +147,11 @@ The agent reads configuration at service start; restart the "ExecuteR Agent" ser + + + + + diff --git a/src/Installer/Product.wxs b/src/Installer/Product.wxs index 417f6e0..338c2c6 100644 --- a/src/Installer/Product.wxs +++ b/src/Installer/Product.wxs @@ -5,7 +5,7 @@ + + + @@ -137,6 +143,10 @@ + + + diff --git a/src/WebUI/src/lib/components/AddDeviceModal.svelte b/src/WebUI/src/lib/components/AddDeviceModal.svelte index c16dc22..e253f45 100644 --- a/src/WebUI/src/lib/components/AddDeviceModal.svelte +++ b/src/WebUI/src/lib/components/AddDeviceModal.svelte @@ -15,7 +15,7 @@ let token = $state(''); let tokenId = $state(''); let baseUrl = $state(''); - let selfSignedDirect = $state(false); + let skipTlsVerify = $state(false); let errorText = $state(''); let busy = $state(false); let regenTimer: ReturnType | undefined; @@ -31,7 +31,10 @@ .serverInfo() .then((info) => { baseUrl = info.baseUrl ?? location.origin; - selfSignedDirect = info.selfSignedDirect ?? false; + // Pre-select only while the server serves its self-signed chain + // directly; the operator decides either way (a proxy added later + // should not leave agents skipping verification needlessly). + skipTlsVerify = info.selfSignedDirect ?? false; }) .catch(() => (baseUrl = location.origin)); @@ -90,13 +93,15 @@ const command = $derived.by(() => { if (!token || !baseUrl) return ''; - const install = `${baseUrl}/api/enrollment/install?token=${token}`; - // Self-signed direct serving: the fetch itself must skip verification - // (the install script then configures the agent the same way). The + // skipVerify=1 makes the served script configure the agent's + // TlsSkipVerify too; the fetch itself gets the same treatment. The // hop is still encrypted — the roots just aren't distributed. - const curl = selfSignedDirect ? 'curl -fsSLk' : 'curl -fsSL'; - const psPrefix = selfSignedDirect - ? '[Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }; ' + const install = `${baseUrl}/api/enrollment/install?token=${token}${skipTlsVerify ? '&skipVerify=1' : ''}`; + const curl = skipTlsVerify ? 'curl -fsSLk' : 'curl -fsSL'; + // PS7's iwr/irm need -SkipCertificateCheck (set as a wildcard default + // so the fetched script inherits it too); PS5.1 needs the callback. + const psPrefix = skipTlsVerify + ? "if ($PSVersionTable.PSVersion.Major -ge 6) { $PSDefaultParameterValues['*:SkipCertificateCheck'] = $true } else { [Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } }; " : ''; switch (platform) { case 'windows': @@ -176,6 +181,11 @@ {/if} + {#if errorText} diff --git a/src/WebUI/src/routes/settings/+page.svelte b/src/WebUI/src/routes/settings/+page.svelte index a24e5f3..ca8259d 100644 --- a/src/WebUI/src/routes/settings/+page.svelte +++ b/src/WebUI/src/routes/settings/+page.svelte @@ -17,14 +17,16 @@ let busy = $state(false); let copied = $state(false); let copiedCmd = $state(false); + let skipTlsVerify = $state(false); // PUBLIC_SERVER_URL (or trusted forwarded headers) beats the browser's own // origin, so the command works even when the admin browses via an internal - // hostname the target devices cannot reach. Direct self-signed serving - // prefixes a PS5-safe skip-verify (the hop is still encrypted). + // hostname the target devices cannot reach. Skip-verify is an operator + // choice (pre-selected only while serving the self-signed chain directly); + // the hop stays encrypted either way. const installCommand = $derived( newToken?.token - ? `${serverInfo?.selfSignedDirect ? '[Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }; ' : ''}iwr ${serverInfo?.baseUrl ?? location.origin}/api/enrollment/install?token=${newToken.token} -UseBasicParsing | iex` + ? `${skipTlsVerify ? "if ($PSVersionTable.PSVersion.Major -ge 6) { $PSDefaultParameterValues['*:SkipCertificateCheck'] = $true } else { [Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } }; " : ''}iwr ${serverInfo?.baseUrl ?? location.origin}/api/enrollment/install?token=${newToken.token}${skipTlsVerify ? '&skipVerify=1' : ''} -UseBasicParsing | iex` : '' ); @@ -36,7 +38,10 @@ void refresh(); void api .serverInfo() - .then((info) => (serverInfo = info)) + .then((info) => { + serverInfo = info; + skipTlsVerify = info.selfSignedDirect ?? false; + }) .catch(() => (serverInfo = null)); }); @@ -129,6 +134,10 @@
Deploy on a target device (run in an elevated PowerShell):
{installCommand}
+
Requires Agent.msi in the backend’s AGENT_PACKAGE_PATH. Also usable: diff --git a/tests/Agent.Tests/AgentConfigurationTests.cs b/tests/Agent.Tests/AgentConfigurationTests.cs index 366abe3..73dabc2 100644 --- a/tests/Agent.Tests/AgentConfigurationTests.cs +++ b/tests/Agent.Tests/AgentConfigurationTests.cs @@ -82,9 +82,23 @@ public class AgentConfigurationTests Assert.False(config.AllowRemoteShell.Value); Assert.True(config.AllowScriptExecution.Value); Assert.False(config.TlsSkipVerify.Value); + Assert.Null(config.ProxyUrl.Value); Assert.Equal("Information", config.LogLevel.Value); } + [Fact] + public void ProxyUrlFollowsStringPrecedence() + { + registry.SetString(Branding.AgentRegistryKey, AgentConfigurationKeys.ProxyUrl, "http://local-proxy:8080"); + var local = new AgentConfigurationLoader(registry, allowEnvironment: false).Load(); + Assert.Equal("http://local-proxy:8080", local.ProxyUrl.Value); + + registry.SetString(Branding.AgentPolicyRegistryKey, AgentConfigurationKeys.ProxyUrl, "http://gpo-proxy:8080"); + var policy = new AgentConfigurationLoader(registry, allowEnvironment: false).Load(); + Assert.Equal("http://gpo-proxy:8080", policy.ProxyUrl.Value); + Assert.True(policy.ProxyUrl.IsPolicyControlled); + } + [Fact] public void TlsSkipVerifyFollowsDwordPrecedence() { diff --git a/tests/Backend.Tests/InstallScriptTests.cs b/tests/Backend.Tests/InstallScriptTests.cs index c44e382..dfc8592 100644 --- a/tests/Backend.Tests/InstallScriptTests.cs +++ b/tests/Backend.Tests/InstallScriptTests.cs @@ -128,36 +128,30 @@ public class InstallScriptTests(BackendTestFixture fixture) : IClassFixture - { - builder.UseSetting("TLS_SELF_SIGNED", "1"); - builder.UseSetting("TLS_CERT_DIR", certDir); - }); - using var client = factory.CreateClient( - new WebApplicationFactoryClientOptions { BaseAddress = new Uri("https://localhost") }); + // &skipVerify=1 is the operator opting in (the modal checkbox); + // every install path then skips verification and configures the + // agent to keep doing so. Without the parameter nothing is inferred + // — a self-signed server that later gains a proxy must not leave + // agents skipping validation needlessly. + using var client = fixture.CreateClient(); - var msi = await (await client.GetAsync("/api/enrollment/install?token=t")).Content.ReadAsStringAsync(); - Assert.Contains("ServerCertificateValidationCallback", msi); + var msi = await (await client.GetAsync("/api/enrollment/install?token=t&skipVerify=1")).Content.ReadAsStringAsync(); + Assert.Contains("ServerCertificateValidationCallback", msi); // PS 5.1 path + Assert.Contains("SkipCertificateCheck", msi); // PS 7 path Assert.Contains("SKIPTLSVERIFY=1", msi); - var zip = await (await client.GetAsync("/api/enrollment/install?token=t&type=zip")).Content.ReadAsStringAsync(); + var zip = await (await client.GetAsync("/api/enrollment/install?token=t&type=zip&skipVerify=1")).Content.ReadAsStringAsync(); Assert.Contains("ServerCertificateValidationCallback", zip); Assert.Contains("TlsSkipVerify", zip); - var bash = await (await client.GetAsync("/api/enrollment/install?token=t&type=linux")).Content.ReadAsStringAsync(); + var bash = await (await client.GetAsync("/api/enrollment/install?token=t&type=linux&skipVerify=1")).Content.ReadAsStringAsync(); Assert.Contains("curl -fsSLk", bash); Assert.Contains("--skip-tls-verify", bash); - // Plain HTTP (the fixture default) stays clean. - using var plain = fixture.CreateClient(); - var script = await (await plain.GetAsync("/api/enrollment/install?token=t")).Content.ReadAsStringAsync(); - Assert.DoesNotContain("ServerCertificateValidationCallback", script); + var plain = await (await client.GetAsync("/api/enrollment/install?token=t")).Content.ReadAsStringAsync(); + Assert.DoesNotContain("ServerCertificateValidationCallback", plain); + Assert.DoesNotContain("SKIPTLSVERIFY", plain); } } diff --git a/tests/Integration.Tests/JobPipelineIntegrationTests.cs b/tests/Integration.Tests/JobPipelineIntegrationTests.cs index e163db9..6d75f29 100644 --- a/tests/Integration.Tests/JobPipelineIntegrationTests.cs +++ b/tests/Integration.Tests/JobPipelineIntegrationTests.cs @@ -62,6 +62,7 @@ public class JobPipelineIntegrationTests AllowRemoteShell = new(false, ConfigurationSource.Default), AllowScriptExecution = new(true, ConfigurationSource.Default), TlsSkipVerify = new(false, ConfigurationSource.Default), + ProxyUrl = new(null, ConfigurationSource.Default), }; private sealed class FixedIdentity : IHardwareIdentitySource