Merge remote-tracking branch 'origin/main' into fix/agent-systemd-credentials
Heimdall Gitea / Build and tests (pull_request) Failing after 7m9s
Heimdall Gitea / Publish versioned release (pull_request) Skipped

# Conflicts:
#	install/install-agent.sh
#	src/Heimdall.Agent/AgentOptions.cs
This commit is contained in:
Arnaud Dartois committed 2026-10-22 19:14:27 +02:00
commit 7262c6dc55
8 files changed
+36 -12

No files matched your search

+4 -2
View File
@@ -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"]
+3 -3
View File
@@ -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
+5 -3
View File
@@ -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
+7 -2
View File
@@ -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; }
@@ -38,6 +42,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__StateDirectory=$STATE_DIR
LoadCredential=site-token:/etc/heimdall/credentials/site-token
$AGENT_NAME_CREDENTIAL
+4
View File
@@ -16,7 +16,11 @@ public sealed class AgentOptions
[Required, Url]
public string CentralUrl { get; init; } = string.Empty;
/// <summary>Allow an unencrypted HTTP Central URL for isolated development networks only.</summary>
public bool AllowInsecureHttp { get; init; }
/// <summary>Site token for initial agent registration.</summary>
[Required, MinLength(1)]
public string SiteToken
{
get => string.IsNullOrWhiteSpace(_siteToken)
+4
View File
@@ -39,6 +39,10 @@ if (!string.IsNullOrEmpty(sentryDsn))
builder.Services.AddOptions<AgentOptions>()
.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
@@ -21,7 +21,11 @@ public class UserRepository : IUserRepository
public async Task<PagedResult<UserResponse>> 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)
@@ -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)}'";
}