From 8ebcdb81a6ab25f20ac935c6591aea120e08ff37 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Thu, 22 Oct 2026 06:56:06 +0200 Subject: [PATCH 1/2] fix(agent): secure diagnostics and require TLS to central --- docker/Dockerfile.agent | 6 ++++-- docker/docker-compose.prod.yml | 6 +++--- docker/docker-compose.yml | 8 +++++--- install/install-agent.sh | 9 +++++++-- src/Heimdall.Agent/AgentOptions.cs | 3 +++ src/Heimdall.Agent/Program.cs | 4 ++++ src/Heimdall.Web/Components/SiteInstallPanel.razor | 5 ++++- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile.agent b/docker/Dockerfile.agent index d96d317..55db10b 100644 --- a/docker/Dockerfile.agent +++ b/docker/Dockerfile.agent @@ -13,9 +13,11 @@ RUN dotnet publish src/Heimdall.Agent/Heimdall.Agent.csproj -c Release --no-rest FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:d5633778c754e89a386882eddf8dbee6942447a8a4b8267c19cf1e1158d0b0ac WORKDIR /app RUN apt-get update -qq && apt-get install -y --no-install-recommends ffmpeg wget libgomp1 tzdata && rm -rf /var/lib/apt/lists/* -ENV ASPNETCORE_URLS=http://+:8080 +# The agent only needs these diagnostic endpoints for its local healthcheck. +# Keep them off the host/container network interfaces by default. +ENV ASPNETCORE_URLS=http://127.0.0.1:8080 COPY --from=build /out/ ./ COPY models/yolov8n.onnx ./models/yolov8n.onnx EXPOSE 8080 -HEALTHCHECK --interval=30s --timeout=5s --start-period=30s CMD wget -q --spider http://localhost:8080/healthz || exit 1 +HEALTHCHECK --interval=30s --timeout=5s --start-period=30s CMD wget -q --spider http://127.0.0.1:8080/healthz || exit 1 ENTRYPOINT ["dotnet", "Heimdall.Agent.dll"] diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index 89dbda3..6715a4c 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -144,8 +144,8 @@ services: # On a bridge network it only sees 172.x → the scanner skips (no local subnet). network_mode: host environment: - # 8080 is taken by ntfy on the host → listen on 8081 - ASPNETCORE_URLS: http://+:8081 + # Diagnostics are loopback-only; 8081 avoids conflicts with ntfy. + ASPNETCORE_URLS: http://127.0.0.1:8081 # Host network: Docker DNS names don't resolve → point HEIMDALL_CENTRAL_URL # to the Central's public URL (e.g. https://heimdall.tordais.cc) Agent__CentralUrl: ${HEIMDALL_CENTRAL_URL:?HEIMDALL_CENTRAL_URL is required (public URL of the Central, e.g. https://heimdall.tordais.cc)} @@ -180,7 +180,7 @@ services: count: 1 capabilities: [gpu] healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8081/healthz"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:8081/healthz"] interval: 30s timeout: 5s retries: 3 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 30198ff..687a8d6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -124,11 +124,13 @@ services: # On a bridge network it only sees 172.x → the scanner skips (no local subnet). network_mode: host environment: - # 8080 is taken by ntfy on the host → listen on 8081 - ASPNETCORE_URLS: http://+:8081 + # Diagnostics are loopback-only; 8081 avoids conflicts with ntfy. + ASPNETCORE_URLS: http://127.0.0.1:8081 # Host network: Docker DNS names don't resolve → reach the Central via # a host-reachable URL (same machine: http://localhost:5010) Agent__CentralUrl: ${HEIMDALL_CENTRAL_URL:-http://localhost:5010} + # This development profile uses local plain HTTP; never enable this in production. + Agent__AllowInsecureHttp: "true" Agent__SiteToken: ${HEIMDALL_SITE_TOKEN:?HEIMDALL_SITE_TOKEN is required} Agent__AgentName: ${HEIMDALL_AGENT_NAME:-agent-01} Agent__HeartbeatIntervalSeconds: ${HEIMDALL_HEARTBEAT_INTERVAL:-30} @@ -163,7 +165,7 @@ services: count: 1 capabilities: [gpu] healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8081/healthz"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:8081/healthz"] interval: 30s timeout: 5s retries: 3 diff --git a/install/install-agent.sh b/install/install-agent.sh index c33894e..fb339a6 100755 --- a/install/install-agent.sh +++ b/install/install-agent.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash # install-agent.sh — Heimdall Agent installer for Linux set -euo pipefail -CENTRAL_URL="" SITE_TOKEN="" AGENT_NAME="" STATE_DIR="/var/lib/heimdall" +CENTRAL_URL="" SITE_TOKEN="" AGENT_NAME="" STATE_DIR="/var/lib/heimdall" ALLOW_INSECURE_HTTP=false BINARY_NAME="heimdall-agent" INSTALL_DIR="/usr/local/bin" SERVICE_NAME="heimdall-agent" SERVICE_USER="heimdall" -while [[ $# -gt 0 ]]; do case "$1" in --central-url) CENTRAL_URL="$2"; shift 2;; --site-token) SITE_TOKEN="$2"; shift 2;; --agent-name) AGENT_NAME="$2"; shift 2;; --state-dir) STATE_DIR="$2"; shift 2;; -h|--help) echo "Usage: $0 --central-url URL --site-token TOKEN"; exit 0;; *) echo "Unknown: $1" >&2; exit 1;; esac; done +while [[ $# -gt 0 ]]; do case "$1" in --central-url) CENTRAL_URL="$2"; shift 2;; --site-token) SITE_TOKEN="$2"; shift 2;; --agent-name) AGENT_NAME="$2"; shift 2;; --state-dir) STATE_DIR="$2"; shift 2;; --allow-insecure-http) ALLOW_INSECURE_HTTP=true; shift;; -h|--help) echo "Usage: $0 --central-url URL --site-token TOKEN [--agent-name NAME] [--state-dir PATH] [--allow-insecure-http]"; exit 0;; *) echo "Unknown: $1" >&2; exit 1;; esac; done [[ -z "$CENTRAL_URL" || -z "$SITE_TOKEN" ]] && { echo "Error: --central-url and --site-token required" >&2; exit 1; } CENTRAL_URL="${CENTRAL_URL%/}" +if [[ "$CENTRAL_URL" != https://* && ! ( "$ALLOW_INSECURE_HTTP" == true && "$CENTRAL_URL" == http://* ) ]]; then + echo "Error: --central-url must use HTTPS (or explicitly opt in with --allow-insecure-http on an isolated network)" >&2 + exit 1 +fi ARCH=$(uname -m); case "$ARCH" in x86_64|amd64) PLATFORM="linux-x64";; aarch64|arm64) PLATFORM="linux-arm64";; armv7l|armhf) PLATFORM="linux-arm";; *) echo "Unsupported: $ARCH" >&2; exit 1;; esac echo "Installing Heimdall Agent for $PLATFORM..." RELEASE_JSON=$(curl -sf "$CENTRAL_URL/api/updates/latest") || { echo "Failed to fetch release" >&2; exit 1; } @@ -30,6 +34,7 @@ ExecStart=$INSTALL_DIR/$BINARY_NAME Restart=on-failure Environment=ASPNETCORE_ENVIRONMENT=Production Environment=Agent__CentralUrl=$CENTRAL_URL +Environment=Agent__AllowInsecureHttp=$ALLOW_INSECURE_HTTP Environment=Agent__SiteToken=$SITE_TOKEN Environment=Agent__StateDirectory=$STATE_DIR $AGENT_NAME_ENV diff --git a/src/Heimdall.Agent/AgentOptions.cs b/src/Heimdall.Agent/AgentOptions.cs index 89afb0f..cd70e93 100644 --- a/src/Heimdall.Agent/AgentOptions.cs +++ b/src/Heimdall.Agent/AgentOptions.cs @@ -16,6 +16,9 @@ public sealed class AgentOptions [Required, Url] public string CentralUrl { get; init; } = string.Empty; + /// Allow an unencrypted HTTP Central URL for isolated development networks only. + public bool AllowInsecureHttp { get; init; } + /// Site token for agent registration. [Required, MinLength(1)] public string SiteToken { get; init; } = string.Empty; diff --git a/src/Heimdall.Agent/Program.cs b/src/Heimdall.Agent/Program.cs index 641e10a..f80cbb4 100644 --- a/src/Heimdall.Agent/Program.cs +++ b/src/Heimdall.Agent/Program.cs @@ -39,6 +39,10 @@ if (!string.IsNullOrEmpty(sentryDsn)) builder.Services.AddOptions() .BindConfiguration(AgentOptions.SectionName) .ValidateDataAnnotations() + .Validate(options => Uri.TryCreate(options.CentralUrl, UriKind.Absolute, out var centralUri) && + (centralUri.Scheme == Uri.UriSchemeHttps || + (options.AllowInsecureHttp && centralUri.Scheme == Uri.UriSchemeHttp)), + "Agent:CentralUrl must use HTTPS unless Agent:AllowInsecureHttp is explicitly enabled.") .ValidateOnStart(); // HTTP clients diff --git a/src/Heimdall.Web/Components/SiteInstallPanel.razor b/src/Heimdall.Web/Components/SiteInstallPanel.razor index 329c891..002cea1 100644 --- a/src/Heimdall.Web/Components/SiteInstallPanel.razor +++ b/src/Heimdall.Web/Components/SiteInstallPanel.razor @@ -84,7 +84,7 @@ } private string ShellCommand - => $"curl -sSL {CentralUrl}/install-agent.sh -o install-agent.sh && bash install-agent.sh --site-token {SiteToken} --name \"{SiteName}\""; + => $"curl -sSL {ShellQuote(CentralUrl.TrimEnd('/') + "/install-agent.sh")} -o install-agent.sh && bash install-agent.sh --central-url {ShellQuote(CentralUrl)} --site-token {ShellQuote(SiteToken)} --agent-name {ShellQuote(SiteName)}"; private async Task CopyCode(string code) { @@ -101,4 +101,7 @@ sb.Append(char.IsLetterOrDigit(ch) ? ch : '-'); return sb.ToString().Trim('-'); } + + private static string ShellQuote(string value) + => $"'{value.Replace("'", "'\\''", StringComparison.Ordinal)}'"; } From 86963af53870813393b4e7aa10b2357b22ec8d18 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Thu, 22 Oct 2026 19:09:29 +0200 Subject: [PATCH 2/2] fix(users): show recently created accounts first --- src/Heimdall.Infrastructure/Persistence/UserRepository.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Heimdall.Infrastructure/Persistence/UserRepository.cs b/src/Heimdall.Infrastructure/Persistence/UserRepository.cs index d6c553a..d2e6763 100644 --- a/src/Heimdall.Infrastructure/Persistence/UserRepository.cs +++ b/src/Heimdall.Infrastructure/Persistence/UserRepository.cs @@ -21,7 +21,11 @@ public class UserRepository : IUserRepository public async Task> GetPagedAsync(int page, int pageSize, CancellationToken ct) { - var query = _db.Users.AsNoTracking().OrderBy(u => u.DisplayName); + // Keep newly created accounts visible on the first page immediately after + // creation, even when the installation has more users than one page. + var query = _db.Users.AsNoTracking() + .OrderByDescending(u => u.CreatedAt) + .ThenBy(u => u.Id); var total = await query.CountAsync(ct).ConfigureAwait(false); var users = await query .Skip((page - 1) * pageSize)