diff --git a/src/Heimdall.Agent/Program.cs b/src/Heimdall.Agent/Program.cs index 7911d55..4bbddae 100644 --- a/src/Heimdall.Agent/Program.cs +++ b/src/Heimdall.Agent/Program.cs @@ -4,20 +4,22 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; -// ── Sentry (GlitchTip) — DSN from env var, with hardcoded fallback ─ -var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN") - ?? "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6"; +// ── Sentry (GlitchTip) — DSN from env var only ─────────────────── +var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); var builder = WebApplication.CreateSlimBuilder(args); // ── Sentry ──────────────────────────────────────────────────────── -builder.WebHost.UseSentry(options => +if (sentryDsn is not null) { - options.Dsn = sentryDsn; - options.MinimumBreadcrumbLevel = LogLevel.Debug; - options.MinimumEventLevel = LogLevel.Error; - options.TracesSampleRate = 0.1; -}); + builder.WebHost.UseSentry(options => + { + options.Dsn = sentryDsn; + options.MinimumBreadcrumbLevel = LogLevel.Debug; + options.MinimumEventLevel = LogLevel.Error; + options.TracesSampleRate = 0.1; + }); +} // Strongly-typed configuration with validation builder.Services.AddOptions() diff --git a/src/Heimdall.Api/Program.cs b/src/Heimdall.Api/Program.cs index 6e26a22..85cc210 100644 --- a/src/Heimdall.Api/Program.cs +++ b/src/Heimdall.Api/Program.cs @@ -12,20 +12,22 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; -// ── Sentry (GlitchTip) — DSN from env var, with hardcoded fallback ─ -var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN") - ?? "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6"; +// ── Sentry (GlitchTip) — DSN from env var only ─────────────────── +var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); var builder = WebApplication.CreateBuilder(args); // ── Sentry ──────────────────────────────────────────────────────── -builder.WebHost.UseSentry(options => +if (sentryDsn is not null) { - options.Dsn = sentryDsn; - options.MinimumBreadcrumbLevel = LogLevel.Debug; - options.MinimumEventLevel = LogLevel.Error; - options.TracesSampleRate = 0.1; -}); + builder.WebHost.UseSentry(options => + { + options.Dsn = sentryDsn; + options.MinimumBreadcrumbLevel = LogLevel.Debug; + options.MinimumEventLevel = LogLevel.Error; + options.TracesSampleRate = 0.1; + }); +} // ── Rate Limiting (Polly/System.Threading.RateLimiting) ─────────── builder.Services.AddRateLimiter(options => diff --git a/src/Heimdall.Infrastructure/DependencyInjection.cs b/src/Heimdall.Infrastructure/DependencyInjection.cs index da8a388..8aac0c0 100644 --- a/src/Heimdall.Infrastructure/DependencyInjection.cs +++ b/src/Heimdall.Infrastructure/DependencyInjection.cs @@ -1,9 +1,11 @@ +using System.IO; using Heimdall.Application.Services; using Heimdall.Domain.Entities; using Heimdall.Infrastructure.Data; using Heimdall.Infrastructure.Security; using Heimdall.Infrastructure.Services; using Heimdall.Infrastructure.Services.Discovery; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -23,7 +25,8 @@ public static class DependencyInjection var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL") ?? configuration.GetConnectionString("Default") - ?? "Host=localhost;Port=5432;Database=heimdall;Username=heimdall;Password=heimdall"; + ?? throw new InvalidOperationException( + "Database connection string is not configured. Set DATABASE_URL env var or ConnectionStrings:Default."); if (isTesting) { @@ -58,7 +61,11 @@ public static class DependencyInjection .AddDefaultTokenProviders(); // Data Protection (for camera credential encryption) - services.AddDataProtection(); + // Keys are persisted to /var/lib/heimdall/dp-keys to survive container restarts. + // Without this, Docker container restart permanently breaks camera credential decryption. + services.AddDataProtection() + .PersistKeysToFileSystem(new DirectoryInfo("/var/lib/heimdall/dp-keys")) + .SetApplicationName("Heimdall"); // JWT services.AddScoped(); diff --git a/src/Heimdall.Infrastructure/Heimdall.Infrastructure.csproj b/src/Heimdall.Infrastructure/Heimdall.Infrastructure.csproj index 4f63140..dda5162 100644 --- a/src/Heimdall.Infrastructure/Heimdall.Infrastructure.csproj +++ b/src/Heimdall.Infrastructure/Heimdall.Infrastructure.csproj @@ -15,6 +15,7 @@ all + diff --git a/src/Heimdall.Web/Program.cs b/src/Heimdall.Web/Program.cs index 75fb154..ae9f237 100644 --- a/src/Heimdall.Web/Program.cs +++ b/src/Heimdall.Web/Program.cs @@ -7,20 +7,22 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Components.Authorization; using MudBlazor.Services; -// ── Sentry (GlitchTip) — DSN from env var, with hardcoded fallback ─ -var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN") - ?? "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6"; +// ── Sentry (GlitchTip) — DSN from env var only ─────────────────── +var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); var builder = WebApplication.CreateBuilder(args); // ── Sentry ──────────────────────────────────────────────────────── -builder.WebHost.UseSentry(options => +if (sentryDsn is not null) { - options.Dsn = sentryDsn; - options.MinimumBreadcrumbLevel = LogLevel.Debug; - options.MinimumEventLevel = LogLevel.Error; - options.TracesSampleRate = 0.1; -}); + builder.WebHost.UseSentry(options => + { + options.Dsn = sentryDsn; + options.MinimumBreadcrumbLevel = LogLevel.Debug; + options.MinimumEventLevel = LogLevel.Error; + options.TracesSampleRate = 0.1; + }); +} builder.Services.AddRazorComponents() .AddInteractiveServerComponents();