mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 07:01:10 +00:00
Adds bundled plugin trust and cross-platform native deployment
- embeds the append-only historical and deny trust lists in the API and marks matching bundled plugins as Official without blocking loading - builds and records the current plugin manifest only for official release builds - deploys the PDF native libraries for the supported Linux, macOS and Windows runtimes from the plugin dependency manifest - records release hashes by appending only missing entries to master's manifest and rejects any diff that removes a line - documents the release flow, the supported runtimes and the plugin installer limits
This commit is contained in:
1 parent
3fb8912c7f
commit
b30cbd6b9e
114 files changed
+2708
-243
No files matched your search
@@ -1,39 +0,0 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
|
||||
# AI
|
||||
**/AGENTS.[Mm][Dd]
|
||||
**/agents.[Mm][Dd]
|
||||
**/SKILL.[Mm][Dd]
|
||||
**/skill.[Mm][Dd]
|
||||
|
||||
# Six Labors license key file: must always be present for build-time license validation
|
||||
!**/sixlabors.lic
|
||||
@@ -1,6 +1,9 @@
|
||||
<Project>
|
||||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))" />
|
||||
|
||||
<!-- Shared warning and documentation policy for every production project under src. -->
|
||||
<PropertyGroup>
|
||||
<BaseOutputPath>$(RepoRoot)bin/api/</BaseOutputPath>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors><!--Public members must have XML documentation.-->
|
||||
|
||||
@@ -23,4 +23,11 @@ public interface IPluginManager
|
||||
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
||||
/// <returns>The plugin, or <see langword="null"/> when no plugin with the provided Id was loaded.</returns>
|
||||
IPlugin? GetPlugin(Guid pluginId);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the loaded plugin identified by <paramref name="pluginId"/> matches a trusted bundled plugin binary.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
||||
/// <returns><see langword="true"/> when the plugin is official, <see langword="false"/> otherwise.</returns>
|
||||
bool IsOfficial(Guid pluginId);
|
||||
}
|
||||
@@ -16,9 +16,11 @@ public static class PluginEntityMapping
|
||||
/// Converts <paramref name="pluginEntity"/> to <see cref="PluginResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="pluginEntity">The repository entity to be converted.</param>
|
||||
/// <param name="isOfficial">Whether the plugin matches a trusted bundled plugin binary.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static PluginResponse ToResponse(this PluginEntity pluginEntity)
|
||||
public static PluginResponse ToResponse(this PluginEntity pluginEntity, bool isOfficial)
|
||||
{
|
||||
// Official status is supplied by the caller because it is derived from the running plugin manager, not from the persisted entity.
|
||||
return new PluginResponse(
|
||||
pluginEntity.Id,
|
||||
pluginEntity.Name,
|
||||
@@ -27,7 +29,8 @@ public static class PluginEntityMapping
|
||||
pluginEntity.Description,
|
||||
pluginEntity.LoadStatus,
|
||||
pluginEntity.LoadError,
|
||||
pluginEntity.ToSettings()
|
||||
pluginEntity.ToSettings(),
|
||||
isOfficial
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Nemera.Domain.Common.Primitives;
|
||||
using Nemera.Application.Common.CQRS;
|
||||
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Nemera.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Nemera.Application.Common.DataAccess.UoW;
|
||||
using Nemera.Application.Common.DTO.Filtering;
|
||||
using Nemera.Application.Common.DTO.Pagination;
|
||||
using Nemera.Application.Common.Infrastructure.Plugins;
|
||||
using Nemera.Application.Common.Mapping.Plugins;
|
||||
using Nemera.Contracts.Responses.Plugins;
|
||||
using Nemera.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -22,14 +23,17 @@ namespace Nemera.Application.Core.Plugins.Queries.GetPlugins;
|
||||
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IReadOnlyList<PluginResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPluginsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public GetPluginsQueryHandler(IUnitOfWork unitOfWork)
|
||||
/// <param name="pluginManager">Injected manager of the plugins loaded by the host application.</param>
|
||||
public GetPluginsQueryHandler(IUnitOfWork unitOfWork, IPluginManager pluginManager)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,6 +47,7 @@ public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IRea
|
||||
public async Task<Result<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getPluginsResult.Match(plugins => Result.From<IReadOnlyList<PluginResponse>>([.. plugins.Data.Select(plugin => plugin.ToResponse())]), errors => errors);
|
||||
// Official status comes from the loaded plugin binaries, not from the persisted entity, so it is resolved for each response.
|
||||
return getPluginsResult.Match(plugins => Result.From<IReadOnlyList<PluginResponse>>([.. plugins.Data.Select(plugin => plugin.ToResponse(_pluginManager.IsOfficial(plugin.Id)))]), errors => errors);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ namespace Nemera.Contracts.Responses.Plugins;
|
||||
/// <summary>
|
||||
/// Represents a detected plugin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// IsOfficial is computed from the loaded plugin binaries when the response is built. It is not stored with the plugin entity, because replacing a plugin binary must change the badge without a database migration.
|
||||
/// </remarks>
|
||||
/// <param name="Id">The unique identifier of the plugin.</param>
|
||||
/// <param name="Name">The display name of the plugin.</param>
|
||||
/// <param name="Author">The author of the plugin.</param>
|
||||
@@ -18,6 +21,7 @@ namespace Nemera.Contracts.Responses.Plugins;
|
||||
/// <param name="LoadStatus">The load status of the plugin.</param>
|
||||
/// <param name="LoadError">The error message when the plugin failed to load, if applicable.</param>
|
||||
/// <param name="Settings">The settings of the plugin.</param>
|
||||
/// <param name="IsOfficial">Whether the plugin matches a trusted bundled plugin binary.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public sealed record PluginResponse(
|
||||
Guid Id,
|
||||
@@ -27,5 +31,6 @@ public sealed record PluginResponse(
|
||||
string Description,
|
||||
PluginLoadStatus LoadStatus,
|
||||
string? LoadError,
|
||||
IReadOnlyDictionary<string, string>? Settings
|
||||
IReadOnlyDictionary<string, string>? Settings,
|
||||
bool IsOfficial
|
||||
);
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
+17
-10
@@ -1,4 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Application.Common.DomainEvents;
|
||||
using Nemera.Application.Common.Infrastructure.Authentication;
|
||||
using Nemera.Application.Common.Infrastructure.Authorization;
|
||||
@@ -8,8 +11,8 @@ using Nemera.Application.Common.Infrastructure.Authorization.Policies.Over18;
|
||||
using Nemera.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Nemera.Application.Common.Infrastructure.Plugins;
|
||||
using Nemera.Application.Common.Infrastructure.Reading;
|
||||
using Nemera.Application.Common.Infrastructure.Security;
|
||||
using Nemera.Application.Common.Infrastructure.Scheduling;
|
||||
using Nemera.Application.Common.Infrastructure.Security;
|
||||
using Nemera.Application.Common.Infrastructure.Themes;
|
||||
using Nemera.Application.Common.Infrastructure.Time;
|
||||
using Nemera.Application.Common.Infrastructure.Validation;
|
||||
@@ -34,14 +37,14 @@ using Nemera.Infrastructure.Core.Authorization.Policies.Common.Factory;
|
||||
using Nemera.Infrastructure.Core.Authorization.Policies.ConsumptionActivity;
|
||||
using Nemera.Infrastructure.Core.Authorization.Policies.LibraryOwnership;
|
||||
using Nemera.Infrastructure.Core.Authorization.Policies.Over18;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Cancellation;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Audio.Music;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Common;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.WrittenContent.Books;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Progress;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Artwork;
|
||||
using Nemera.Infrastructure.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||
using Nemera.Infrastructure.Core.Plugins;
|
||||
@@ -52,9 +55,6 @@ using Nemera.Infrastructure.Core.Security;
|
||||
using Nemera.Infrastructure.Core.Themes;
|
||||
using Nemera.Infrastructure.Core.Time;
|
||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -77,8 +77,9 @@ public static class InfrastructureLayerServices
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection to add the services to.</param>
|
||||
/// <param name="configuration">The configuration used to read the application configuration.</param>
|
||||
/// <param name="bundledPluginChecksums">The trusted checksums of the bundled plugin assemblies, keyed by assembly file name.</param>
|
||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddInfrastructureLayerServices(this IServiceCollection services, IConfiguration configuration)
|
||||
public static IServiceCollection AddInfrastructureLayerServices(this IServiceCollection services, IConfiguration configuration, IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums)
|
||||
{
|
||||
// Scan the current assembly for validators and add them to the DI container.
|
||||
IEnumerable<Type> concreteTypes = Assembly.GetExecutingAssembly()
|
||||
@@ -89,7 +90,7 @@ public static class InfrastructureLayerServices
|
||||
foreach (Type contract in implementation.GetInterfaces())
|
||||
if (contract.IsGenericType && contract.GetGenericTypeDefinition() == typeof(IValidator<>))
|
||||
services.AddSingleton(contract, implementation);
|
||||
|
||||
|
||||
services.AddSingleton<IFileHashService, FileHashService>();
|
||||
services.AddSingleton<IPasswordHashService, PasswordHashService>();
|
||||
services.AddSingleton<ICryptographyService, CryptographyService>();
|
||||
@@ -190,10 +191,15 @@ public static class InfrastructureLayerServices
|
||||
services.AddSingleton<IBookReadingService, BookReadingService>();
|
||||
|
||||
// Plugins: load the plugin assemblies from the plugins directory, register their services and provide the plugin manager.
|
||||
// The trust list only labels plugins as Official. It never gates loading, so a plugin with an unknown or missing hash still works.
|
||||
string pluginsDirectorySetting = configuration.GetSection(PluginsSettingsDto.SECTION_NAME)["Directory"] ?? "plugins";
|
||||
string pluginsDirectory = Path.Combine(AppContext.BaseDirectory, pluginsDirectorySetting);
|
||||
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services);
|
||||
services.AddSingleton<IPluginManager>(new PluginManager(pluginLoadResult.Plugins, pluginLoadResult.LoadContexts));
|
||||
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services, bundledPluginChecksums);
|
||||
IReadOnlySet<Guid> officialPluginIds = pluginLoadResult.LoadedPlugins
|
||||
.Where(plugin => plugin.IsOfficial)
|
||||
.Select(plugin => plugin.PluginId)
|
||||
.ToHashSet();
|
||||
services.AddSingleton<IPluginManager>(new PluginManager(pluginLoadResult.Plugins, pluginLoadResult.LoadContexts, officialPluginIds));
|
||||
services.AddScoped<IPluginSettingsStore, PluginSettingsStore>();
|
||||
services.AddScoped<IPluginInstaller, PluginInstaller>();
|
||||
services.AddScoped<IMediaLibraryProviderConfigurationStore, MediaLibraryProviderConfigurationStore>();
|
||||
@@ -201,6 +207,7 @@ public static class InfrastructureLayerServices
|
||||
serviceProvider.GetRequiredService<IServiceScopeFactory>(),
|
||||
serviceProvider.GetRequiredService<IPluginManager>(),
|
||||
pluginLoadResult.Errors,
|
||||
pluginLoadResult.Warnings,
|
||||
serviceProvider.GetRequiredService<ILogger<PluginDetectionSyncJob>>()));
|
||||
services.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<PluginDetectionSyncJob>());
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the trust metadata of a loaded plugin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The Official flag is computed at load time from the plugin binary's SHA-256 hash against the embedded trust list. It is not persisted, because a plugin binary can be replaced and because each release ships a different trust list.
|
||||
/// </remarks>
|
||||
/// <param name="PluginId">The unique identifier of the plugin.</param>
|
||||
/// <param name="AssemblyFileName">The file name of the plugin assembly.</param>
|
||||
/// <param name="IsOfficial">Whether the plugin assembly matches a trusted bundled plugin binary.</param>
|
||||
[DebuggerDisplay("AssemblyFileName: {AssemblyFileName}, IsOfficial: {IsOfficial}")]
|
||||
internal sealed record LoadedPluginMetadataDto(
|
||||
Guid PluginId,
|
||||
string AssemblyFileName,
|
||||
bool IsOfficial
|
||||
);
|
||||
@@ -16,8 +16,12 @@ namespace Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||
/// when a lazily resolved dependency is first used.
|
||||
/// </param>
|
||||
/// <param name="Errors">The errors that occurred while loading the plugins.</param>
|
||||
/// <param name="LoadedPlugins">The trust metadata of the successfully loaded plugins.</param>
|
||||
/// <param name="Warnings">The warnings that occurred while loading the plugins, such as a trust status that could not be verified or a dependency manifest that could not be read.</param>
|
||||
internal sealed record PluginLoadResultDto(
|
||||
IReadOnlyList<IPlugin> Plugins,
|
||||
IReadOnlyList<PluginLoadContext> LoadContexts,
|
||||
IReadOnlyList<PluginLoadErrorDto> Errors
|
||||
IReadOnlyList<PluginLoadErrorDto> Errors,
|
||||
IReadOnlyList<LoadedPluginMetadataDto> LoadedPlugins,
|
||||
IReadOnlyList<string> Warnings
|
||||
);
|
||||
@@ -1,4 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Nemera.Application.Common.DataAccess.UoW;
|
||||
@@ -9,9 +12,6 @@ using Nemera.Domain.Common.Primitives;
|
||||
using Nemera.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -31,6 +31,7 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
private readonly IReadOnlyList<PluginLoadErrorDto> _loadErrors;
|
||||
private readonly IReadOnlyList<string> _warnings;
|
||||
private readonly ILogger<PluginDetectionSyncJob> _logger;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,12 +40,14 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
||||
/// <param name="serviceScopeFactory">Injected factory for creating scopes in which services are requested.</param>
|
||||
/// <param name="pluginManager">Injected manager of the plugins loaded by the host application.</param>
|
||||
/// <param name="loadErrors">The errors that occurred while loading the plugins.</param>
|
||||
/// <param name="warnings">The warnings that occurred while loading the plugins.</param>
|
||||
/// <param name="logger">Injected logger used for logging.</param>
|
||||
public PluginDetectionSyncJob(IServiceScopeFactory serviceScopeFactory, IPluginManager pluginManager, IReadOnlyList<PluginLoadErrorDto> loadErrors, ILogger<PluginDetectionSyncJob> logger)
|
||||
public PluginDetectionSyncJob(IServiceScopeFactory serviceScopeFactory, IPluginManager pluginManager, IReadOnlyList<PluginLoadErrorDto> loadErrors, IReadOnlyList<string> warnings, ILogger<PluginDetectionSyncJob> logger)
|
||||
{
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
_pluginManager = pluginManager;
|
||||
_loadErrors = loadErrors;
|
||||
_warnings = warnings;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -59,6 +62,11 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
||||
if (_logger.IsEnabled(LogLevel.Warning))
|
||||
_logger.LogWarning("Plugin load failure: {LoadError}", loadError.ErrorMessage);
|
||||
|
||||
// Warnings are informational and never stop the host. They cover trust verification and dependency resolution problems.
|
||||
foreach (string warning in _warnings)
|
||||
if (_logger.IsEnabled(LogLevel.Warning))
|
||||
_logger.LogWarning("Plugin warning: {Warning}", warning);
|
||||
|
||||
await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope();
|
||||
IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetRequiredService<IUnitOfWork>();
|
||||
|
||||
|
||||
@@ -1,26 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Loader;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Infrastructure.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Assembly load context of a single plugin, resolving the shared host assemblies from the default context and the plugin local dependencies from the plugin directory.
|
||||
/// Assembly load context of a single plugin, resolving the shared host assemblies from the default context, and the plugin local dependencies and native libraries from its dependency manifest.
|
||||
/// </summary>
|
||||
internal sealed class PluginLoadContext : AssemblyLoadContext
|
||||
{
|
||||
private readonly string _pluginDirectory;
|
||||
private readonly AssemblyDependencyResolver? _dependencyResolver;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the plugin assembly has no dependency manifest next to it.
|
||||
/// </summary>
|
||||
public bool IsDependencyManifestMissing { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error that occurred while reading the dependency manifest, or <see langword="null"/> when no error occurred.
|
||||
/// </summary>
|
||||
public string? DependencyManifestError { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginLoadContext"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pluginDirectory">The directory where the plugin assemblies and their dependencies are located.</param>
|
||||
/// <param name="pluginAssemblyPath">The path of the plugin assembly whose dependencies and native libraries are resolved from its adjacent dependency manifest.</param>
|
||||
/// <param name="name">The name of the load context.</param>
|
||||
public PluginLoadContext(string pluginDirectory, string name) : base(name, isCollectible: true)
|
||||
public PluginLoadContext(string pluginAssemblyPath, string name) : base(name, isCollectible: true)
|
||||
{
|
||||
_pluginDirectory = pluginDirectory;
|
||||
_pluginDirectory = Path.GetDirectoryName(pluginAssemblyPath) ?? throw new ArgumentException("The plugin assembly path has no directory.", nameof(pluginAssemblyPath));
|
||||
IsDependencyManifestMissing = !File.Exists(Path.ChangeExtension(pluginAssemblyPath, ".deps.json"));
|
||||
try
|
||||
{
|
||||
_dependencyResolver = new AssemblyDependencyResolver(pluginAssemblyPath);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// The plugin can still load its managed dependencies through the directory fallback, but the native libraries under the shared runtimes folder cannot be resolved without a readable dependency manifest,
|
||||
// so the error is recorded and the loader reports it for the plugin that it belongs to.
|
||||
_dependencyResolver = null;
|
||||
DependencyManifestError = exception.Message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,4 +74,19 @@ internal sealed class PluginLoadContext : AssemblyLoadContext
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the native library whose name is specified, using the plugin's dependency manifest to select the library of the current runtime.
|
||||
/// </summary>
|
||||
/// <param name="unmanagedDllName">The name of the native library to load.</param>
|
||||
/// <returns>The handle of the loaded native library.</returns>
|
||||
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
|
||||
{
|
||||
// The dependency resolver selects the native library for the current RID from the plugin's deps.json. When it has no match,
|
||||
// fall back to the default resolution so system libraries still load.
|
||||
string? nativeLibraryPath = _dependencyResolver?.ResolveUnmanagedDllToPath(unmanagedDllName);
|
||||
return nativeLibraryPath is null
|
||||
? base.LoadUnmanagedDll(unmanagedDllName)
|
||||
: NativeLibrary.Load(nativeLibraryPath);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Infrastructure.Core.Plugins;
|
||||
@@ -21,20 +22,23 @@ internal static class PluginLoader
|
||||
/// </summary>
|
||||
/// <param name="pluginsDirectory">The directory where the plugin assemblies are located.</param>
|
||||
/// <param name="services">The service collection to which the plugin services are added.</param>
|
||||
/// <param name="bundledPluginChecksums">The trusted checksums of the bundled plugin assemblies, keyed by assembly file name.</param>
|
||||
/// <returns>The result of loading the plugins.</returns>
|
||||
public static PluginLoadResultDto LoadPlugins(string pluginsDirectory, IServiceCollection services)
|
||||
public static PluginLoadResultDto LoadPlugins(string pluginsDirectory, IServiceCollection services, IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums)
|
||||
{
|
||||
List<IPlugin> plugins = [];
|
||||
List<PluginLoadContext> loadContexts = [];
|
||||
List<PluginLoadErrorDto> errors = [];
|
||||
List<LoadedPluginMetadataDto> loadedPlugins = [];
|
||||
List<string> warnings = [];
|
||||
|
||||
if (!Directory.Exists(pluginsDirectory))
|
||||
return new PluginLoadResultDto(plugins, loadContexts, errors);
|
||||
return new PluginLoadResultDto(plugins, loadContexts, errors, loadedPlugins, warnings);
|
||||
|
||||
foreach (string assemblyPath in Directory.EnumerateFiles(pluginsDirectory, "*.dll"))
|
||||
{
|
||||
// A failing plugin must not prevent the other plugins from loading, so each assembly is isolated in its own load context.
|
||||
PluginLoadContext loadContext = new(pluginsDirectory, Path.GetFileNameWithoutExtension(assemblyPath));
|
||||
PluginLoadContext loadContext = new(assemblyPath, Path.GetFileNameWithoutExtension(assemblyPath));
|
||||
try
|
||||
{
|
||||
Assembly assembly = loadContext.LoadFromAssemblyPath(assemblyPath);
|
||||
@@ -52,9 +56,25 @@ internal static class PluginLoader
|
||||
if (plugin is IPluginServiceRegistrator serviceRegistrator)
|
||||
serviceRegistrator.RegisterServices(services);
|
||||
plugins.Add(plugin);
|
||||
// The trust manifest is a list of known bundled binaries, so a plugin remains Official only while its assembly matches one of them.
|
||||
string assemblyFileName = Path.GetFileName(assemblyPath);
|
||||
(string? checksum, string? checksumError) = GetSha256(assemblyPath);
|
||||
bool isOfficial = checksum is not null
|
||||
&& bundledPluginChecksums.TryGetValue(assemblyFileName, out IReadOnlySet<string>? trustedChecksums)
|
||||
&& trustedChecksums.Contains(checksum);
|
||||
// A checksum failure must not prevent the plugin from loading. It only means the Official badge cannot be verified.
|
||||
if (checksum is null)
|
||||
warnings.Add($"The SHA-256 checksum of plugin assembly '{assemblyFileName}' could not be computed, so its Official status cannot be verified: {checksumError}");
|
||||
loadedPlugins.Add(new LoadedPluginMetadataDto(plugin.Id, assemblyFileName, isOfficial));
|
||||
// A collectible load context is only kept alive by a direct reference to the context object itself, so the context of a loaded plugin is held for the lifetime
|
||||
// of the host, keeping the plugin assemblies (and any lazily resolved dependency, like a book reader library) from being unloaded by the garbage collector.
|
||||
loadContexts.Add(loadContext);
|
||||
// Uploaded plugins normally have no dependency manifest because the installer stores only assemblies. Only a bundled
|
||||
// (Official) plugin is expected to have one, so a missing manifest is a warning only for that case.
|
||||
if (loadContext.DependencyManifestError is not null)
|
||||
warnings.Add($"The dependency manifest of plugin assembly '{assemblyFileName}' could not be read, so its native libraries cannot be resolved from the plugin folder: {loadContext.DependencyManifestError}");
|
||||
else if (loadContext.IsDependencyManifestMissing && isOfficial)
|
||||
warnings.Add($"The bundled plugin assembly '{assemblyFileName}' has no dependency manifest next to it, so its native libraries cannot be resolved from the plugin folder.");
|
||||
break; // Only one plugin descriptor per assembly.
|
||||
}
|
||||
}
|
||||
@@ -75,7 +95,29 @@ internal static class PluginLoader
|
||||
}
|
||||
}
|
||||
|
||||
return new PluginLoadResultDto(plugins, loadContexts, errors);
|
||||
return new PluginLoadResultDto(plugins, loadContexts, errors, loadedPlugins, warnings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the SHA-256 checksum of the file at <paramref name="path"/>, in the uppercase hexadecimal form the bundled plugin trust manifest uses.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to hash.</param>
|
||||
/// <returns>The checksum and a <see langword="null"/> error message, or a <see langword="null"/> checksum and the error message when the file cannot be read.</returns>
|
||||
private static (string? Checksum, string? ErrorMessage) GetSha256(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
return (Convert.ToHexString(SHA256.HashData(fileStream)), null);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
return (null, exception.Message);
|
||||
}
|
||||
catch (UnauthorizedAccessException exception)
|
||||
{
|
||||
return (null, exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,12 +130,14 @@ internal static class PluginLoader
|
||||
{
|
||||
try
|
||||
{
|
||||
using FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
Span<byte> signature = stackalloc byte[2];
|
||||
if (fileStream.Read(signature) < signature.Length)
|
||||
return false;
|
||||
// The DOS signature "MZ" is the header every PE image starts with, whether it is a managed assembly or a native library.
|
||||
return signature[0] == (byte)'M' && signature[1] == (byte)'Z';
|
||||
using (FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
Span<byte> signature = stackalloc byte[2];
|
||||
if (fileStream.Read(signature) < signature.Length)
|
||||
return false;
|
||||
// The DOS signature "MZ" is the header every PE image starts with, whether it is a managed assembly or a native library.
|
||||
return signature[0] == (byte)'M' && signature[1] == (byte)'Z';
|
||||
}
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Nemera.Infrastructure.Core.Plugins;
|
||||
internal sealed class PluginManager : IPluginManager
|
||||
{
|
||||
private readonly IReadOnlyDictionary<Guid, IPlugin> _pluginsById;
|
||||
private readonly IReadOnlySet<Guid> _officialPluginIds;
|
||||
// The load contexts of the loaded plugins are held for the lifetime of the host, because a collectible load context is only kept alive by a direct reference to the
|
||||
// context object itself, and the garbage collector would otherwise unload the plugin assemblies mid-request, when a lazily resolved dependency is first used.
|
||||
private readonly IReadOnlyList<PluginLoadContext> _loadContexts;
|
||||
@@ -23,9 +24,11 @@ internal sealed class PluginManager : IPluginManager
|
||||
/// </summary>
|
||||
/// <param name="plugins">The plugins that were loaded successfully.</param>
|
||||
/// <param name="loadContexts">The load contexts of the loaded plugins, kept referenced for the lifetime of the host.</param>
|
||||
public PluginManager(IEnumerable<IPlugin> plugins, IReadOnlyList<PluginLoadContext> loadContexts)
|
||||
/// <param name="officialPluginIds">The Ids of the loaded plugins whose assemblies match a trusted bundled plugin binary.</param>
|
||||
public PluginManager(IEnumerable<IPlugin> plugins, IReadOnlyList<PluginLoadContext> loadContexts, IReadOnlySet<Guid> officialPluginIds)
|
||||
{
|
||||
_pluginsById = plugins.ToDictionary(plugin => plugin.Id);
|
||||
_officialPluginIds = officialPluginIds;
|
||||
_loadContexts = loadContexts;
|
||||
}
|
||||
|
||||
@@ -47,4 +50,14 @@ internal sealed class PluginManager : IPluginManager
|
||||
{
|
||||
return _pluginsById.GetValueOrDefault(pluginId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the loaded plugin identified by <paramref name="pluginId"/> matches a trusted bundled plugin binary.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
||||
/// <returns><see langword="true"/> when the plugin is official, <see langword="false"/> otherwise.</returns>
|
||||
public bool IsOfficial(Guid pluginId)
|
||||
{
|
||||
return _officialPluginIds.Contains(pluginId);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
+3
-1
@@ -31,6 +31,7 @@ public class GetPluginsEndpointSummary : Summary<GetPluginsEndpoint, EmptyReques
|
||||
ResponseParam<PluginResponse>(r => r.LoadStatus, "The load status of the plugin.");
|
||||
ResponseParam<PluginResponse>(r => r.LoadError, "The error message when the plugin failed to load, if applicable.");
|
||||
ResponseParam<PluginResponse>(r => r.Settings, "The settings of the plugin.");
|
||||
ResponseParam<PluginResponse>(r => r.IsOfficial, "Whether the plugin matches a trusted bundled plugin binary.");
|
||||
|
||||
Response(200, "The list of detected plugins is returned.",
|
||||
example: new PluginResponse[] {
|
||||
@@ -46,7 +47,8 @@ public class GetPluginsEndpointSummary : Summary<GetPluginsEndpoint, EmptyReques
|
||||
{
|
||||
{ "preferredLanguage", "en" },
|
||||
{ "selectionStrategy", "first" }
|
||||
}
|
||||
},
|
||||
IsOfficial: true
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the trust manifests of the bundled plugin binaries embedded in the API assembly.
|
||||
/// </summary>
|
||||
internal static class BundledPluginManifestReader
|
||||
{
|
||||
/// <summary>
|
||||
/// The resource name of the append-only trust list of previously released bundled plugin binaries.
|
||||
/// </summary>
|
||||
private const string HISTORICAL_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.historical.manifest";
|
||||
|
||||
/// <summary>
|
||||
/// The resource name of the trust list generated for the current build's bundled plugin binaries.
|
||||
/// </summary>
|
||||
private const string CURRENT_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.current.manifest";
|
||||
|
||||
/// <summary>
|
||||
/// The resource name of the list of bundled plugin checksums that are no longer trusted.
|
||||
/// </summary>
|
||||
private const string DENY_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.deny.manifest";
|
||||
|
||||
/// <summary>
|
||||
/// Reads the trusted SHA-256 checksums of the bundled plugin binaries from the embedded trust manifests.
|
||||
/// The current build's manifest is read only for an official release build, so a local build cannot certify its own plugins.
|
||||
/// Denied checksums are removed from the historical and current trust lists.
|
||||
/// </summary>
|
||||
/// <returns>A dictionary that maps each bundled plugin assembly file name to the checksums it is allowed to have.</returns>
|
||||
public static IReadOnlyDictionary<string, IReadOnlySet<string>> ReadExpectedChecksums()
|
||||
{
|
||||
// The historical list is always embedded, because it carries the hashes of earlier releases and those binaries must stay trusted after an upgrade.
|
||||
using (Stream historicalManifestStream = GetManifestResourceStream(HISTORICAL_MANIFEST_RESOURCE_NAME))
|
||||
{
|
||||
// The deny list is always embedded too, so revoking a hash does not depend on the release being rebuilt.
|
||||
using (Stream denyManifestStream = GetManifestResourceStream(DENY_MANIFEST_RESOURCE_NAME))
|
||||
{
|
||||
// A normal build cannot certify its own plugins. Only an official release build embeds the current manifest,
|
||||
// so a developer cannot make a locally built plugin appear Official just by building the project.
|
||||
if (!IsOfficialReleaseBuild())
|
||||
return ReadExpectedChecksums(historicalManifestStream, null, denyManifestStream);
|
||||
using (Stream currentManifestStream = GetManifestResourceStream(CURRENT_MANIFEST_RESOURCE_NAME))
|
||||
return ReadExpectedChecksums(historicalManifestStream, currentManifestStream, denyManifestStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the trusted SHA-256 checksums of the bundled plugin binaries from the provided trust manifest streams.
|
||||
/// </summary>
|
||||
/// <param name="historicalManifestStream">The stream that contains the append-only trust list of previously released bundled plugin binaries.</param>
|
||||
/// <param name="currentManifestStream">The stream that contains the trust list generated for the current build's bundled plugin binaries, or <see langword="null"/> when the build is not an official release build.</param>
|
||||
/// <param name="denyManifestStream">The stream that contains the checksums that are no longer trusted, or <see langword="null"/> when no deny list is available.</param>
|
||||
/// <returns>A dictionary that maps each bundled plugin assembly file name to the checksums it is allowed to have.</returns>
|
||||
internal static IReadOnlyDictionary<string, IReadOnlySet<string>> ReadExpectedChecksums(Stream historicalManifestStream, Stream? currentManifestStream = null, Stream? denyManifestStream = null)
|
||||
{
|
||||
// Assembly file names are compared case-insensitively because the plugins directory is case-insensitive on Windows.
|
||||
Dictionary<string, HashSet<string>> checksumsByAssemblyFileName = new(StringComparer.OrdinalIgnoreCase);
|
||||
// The historical list comes first so the current release can add hashes without replacing the earlier ones.
|
||||
ReadManifest(historicalManifestStream, HISTORICAL_MANIFEST_RESOURCE_NAME, checksumsByAssemblyFileName);
|
||||
if (currentManifestStream is not null)
|
||||
ReadManifest(currentManifestStream, CURRENT_MANIFEST_RESOURCE_NAME, checksumsByAssemblyFileName);
|
||||
// Revocation is applied last so a denied hash wins over every trust list, including the current release's own entries.
|
||||
if (denyManifestStream is not null)
|
||||
RemoveDeniedChecksums(denyManifestStream, checksumsByAssemblyFileName);
|
||||
// The loader only reads the trust list, so the result exposes the sets as read-only even though they were built as mutable sets.
|
||||
Dictionary<string, IReadOnlySet<string>> expectedChecksums = new(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (KeyValuePair<string, HashSet<string>> checksums in checksumsByAssemblyFileName)
|
||||
expectedChecksums[checksums.Key] = checksums.Value;
|
||||
return expectedChecksums;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the checksums of the deny list from the accumulated trust list.
|
||||
/// </summary>
|
||||
/// <param name="denyManifestStream">The stream that contains the checksums that are no longer trusted.</param>
|
||||
/// <param name="checksumsByAssemblyFileName">The dictionary that accumulates the trust list entries.</param>
|
||||
private static void RemoveDeniedChecksums(Stream denyManifestStream, Dictionary<string, HashSet<string>> checksumsByAssemblyFileName)
|
||||
{
|
||||
// The deny list is parsed on its own first, so an entry for an unknown or retired assembly can be ignored without failing the whole manifest.
|
||||
Dictionary<string, HashSet<string>> deniedChecksumsByAssemblyFileName = new(StringComparer.OrdinalIgnoreCase);
|
||||
ReadManifest(denyManifestStream, DENY_MANIFEST_RESOURCE_NAME, deniedChecksumsByAssemblyFileName);
|
||||
foreach (KeyValuePair<string, HashSet<string>> deniedChecksums in deniedChecksumsByAssemblyFileName)
|
||||
{
|
||||
// A deny entry for an assembly that is not trusted anywhere is harmless.
|
||||
if (!checksumsByAssemblyFileName.TryGetValue(deniedChecksums.Key, out HashSet<string>? assemblyChecksums))
|
||||
continue;
|
||||
assemblyChecksums.ExceptWith(deniedChecksums.Value);
|
||||
// An assembly with no trusted hashes left is removed, so the result never carries an empty trust set.
|
||||
if (assemblyChecksums.Count == 0)
|
||||
checksumsByAssemblyFileName.Remove(deniedChecksums.Key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the API assembly was produced by an official release build.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> when the assembly carries the official release marker, <see langword="false"/> otherwise.</returns>
|
||||
private static bool IsOfficialReleaseBuild()
|
||||
{
|
||||
// The official build injects this marker from the OFFICIAL_RELEASE_BUILD compilation symbol. build.proj defines the symbol only for the
|
||||
// official release flow, so a normal build has no marker and does not embed a current manifest of its own binaries.
|
||||
return typeof(BundledPluginManifestReader).Assembly
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.Any(attribute => attribute.Key == "OfficialReleaseBuild" && attribute.Value == "true");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens an embedded trust manifest resource.
|
||||
/// </summary>
|
||||
/// <param name="resourceName">The name of the embedded manifest resource.</param>
|
||||
/// <returns>The stream that contains the manifest.</returns>
|
||||
private static Stream GetManifestResourceStream(string resourceName)
|
||||
{
|
||||
// The historical and deny manifests are required for every build. A missing resource means the packaging step is broken,
|
||||
// and failing fast is safer than starting with an empty trust list that marks every bundled plugin as not Official.
|
||||
return typeof(BundledPluginManifestReader).Assembly.GetManifestResourceStream(resourceName)
|
||||
?? throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' is missing.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads one trust manifest and adds its entries to <paramref name="checksumsByAssemblyFileName"/>.
|
||||
/// </summary>
|
||||
/// <param name="manifestStream">The stream that contains the manifest.</param>
|
||||
/// <param name="resourceName">The name of the manifest resource, used in error messages.</param>
|
||||
/// <param name="checksumsByAssemblyFileName">The dictionary that accumulates the trust list entries.</param>
|
||||
private static void ReadManifest(Stream manifestStream, string resourceName, Dictionary<string, HashSet<string>> checksumsByAssemblyFileName)
|
||||
{
|
||||
// Each entry is "assembly-file-name|sha256". Blank lines and lines starting with # are ignored, so the checked-in list can carry release notes.
|
||||
using (StreamReader reader = new(manifestStream))
|
||||
{
|
||||
int lineNumber = 0;
|
||||
string? line;
|
||||
while ((line = reader.ReadLine()) is not null)
|
||||
{
|
||||
lineNumber++;
|
||||
string trimmedLine = line.Trim();
|
||||
if (trimmedLine.Length == 0 || trimmedLine.StartsWith('#'))
|
||||
continue;
|
||||
// A malformed entry is a build error rather than a skipped line, because silently ignoring it could hide a plugin that the release intended to trust.
|
||||
string[] parts = trimmedLine.Split('|');
|
||||
if (parts.Length != 2)
|
||||
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid entry at line {lineNumber}.");
|
||||
string assemblyFileName = parts[0].Trim();
|
||||
string checksum = parts[1].Trim();
|
||||
// A SHA-256 checksum is 64 hexadecimal characters. The length check gives a clearer error than the conversion below.
|
||||
if (assemblyFileName.Length == 0 || checksum.Length != 64)
|
||||
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid entry at line {lineNumber}.");
|
||||
int checksumLength;
|
||||
try
|
||||
{
|
||||
checksumLength = Convert.FromHexString(checksum).Length;
|
||||
}
|
||||
catch (FormatException exception)
|
||||
{
|
||||
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid checksum at line {lineNumber}.", exception);
|
||||
}
|
||||
// The byte count is checked as well, so a future change to the length check cannot let a non-SHA-256 value through.
|
||||
if (checksumLength != 32)
|
||||
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid checksum at line {lineNumber}.");
|
||||
// The historical and current manifests can list the same hash. The set makes that duplicate harmless.
|
||||
if (!checksumsByAssemblyFileName.TryGetValue(assemblyFileName, out HashSet<string>? assemblyChecksums))
|
||||
{
|
||||
assemblyChecksums = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
checksumsByAssemblyFileName[assemblyFileName] = assemblyChecksums;
|
||||
}
|
||||
assemblyChecksums.Add(checksum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// The official release marker tells the trust manifest reader and the manifest tests that this is an official release build.
|
||||
// The OFFICIAL_RELEASE_BUILD symbol is defined by build/build.proj only for the official release build, so a normal local build cannot produce it.
|
||||
#if OFFICIAL_RELEASE_BUILD
|
||||
[assembly: System.Reflection.AssemblyMetadata("OfficialReleaseBuild", "true")]
|
||||
#endif
|
||||
@@ -14,34 +14,33 @@ WORKDIR /app
|
||||
EXPOSE 5214
|
||||
|
||||
# ==== Stage 1: Build stage
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0.100 AS build
|
||||
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# Restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages).
|
||||
COPY ["AssemblyInfo_Shared.cs", "."]
|
||||
COPY ["Nemera.Presentation.Api/Nemera.Presentation.Api.csproj", "Nemera.Presentation.Api/"]
|
||||
COPY ["Nemera.Application/Nemera.Application.csproj", "Nemera.Application/"]
|
||||
COPY ["Nemera.Contracts/Nemera.Contracts.csproj", "Nemera.Contracts/"]
|
||||
COPY ["Nemera.Domain/Nemera.Domain.csproj", "Nemera.Domain/"]
|
||||
COPY ["Nemera.Domain.SharedKernel/Nemera.Domain.SharedKernel.csproj", "Nemera.Domain.SharedKernel/"]
|
||||
COPY ["Nemera.Infrastructure/Nemera.Infrastructure.csproj", "Nemera.Infrastructure/"]
|
||||
COPY ["Nemera.DataAccess/Nemera.DataAccess.csproj", "Nemera.DataAccess/"]
|
||||
COPY ["Nemera.Plugins.Contracts/Nemera.Plugins.Contracts.csproj", "Nemera.Plugins.Contracts/"]
|
||||
COPY ["Directory.Build.props", "."]
|
||||
COPY ["Directory.Packages.props", "."]
|
||||
COPY ["global.json", "."]
|
||||
COPY ["src/AssemblyInfo_Shared.cs", "src/"]
|
||||
COPY ["src/Directory.Build.props", "src/"]
|
||||
COPY ["src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj", "src/Nemera.Presentation.Api/"]
|
||||
COPY ["src/Nemera.Application/Nemera.Application.csproj", "src/Nemera.Application/"]
|
||||
COPY ["src/Nemera.Contracts/Nemera.Contracts.csproj", "src/Nemera.Contracts/"]
|
||||
COPY ["src/Nemera.Domain/Nemera.Domain.csproj", "src/Nemera.Domain/"]
|
||||
COPY ["src/Nemera.Domain.SharedKernel/Nemera.Domain.SharedKernel.csproj", "src/Nemera.Domain.SharedKernel/"]
|
||||
COPY ["src/Nemera.Infrastructure/Nemera.Infrastructure.csproj", "src/Nemera.Infrastructure/"]
|
||||
COPY ["src/Nemera.DataAccess/Nemera.DataAccess.csproj", "src/Nemera.DataAccess/"]
|
||||
COPY ["src/Nemera.Plugins.Contracts/Nemera.Plugins.Contracts.csproj", "src/Nemera.Plugins.Contracts/"]
|
||||
|
||||
RUN dotnet restore "./Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" /p:BaseOutputPath=/app/publish/
|
||||
RUN dotnet restore "./src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" /p:BaseOutputPath=/app/publish/
|
||||
|
||||
# Build the project.
|
||||
COPY ["Nemera.Presentation.Api/", "Nemera.Presentation.Api/"]
|
||||
COPY ["Nemera.Application/", "Nemera.Application/"]
|
||||
COPY ["Nemera.Contracts/", "Nemera.Contracts/"]
|
||||
COPY ["Nemera.Domain/", "Nemera.Domain/"]
|
||||
COPY ["Nemera.Infrastructure/", "Nemera.Infrastructure/"]
|
||||
COPY ["Nemera.DataAccess/", "Nemera.DataAccess/"]
|
||||
COPY . .
|
||||
WORKDIR /src/Nemera.Presentation.Api
|
||||
COPY ["src/", "src/"]
|
||||
COPY ["build/", "build/"]
|
||||
WORKDIR /src/src/Nemera.Presentation.Api
|
||||
|
||||
RUN dotnet build "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
||||
|
||||
@@ -50,7 +49,10 @@ FROM build AS publish
|
||||
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
|
||||
RUN dotnet publish "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:BaseOutputPath=/app/publish/
|
||||
RUN dotnet publish "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:BaseOutputPath=/app/publish/ -p:BundledPluginsPredeployed=true
|
||||
# Build the bundled plugins into the publish folder, so the image contains the same plugin binaries as the verified release artifact.
|
||||
COPY ["plugins/", "/src/plugins/"]
|
||||
RUN dotnet msbuild "/src/build/build.proj" -t:BuildBundledPlugins -p:Configuration=$BUILD_CONFIGURATION -p:NemeraPluginsOutputDirectory=/app/publish/plugins/
|
||||
|
||||
# ==== Stage 3: Run stage
|
||||
#FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
|
||||
@@ -58,7 +60,8 @@ FROM base AS final
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=publish /app/publish .
|
||||
# The app user must own the published files, because the plugin installer writes into /app/plugins.
|
||||
COPY --from=publish --chown=app:app /app/publish .
|
||||
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
||||
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
||||
ENV ASPNETCORE_HTTP_PORTS=5214
|
||||
@@ -66,4 +69,4 @@ EXPOSE 5214
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
||||
|
||||
# To build this Docker image, run the following command from the root of the project (location of the .slnx solution file):
|
||||
# docker build --no-cache -t nemera-api -f Nemera.Presentation.Api/Dockerfile .
|
||||
# docker build --no-cache -t nemera-api -f src/Nemera.Presentation.Api/Dockerfile .
|
||||
@@ -0,0 +1,21 @@
|
||||
# This image ships the published release artifacts, so the recorded plugin hashes and the image contents are the same files.
|
||||
# Build it with the published API directory as the context:
|
||||
# docker build -t nemera-api -f src/Nemera.Presentation.Api/Dockerfile.release bin/api/publish
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
||||
|
||||
# Curl is used by the container healthcheck to probe the /health endpoints.
|
||||
# FFmpeg is used by the API server to remux or transcode audio the browser cannot play directly.
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends curl ffmpeg \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& mkdir -p /app /logs && chown -R app:app /app /logs
|
||||
|
||||
USER app
|
||||
WORKDIR /app
|
||||
|
||||
# The app user must own the published files, because the plugin installer writes into /app/plugins.
|
||||
COPY --chown=app:app . .
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=5214
|
||||
EXPOSE 5214
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
||||
@@ -3,7 +3,6 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UserSecretsId>37d55c87-4374-4971-82e9-012fcaad1853</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
@@ -11,10 +10,13 @@
|
||||
<DockerfileTag>nemera-api</DockerfileTag>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(OfficialReleaseBuild)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);OFFICIAL_RELEASE_BUILD</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
||||
</ItemGroup>
|
||||
@@ -69,4 +71,31 @@
|
||||
<ProjectReference Include="..\Nemera.Infrastructure\Nemera.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Nemera.DataAccess\Nemera.DataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(BundledPluginsCurrentManifest)' != ''">
|
||||
<!-- A relative current manifest path is resolved against the repository root, not the API project directory. -->
|
||||
<_BundledPluginsCurrentManifestPath Condition="$([System.IO.Path]::IsPathRooted('$(BundledPluginsCurrentManifest)'))">$(BundledPluginsCurrentManifest)</_BundledPluginsCurrentManifestPath>
|
||||
<_BundledPluginsCurrentManifestPath Condition="!$([System.IO.Path]::IsPathRooted('$(BundledPluginsCurrentManifest)'))">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\$(BundledPluginsCurrentManifest)'))</_BundledPluginsCurrentManifestPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- The API embeds the trust manifests, but it does not reference or catalog the plugin projects. The release orchestrator generates and passes the current manifest. -->
|
||||
<EmbeddedResource Include="..\..\build\BundledPlugins.manifest" LogicalName="Nemera.Presentation.Api.BundledPlugins.historical.manifest" Link="Core\Plugins\BundledPlugins.historical.manifest" />
|
||||
<EmbeddedResource Include="..\..\build\BundledPlugins.deny.manifest" LogicalName="Nemera.Presentation.Api.BundledPlugins.deny.manifest" Link="Core\Plugins\BundledPlugins.deny.manifest" />
|
||||
<EmbeddedResource Include="$(_BundledPluginsCurrentManifestPath)" LogicalName="Nemera.Presentation.Api.BundledPlugins.current.manifest" Link="Core\Plugins\BundledPlugins.current.manifest" Condition="'$(_BundledPluginsCurrentManifestPath)' != ''" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Official release builds receive the current manifest from build.proj. The API does not know the bundled plugin catalog. -->
|
||||
<Target Name="ValidateBundledPluginsCurrentManifest" BeforeTargets="AssignTargetPaths" Condition="'$(OfficialReleaseBuild)' == 'true'">
|
||||
<Error Condition="'$(_BundledPluginsCurrentManifestPath)' == ''" Text="Official release builds require the current bundled plugin manifest. Build the API through build.proj so the plugin binaries are hashed first." />
|
||||
<Error Condition="'$(_BundledPluginsCurrentManifestPath)' != '' And !Exists('$(_BundledPluginsCurrentManifestPath)')" Text="The current bundled plugin manifest '$(_BundledPluginsCurrentManifestPath)' does not exist. Build the API through build.proj so the plugin binaries are hashed first." />
|
||||
</Target>
|
||||
|
||||
<!-- Publishing uses the plugins folder already populated by the build, unless the orchestrator has already deployed the plugins. -->
|
||||
<Target Name="CopyBundledPluginsToPublish" AfterTargets="Publish" Condition="'$(BundledPluginsPredeployed)' != 'true'">
|
||||
<ItemGroup>
|
||||
<_BundledPluginPublishFile Include="$(TargetDir)plugins/**/*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(_BundledPluginPublishFile)" DestinationFolder="$(PublishDir)plugins/%(RecursiveDir)" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,5 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Application.Common.DependencyInjection;
|
||||
using Nemera.DataAccess.Common.DependencyInjection;
|
||||
using Nemera.DataAccess.Core.UoW;
|
||||
@@ -13,20 +24,11 @@ using Nemera.Infrastructure.Core.Scheduling.Notifications;
|
||||
using Nemera.Presentation.Api.Common.DependencyInjection;
|
||||
using Nemera.Presentation.Api.Common.Middlewares;
|
||||
using Nemera.Presentation.Api.Common.Utilities;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Presentation.Api.Core.Plugins;
|
||||
using Scalar.AspNetCore;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -55,7 +57,9 @@ public class Program
|
||||
builder.Services.AddPresentationApiLayerServices(builder.Configuration);
|
||||
builder.Services.AddPresentationApiTelemetryServices(builder.Configuration, builder.Environment);
|
||||
builder.Services.AddApplicationLayerServices();
|
||||
builder.Services.AddInfrastructureLayerServices(builder.Configuration);
|
||||
// The trust list only labels plugins as Official. It is read once at startup and never prevents a plugin from loading.
|
||||
IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums = BundledPluginManifestReader.ReadExpectedChecksums();
|
||||
builder.Services.AddInfrastructureLayerServices(builder.Configuration, bundledPluginChecksums);
|
||||
builder.Services.AddDataAccessLayerServices();
|
||||
builder.Services.AddDomainLayerServices();
|
||||
|
||||
@@ -179,7 +183,7 @@ public class Program
|
||||
// Ensure the default file system structure is present.
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
IServiceProvider services = scope.ServiceProvider;
|
||||
IServiceProvider services = scope.ServiceProvider;
|
||||
IFileSystemStructureSeedService context = services.GetRequiredService<IFileSystemStructureSeedService>();
|
||||
Result<Created> setDefaultDirectoriesResult = context.SetDefaultDirectories(mediaRootPath);
|
||||
if (setDefaultDirectoriesResult.IsFailure)
|
||||
|
||||
@@ -17,4 +17,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: Guid("D910C582-3905-4DD3-8BCA-0CB30852704E")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Nemera.Presentation.Api.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Nemera.Presentation.Api.IntegrationTests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
@@ -52,4 +52,9 @@ public class PluginDto
|
||||
/// Gets or sets the settings of the plugin.
|
||||
/// </summary>
|
||||
public Dictionary<string, string>? Settings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the plugin matches a trusted bundled plugin binary.
|
||||
/// </summary>
|
||||
public bool IsOfficial { get; set; }
|
||||
}
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>فشل الرفع</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>رسمي</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Upload fehlgeschlagen</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Offiziell</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Upload failed</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Official</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Error al subir</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Oficial</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Échec du téléversement</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Officiel</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Caricamento non riuscito</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Ufficiale</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>アップロードに失敗しました</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>公式</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Upload failed</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Official</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Încărcarea a eșuat</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Oficial</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Не вдалося завантажити</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>Офіційний</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>上传失败</value>
|
||||
</data>
|
||||
<data name="Official" xml:space="preserve">
|
||||
<value>官方</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -50,7 +50,14 @@
|
||||
@foreach (PluginDto plugin in Model)
|
||||
{
|
||||
<tr data-plugin-id="@plugin.Id">
|
||||
<td>@plugin.Name</td>
|
||||
<td>
|
||||
@plugin.Name
|
||||
@* Only a loaded plugin can carry the Official badge; a failed plugin has no trusted binary to describe. *@
|
||||
@if (plugin.LoadStatus == PluginLoadStatus.Loaded && plugin.IsOfficial)
|
||||
{
|
||||
<span class="plugin-official-badge">@_localizer["Official"]</span>
|
||||
}
|
||||
</td>
|
||||
<td>@plugin.Author</td>
|
||||
<td>@plugin.Version</td>
|
||||
<td>@plugin.Description</td>
|
||||
|
||||
@@ -11,22 +11,25 @@ EXPOSE 5012
|
||||
|
||||
|
||||
# ==== Stage 1: Build stage
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0.100 AS build
|
||||
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# Restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages).
|
||||
COPY ["AssemblyInfo_Shared.cs", "."]
|
||||
COPY ["Nemera.Presentation.Web/Nemera.Presentation.Web.csproj", "Nemera.Presentation.Web/"]
|
||||
COPY ["Directory.Build.props", "."]
|
||||
COPY ["Directory.Packages.props", "."]
|
||||
COPY ["global.json", "."]
|
||||
COPY ["src/AssemblyInfo_Shared.cs", "src/"]
|
||||
COPY ["src/Directory.Build.props", "src/"]
|
||||
COPY ["src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj", "src/Nemera.Presentation.Web/"]
|
||||
|
||||
RUN dotnet restore "./Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" /p:BaseOutputPath=/app/publish/
|
||||
RUN dotnet restore "./src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" /p:BaseOutputPath=/app/publish/
|
||||
|
||||
# Build the project.
|
||||
COPY ["Nemera.Presentation.Web/", "Nemera.Presentation.Web/"]
|
||||
COPY . .
|
||||
WORKDIR /src/Nemera.Presentation.Web
|
||||
COPY ["src/", "src/"]
|
||||
WORKDIR /src/src/Nemera.Presentation.Web
|
||||
|
||||
RUN dotnet build "./Nemera.Presentation.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
||||
|
||||
@@ -43,7 +46,7 @@ FROM base AS final
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=publish /app/publish .
|
||||
COPY --from=publish --chown=app:app /app/publish .
|
||||
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
||||
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
||||
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||
@@ -51,4 +54,4 @@ EXPOSE 5012
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
||||
|
||||
# To build this Docker image, run the following command from the root of the project (location of the .slnx solution file):
|
||||
# docker build --no-cache -t nemera-web -f Nemera.Presentation.Web/Dockerfile .
|
||||
# docker build --no-cache -t nemera-web -f src/Nemera.Presentation.Web/Dockerfile .
|
||||
@@ -0,0 +1,19 @@
|
||||
# This image ships the published release artifacts, so the image contents are the same files the release workflow exported.
|
||||
# Build it with the published Web directory as the context:
|
||||
# docker build -t nemera-web -f src/Nemera.Presentation.Web/Dockerfile.release bin/web/publish
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
||||
|
||||
# Curl is used by the container healthcheck to probe the /health endpoints.
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends curl \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& mkdir /logs && chown -R app:app /logs
|
||||
|
||||
USER app
|
||||
WORKDIR /app
|
||||
|
||||
COPY --chown=app:app . .
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||
EXPOSE 5012
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
||||
@@ -3,7 +3,7 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\web\</BaseOutputPath>
|
||||
<BaseOutputPath>$(RepoRoot)bin/web/</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<WarningsNotAsErrors>$(WarningsNotAsErrors);EXTEXP0018</WarningsNotAsErrors>
|
||||
<UserSecretsId>10a94da9-18ed-4c70-a9da-b461e08958c4</UserSecretsId>
|
||||
|
||||
@@ -2516,3 +2516,17 @@ html.audio-player-initializing .audio-player-container {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Informational badge for a loaded bundled plugin whose binary matches the release trust list. */
|
||||
.plugin-official-badge {
|
||||
display: inline-block;
|
||||
margin-left: 0.4rem;
|
||||
padding: 0 0.35rem;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 2px;
|
||||
font-size: 0.7em;
|
||||
line-height: 1.4;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
vertical-align: middle;
|
||||
}
|
||||
+13
-1
@@ -31,7 +31,9 @@
|
||||
<Folder Name="/docs/manual/using-nemera/">
|
||||
<File Path="../docs/manual/using-nemera/index.md" />
|
||||
</Folder>
|
||||
<Folder Name="/docs/technical/" />
|
||||
<Folder Name="/docs/technical/">
|
||||
<File Path="../docs/technical/RELEASING.md" />
|
||||
</Folder>
|
||||
<Folder Name="/docs/technical/api/" />
|
||||
<Folder Name="/docs/technical/api/admin/" />
|
||||
<Folder Name="/docs/technical/api/admin/authorization/">
|
||||
@@ -359,6 +361,16 @@
|
||||
<Project Path="../plugins/Nemera.Plugins.OpenLibrary/Nemera.Plugins.OpenLibrary.csproj" />
|
||||
<Project Path="../plugins/Nemera.Plugins.Pdf/Nemera.Plugins.Pdf.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/build/">
|
||||
<File Path="../Directory.Build.props" />
|
||||
<File Path="../global.json" />
|
||||
<File Path="../build/build.proj" />
|
||||
<File Path="../build/BundledPlugins.props" />
|
||||
<File Path="../build/BundledPlugins.manifest" />
|
||||
<File Path="../build/BundledPlugins.deny.manifest" />
|
||||
<File Path="../src/Nemera.Presentation.Api/Dockerfile.release" />
|
||||
<File Path="../src/Nemera.Presentation.Web/Dockerfile.release" />
|
||||
</Folder>
|
||||
<Folder Name="/Solution Items/">
|
||||
<File Path="../.editorconfig" />
|
||||
</Folder>
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
<DockerPublishLocally>False</DockerPublishLocally>
|
||||
<ProjectGuid>d4c61542-fc91-47fa-b1d2-11cc99617454</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<!-- Keep the compose project's empty build output under the repository bin directory. -->
|
||||
<OutputPath>$(RepoRoot)bin/docker-compose/$(Configuration)/</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="docker-compose.override.yml">
|
||||
<DependentUpon>docker-compose.yml</DependentUpon>
|
||||
@@ -14,6 +18,6 @@
|
||||
<DependentUpon>docker-compose.yml</DependentUpon>
|
||||
</None>
|
||||
<None Include="docker-compose.yml" />
|
||||
<None Include=".dockerignore" />
|
||||
<None Include="..\.dockerignore" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -2,8 +2,8 @@ services:
|
||||
nemera-api:
|
||||
container_name: nemera-api
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Nemera.Presentation.Api/Dockerfile
|
||||
context: ..
|
||||
dockerfile: src/Nemera.Presentation.Api/Dockerfile
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Development
|
||||
- ASPNETCORE_HTTP_PORTS=5214
|
||||
@@ -18,8 +18,8 @@ services:
|
||||
nemera-web:
|
||||
container_name: nemera-web
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Nemera.Presentation.Web/Dockerfile
|
||||
context: ..
|
||||
dockerfile: src/Nemera.Presentation.Web/Dockerfile
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Development
|
||||
- ASPNETCORE_HTTP_PORTS=5012
|
||||
|
||||
@@ -3,8 +3,8 @@ services:
|
||||
container_name: nemera-api
|
||||
image: ${DOCKER_REGISTRY-}nemera-api
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Nemera.Presentation.Api/Dockerfile
|
||||
context: ..
|
||||
dockerfile: src/Nemera.Presentation.Api/Dockerfile
|
||||
environment:
|
||||
- LOG_PATH=/logs
|
||||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
||||
@@ -26,8 +26,8 @@ services:
|
||||
container_name: nemera-web
|
||||
image: ${DOCKER_REGISTRY-}nemera-web
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Nemera.Presentation.Web/Dockerfile
|
||||
context: ..
|
||||
dockerfile: src/Nemera.Presentation.Web/Dockerfile
|
||||
environment:
|
||||
- LOG_PATH=/logs
|
||||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "10.0.100",
|
||||
"rollForward": "disable"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user