Major update

This commit is contained in:
dingo
2026-04-07 10:52:53 -04:00
parent 9665ca6168
commit 3bf4ec90d9
22 changed files with 196 additions and 124 deletions
+1
View File
@@ -416,3 +416,4 @@ FodyWeavers.xsd
src/MaxInventory.Web/FutureSecrets.json
src/MaxInventory.Web/appsettings.Development.json
src/MaxInventory.Web/appsettings.json
-28
View File
@@ -1,28 +0,0 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base
USER $APP_UID
WORKDIR /app
# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MaxInventory.csproj", "."]
RUN dotnet restore "./MaxInventory.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./MaxInventory.csproj" -c $BUILD_CONFIGURATION -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MaxInventory.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MaxInventory.dll"]
+1 -1
View File
@@ -1,5 +1,5 @@
<Solution>
<Project Path="src/MaxInventory.Authentication/MaxInventory.Authentication.csproj" Id="c1189b9b-4806-4281-ad95-6c50f1199d25" />
<Project Path="src/MaxInventory.Authentication/MaxInventory.Authentication.csproj" />
<Project Path="src/MaxInventory.Core/MaxInventory.Core.csproj" Id="811e1f0d-a0d1-449a-8787-6a54c382515c" />
<Project Path="src/MaxInventory.Infrastructure/MaxInventory.Infrastructure.csproj" Id="c97d502d-a07f-41e9-a6c7-a8254d9c3c70" />
<Project Path="src/MaxInventory.Web/MaxInventory.Web.csproj" />
-2
View File
@@ -1,2 +0,0 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
-2
View File
@@ -1,2 +0,0 @@
# Inventory
+52
View File
@@ -0,0 +1,52 @@
variables:
- group: "Proxy Variables"
trigger:
branches:
include:
- refs/heads/master
name: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
jobs:
- job: Job_1
displayName: Build Server
cancelTimeoutInMinutes: 1
pool:
name: Dotnet-Build
steps:
- checkout: self
clean: true
submodules: recursive
- task: CmdLine@1
displayName: dotnet clean
inputs:
filename: dotnet
arguments: clean -o $(Build.ArtifactStagingDirectory)/Publish/K8s/
- task: CmdLine@1
displayName: dotnet build
inputs:
filename: dotnet
arguments: build -c Release MaxInventory.slnx
- task: CmdLine@1
displayName: dotnet Info
inputs:
filename: dotnet
arguments: --info
- task: DotNetCoreCLI@2
displayName: dotnet publish Web Api K8s
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/**/MaxInventory.Web.csproj'
arguments: '-c Release -o $(Build.ArtifactStagingDirectory)/Publish/K8s/ --no-self-contained'
zipAfterPublish: false
modifyOutputPath: false
- task: CopyFiles@2
displayName: 'Copy Dockerfile to publish output'
inputs:
SourceFolder: $(Build.SourcesDirectory)/src/MaxInventory.Web/
Contents: 'Dockerfile'
TargetFolder: $(Build.ArtifactStagingDirectory)/Publish/K8s/
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: K8s'
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)/Publish/K8s/
ArtifactName: Kubernetes
@@ -1,4 +1,4 @@
using MaxInventory.Authentication.Core;
using MaxInventory.Authentication.Core;
using System.Security.Claims;
namespace MaxInventory.Authentication.Abstractions
@@ -1,12 +1,31 @@
using MaxInventory.Authentication.Abstractions;
using MaxInventory.Authentication.Abstractions;
using MaxInventory.Authentication.Configuration;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace MaxInventory.Authentication.Core
{
public sealed class AdminCookieValidationEvents : CookieAuthenticationEvents
{
// private static readonly string[] GroupClaimTypes =
// {
// "groups",
// "group",
// "role",
// "roles",
// ClaimTypes.GroupSid,
// ClaimTypes.Role,
// "http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
// "http://schemas.xmlsoap.org/claims/Group"
//};
private readonly IPrincipalAccessEvaluator _principalAccessEvaluator;
public AdminCookieValidationEvents(IPrincipalAccessEvaluator principalAccessEvaluator)
@@ -35,6 +54,24 @@ namespace MaxInventory.Authentication.Core
context.RejectPrincipal();
await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}
//var configuredGroups = (_configuration[AuthEnvironment.AdminGroups] ?? string.Empty)
// .Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
//var principalGroups = identity.Claims
// .Where(c => GroupClaimTypes.Contains(c.Type, StringComparer.OrdinalIgnoreCase))
// .Select(c => c.Value);
//var isAdmin = configuredGroups.Length > 0 &&
// principalGroups.Any(group =>
// configuredGroups.Contains(group, StringComparer.OrdinalIgnoreCase));
//if (!isAdmin)
//{
// context.RejectPrincipal();
// await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
//}
}
}
}
@@ -2,7 +2,7 @@
{
public static class AuthRoles
{
public const string Admin = "SG-OMB-IT";
public const string Admin = "Admin";
public const string EditAdd = "EditAdd";
public const string View = "View";
}
@@ -1,4 +1,4 @@
namespace MaxInventory.Authentication.Core
namespace MaxInventory.Authentication.Core
{
public sealed record PrincipalAccess(bool IsAuthenticated, bool CanView, bool CanEdit, bool CanDelete);
}
@@ -1,4 +1,4 @@
using MaxInventory.Authentication.Abstractions;
using MaxInventory.Authentication.Abstractions;
using System.Security.Claims;
namespace MaxInventory.Authentication.Core
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
@@ -42,7 +42,7 @@ namespace MaxInventory.Authentication.Extensions
authBuilder.AddCookie(options =>
{
options.Cookie.Name = "secure-network.auth";
options.AccessDeniedPath = "/AccesDenied";
options.AccessDeniedPath = "/access-denied";
options.EventsType = typeof(AdminCookieValidationEvents);
});
@@ -79,4 +79,4 @@ namespace MaxInventory.Authentication.Extensions
}
}
}
//Triggering release.
@@ -73,17 +73,18 @@ public sealed class OidcAuthProvider : IAuthProvider
RoleClaimType = roleClaimType
};
options.Events = new OpenIdConnectEvents()
{
OnRedirectToIdentityProvider = context =>
{
var builder = new UriBuilder(context.ProtocolMessage.RedirectUri);
builder.Scheme = "https";
builder.Port = 44374;// 1;
context.ProtocolMessage.RedirectUri = builder.ToString();
return Task.FromResult(0);
}
};
//This is used for Local Testing
//options.Events = new OpenIdConnectEvents()
//{
// OnRedirectToIdentityProvider = context =>
// {
// var builder = new UriBuilder(context.ProtocolMessage.RedirectUri);
// builder.Scheme = "https";
// builder.Port = 443;
// context.ProtocolMessage.RedirectUri = builder.ToString();
// return Task.FromResult(0);
// }
//};
});
}
}
@@ -9,7 +9,7 @@
/// <summary>
/// Base URL for the inventory API.
/// </summary>
public string? BaseUrl { get; set; }
public string BaseUrl { get; set; } = "https://directauth.max.gov/inventory";
/// <summary>
/// HTTP request timeout in seconds. Default is 30.
@@ -3,17 +3,35 @@
/// <summary>
/// Configuration settings for client certificate authentication.
/// Bound from the "Certificate" section of appsettings.json.
/// Uses a mounted PFX file path, typically sourced from a Kubernetes secret volume.
/// Supports two modes: Windows certificate store lookup (by friendly name)
/// or file-based PFX loading (for Docket/Linux environments).
/// </summary>
public sealed class CertificateSettings
{
/// <summary>
/// Path to the mounted PFX certificate file.
/// When true, loads certificate from a PFX file (FilePath + Password).
/// When false, searches the Windows machine certificate store by FriendlyName.
/// </summary>
public bool UseFile { get; set; } = true;
///<summary>Friendly name of the certificate in the Windows machine store.
///Used when UseFile is false.
/// </summary>
public string? FriendlyName { get; set; } = "";
///<summary>
///Certificate thumbprint in the windows machine store.
///Used as a fallback when UseFile is false and FriendlyName lookup does not find a certificate.
/// </summary>
public string? Thumbprint { get; set; }
/// <summary>
/// Path to the PFX certificate file. Used when UseFile is true.
/// </summary>
public string? Path { get; set; }
/// <summary>
/// Password for the PFX certificate file when one is required.
/// Password for the PFC certificate file. Used when UseFile is true.
/// </summary>
public string? Password { get; set; }
}
@@ -11,12 +11,12 @@ namespace MaxInventory.Infrastructure.Certificates
public sealed class FileCertificateProvider : ICertificateProvider
{
private readonly string _filePath;
private readonly string? _password;
private readonly string _password;
public FileCertificateProvider(string filePath, string? password)
public FileCertificateProvider(string filePath, string password)
{
_filePath = filePath ?? throw new ArgumentNullException(nameof(filePath));
_password = password;
_password = password ?? throw new ArgumentNullException(nameof(password));
}
///<inheritdoc/>
@@ -29,15 +29,11 @@ namespace MaxInventory.Infrastructure.Certificates
$"is mounted or copied to the expected location.", _filePath);
}
return string.IsNullOrWhiteSpace(_password)
? new X509Certificate2(
_filePath,
(string?)null,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet)
: new X509Certificate2(
_filePath,
_password,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
return new X509Certificate2(
_filePath,
_password,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet
);
}
}
}
@@ -5,6 +5,7 @@ using MaxInventory.Core.Services;
using MaxInventory.Core.Settings;
using MaxInventory.Infrastructure.Certificates;
using MaxInventory.Infrastructure.Http;
using System.Runtime.CompilerServices;
namespace MaxInventory.Infrastructure.Extensions
{
@@ -25,28 +26,41 @@ namespace MaxInventory.Infrastructure.Extensions
// Bind settings from configuration
var apiSettings = new ApiSettings();
configuration.GetSection("Api").Bind(apiSettings);
if (string.IsNullOrWhiteSpace(apiSettings.BaseUrl))
{
throw new InvalidOperationException(
"Api.BaseUrl must be provided via configuration or Kubernetes secret.");
}
services.AddSingleton(apiSettings);
var certSettings = new CertificateSettings();
configuration.GetSection("Certificate").Bind(certSettings);
if (string.IsNullOrWhiteSpace(certSettings.Path))
{
throw new InvalidOperationException(
"Certificate.Path must be provided via configuration and should point to the mounted Kubernetes secret file.");
}
services.AddSingleton(certSettings);
var proxySettings = new ProxySettings();
configuration.GetSection("Proxy").Bind(proxySettings);
services.AddSingleton(proxySettings);
services.AddSingleton<ICertificateProvider>(
new FileCertificateProvider(certSettings.Path, certSettings.Password));
// Cert provider
if (certSettings.UseFile)
{
services.AddSingleton<ICertificateProvider>(
new FileCertificateProvider(
certSettings.Path ?? throw new InvalidOperationException(
"Certificate.FilePath must be set when Certificate.UseFile is true."),
certSettings.Password ?? throw new InvalidOperationException(
"Certificate.Password must be set when Certificate.UseFile is true."))
);
}
else
{
if (string.IsNullOrWhiteSpace(certSettings.FriendlyName) &&
string.IsNullOrWhiteSpace(certSettings.Thumbprint))
{
throw new InvalidOperationException(
"When Certificate.UseFile is false, set at least one of Certificate.FriendlyName or Certificate.Thumbprint.");
}
//services.AddSingleton<ICertificateProvider>(
// new WindowsCertificateProvider(
// certSettings.FriendlyName,
// certSettings.Thumbprint));
}
//Http Client
services.AddSingleton<HttpClient>(sp =>
@@ -34,7 +34,7 @@ namespace MaxInventory.Infrastructure.Http
}
//Ensure the base URL ends with a trailing slash for proper relative URL resolution
var baseUrl = apiSettings.BaseUrl!.TrimEnd('/') + "/";
var baseUrl = apiSettings.BaseUrl.TrimEnd('/') + "/";
var client = new HttpClient(handler)
{
@@ -1,4 +1,4 @@
namespace MaxInventory.Web.Components.Pages;
namespace MaxInventory.Web.Components.Pages;
using MaxInventory.Authentication.Abstractions;
using MaxInventory.Core.Configuration;
@@ -33,7 +33,7 @@ public partial class ContentTypePage : ComponentBase
[Inject] public required AuthenticationStateProvider AuthenticationStateProvider { get; set; }
// -- Page State ---------------------------------------------------
// ── Page State ───────────────────────────────────────────────────
private ContentTypeDefinition? _definition;
private ContentTypeDefinition? _formDefinition;
private List<IInventoryEntity> _items = new();
@@ -56,7 +56,7 @@ public partial class ContentTypePage : ComponentBase
/// </summary>
private readonly Dictionary<ContentTypeName, IReadOnlyList<IInventoryEntity>> _dataCache = new();
// -- Lifecycle ----------------------------------------------------
// ── Lifecycle ────────────────────────────────────────────────────
protected override async Task OnParametersSetAsync()
{
@@ -91,13 +91,13 @@ public partial class ContentTypePage : ComponentBase
}
if (EditId.HasValue)
{
var editItem = _items.FirstOrDefault(i => i.Id == EditId.Value);
var editItem = _items.FirstOrDefault(i => i.Id == HighlightId.Value);
if (editItem != null && _canEdit)
ShowEditForm(editItem);
}
}
// -- Data Loading -------------------------------------------------
// ── Data Loading ─────────────────────────────────────────────────
private async Task LoadDataAsync()
{
@@ -159,7 +159,7 @@ public partial class ContentTypePage : ComponentBase
}
// -- Row Selection -------------------------------------------------
// ── Row Selection ─────────────────────────────────────────────────
private void SelectItem(IInventoryEntity item)
{
@@ -204,7 +204,7 @@ public partial class ContentTypePage : ComponentBase
}
}
// -- CRUD ---------------------------------------------------------
// ── CRUD ─────────────────────────────────────────────────────────
private void ShowAddForm()
{
@@ -340,7 +340,7 @@ public partial class ContentTypePage : ComponentBase
}
}
// -- Helpers ------------------------------------------------------
// ── Helpers ──────────────────────────────────────────────────────
private string GetDisplayName(IInventoryEntity entity)
{
@@ -381,10 +381,11 @@ public partial class ContentTypePage : ComponentBase
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var access = await PrincipalAccessEvaluator.EvaluateAsync(state.User);
_canView = access.CanView;
_canEdit = access.CanEdit;
_canDelete = access.CanDelete;
}
}
}
+2 -26
View File
@@ -1,30 +1,6 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
COPY . .
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
EXPOSE 8081
# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MaxInventory.Web/MaxInventory.Web.csproj", "MaxInventory.Web/"]
RUN dotnet restore "./MaxInventory.Web/MaxInventory.Web.csproj"
COPY . .
WORKDIR "/src/MaxInventory.Web"
RUN dotnet build "./MaxInventory.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MaxInventory.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MaxInventory.Web.dll"]
+13 -3
View File
@@ -4,6 +4,7 @@ using MaxInventory.Infrastructure.Extensions;
using MaxInventory.Web.Components;
using MaxInventory.Web.Services;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
@@ -19,7 +20,9 @@ if (Directory.Exists(secretsDirectory))
}
//Blazor Server Services
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
.AddInteractiveServerComponents()
.AddCircuitOptions( o => o.DetailedErrors =
builder.Configuration.GetValue<bool>("DetailedErrors",false));
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<ITicketStore, MemoryCacheTicketStore>();
@@ -44,13 +47,20 @@ builder.Services.AddScoped<IToastService, ToastService>();
var app = builder.Build();
//configure the HTTP Request pipeline
var forwardedHeaderOptions = new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto
};
forwardedHeaderOptions.KnownNetworks.Clear();
forwardedHeaderOptions.KnownProxies.Clear();
app.UseForwardedHeaders(forwardedHeaderOptions);
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
@@ -61,4 +71,4 @@ app.MapRazorComponents<App>()
.RequireAuthorization("ViewOnly");
app.Run();
app.Run();
+2 -4
View File
@@ -7,12 +7,10 @@
},
"AllowedHosts": "*",
"Api": {
"BaseUrl": "https://directauth.max.gov/inventory",
"TimeoutSeconds": 30
},
"Certificate": {
"Path": null,
"Password": null
},
"Proxy": {
"Enabled": true,
"Address": "http://proxy.omb.gov:8080"