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:
BinaryAlley committed 2026-11-28 18:00:00 +02:00
1 parent 3fb8912c7f
commit b30cbd6b9e
114 files changed
+2708 -243

No files matched your search

+3
View File
@@ -657,3 +657,6 @@ public void Add_WhenCalledWithVariousInputs_ShouldReturnExpectedSum(int a, int b
### Security Testing
- Include tests that verify security measures (e.g., authentication, authorization)
## Releasing
Releases are cut only by the repository owner. The required GitHub environment, release branch ruleset, secrets, credential rotation and troubleshooting steps are documented in [Releasing](./technical/RELEASING.md).
+2
View File
@@ -86,6 +86,8 @@ Use a release package or installer when one is available, or, with the .NET 10 S
dotnet build Nemera.slnx
```
The official release artifacts include the PDF plugin's native libraries for Linux x64 and ARM64 (including Alpine x64), macOS Intel and Apple Silicon, and Windows x64 and ARM64. The single release download works on those platforms; the plugin loads the native libraries that match the host at runtime.
Run the API and the web client from the installed release package or from the published build. In development, their addresses come from each project's `launchSettings.json` (`http://localhost:5214` and `http://localhost:5012`). When you run a published build directly on a host, set the addresses yourself, either with `ASPNETCORE_URLS` or with `ASPNETCORE_HTTP_PORTS`:
```bash
+9 -3
View File
@@ -44,9 +44,9 @@ The `Needs web` column is worth pausing on: the providers marked `yes` reach out
## Installing a plugin
Plugins are managed from the administration area, on the Plugins page, which only administrators can open. To install one, upload either a single `.dll` assembly or a `.zip` archive that holds the assembly together with any dependencies it needs.
Plugins are managed from the administration area, on the Plugins page, which only administrators can open. To install one, upload either a single `.dll` assembly or a `.zip` archive that holds the assembly together with any managed dependency assemblies it needs. Only `.dll` entries are installed from the archive; dependency manifests, native `.so` and `.dylib` libraries, and the original directory structure are not.
The uploaded files are placed in the plugin storage directory, `plugins` by default, and are picked up at the **next startup of the API**. In other words, after installing a plugin, restart the API server for it to take effect. Installing is a supervised operation: the archive is unpacked into a flat set of assemblies inside the plugin directory, and any directory component in the upload is stripped, so a crafted archive cannot write outside that directory.
The uploaded files are placed in the plugin storage directory, `plugins` by default, and are picked up at the **next startup of the API**. In other words, after installing a plugin, restart the API server for it to take effect. Installing is a supervised operation: the archive is unpacked into a flat set of `.dll` files inside the plugin directory, and any directory component in the upload is stripped, so a crafted archive cannot write outside that directory.
Once installed and restarted, the plugin appears on the Plugins page with its name, author, version and description.
@@ -59,6 +59,12 @@ Each plugin is listed with one of two states:
Nemera reconciles the list at every startup. A plugin that is no longer present in the storage directory is forgotten, together with the per library settings that referenced it.
Every official release of Nemera embeds the SHA-256 checksum of each bundled plugin's main assembly, plus an append-only list of checksums from earlier official releases. A plugin whose main assembly matches an entry is marked **Official**. The checksum covers only that main assembly; the libraries and native files shipped next to it are not checksummed. The list keeps older bundled versions recognized, so shipping a new version does not make an older one unofficial. A checksum can be revoked through the project's deny list; a revoked binary is no longer marked Official, but it still loads.
The **Official** mark is meaningful only when Nemera itself came from an official release published by the project. If you built Nemera yourself or are running a modified build, that build does not generate the current release's trust entries, so a plugin you rebuild locally is not marked Official unless it matches a binary from an earlier official release. Nemera does not call home to check plugin checksums against a server-side list, because that would conflict with the project's no outbound calls policy. The release channel is the trust anchor instead.
The **Official** mark is informational. It never prevents a plugin from loading, and plugins always work whether they are marked or not.
## Uninstalling a plugin
There is no uninstall button. To remove a plugin, delete its assembly (and any files that came with it) from the plugin storage directory and restart the API. The plugin then disappears from the list, and the settings that enabled it for your libraries are cleaned up.
@@ -81,7 +87,7 @@ The shipped plugins use these settings for practical things, such as the base ad
## Writing your own plugin
Anyone can write a plugin, and it is the intended way to teach Nemera about a new source or a new format. A plugin is a .NET assembly targeting the same framework as the server, referencing the `Nemera.Plugins.Contracts` project. To be a plugin it implements `IPlugin`, which describes it and lists its settings, and `IPluginServiceRegistrator`, which wires its services up. To contribute a capability it also implements one or more of `IMetadataProvider`, `IArtworkProvider` and `IBookReader`. Package the built assembly, and any dependencies, into a ZIP and install it like any other plugin.
Anyone can write a plugin, and it is the intended way to teach Nemera about a new source or a new format. A plugin is a .NET assembly targeting the same framework as the server, referencing the `Nemera.Plugins.Contracts` project. To be a plugin it implements `IPlugin`, which describes it and lists its settings, and `IPluginServiceRegistrator`, which wires its services up. To contribute a capability it also implements one or more of `IMetadataProvider`, `IArtworkProvider` and `IBookReader`. Package the built assembly, and any managed dependency assemblies, into a ZIP and install it like any other plugin. Only `.dll` files are installed from an archive, so the upload flow does not support plugins that need native `.so` or `.dylib` libraries.
## Security
+188
View File
@@ -0,0 +1,188 @@
# Releasing
## Contents
- [Overview](#overview)
- [Required GitHub settings](#required-github-settings)
- [Release branch ruleset](#release-branch-ruleset)
- [Release environment](#release-environment)
- [Secrets](#secrets)
- [Workflows](#workflows)
- [Cutting a release](#cutting-a-release)
- [Revoking a bundled plugin hash](#revoking-a-bundled-plugin-hash)
- [Rotating credentials](#rotating-credentials)
- [Troubleshooting](#troubleshooting)
## Overview
Releases are cut only by the repository owner. There is one official build, and it runs on the release branch.
1. The owner creates a `release/x.y.z` branch from `master`.
2. The `Publish Release` workflow builds and publishes the official artifacts with `OfficialReleaseBuild=true`.
3. The same workflow verifies the published API assembly against the published plugin binaries, records the release's plugin hashes in the append-only trust list, builds the release images from the verified publish output, and opens a pull request to `master`.
4. The owner downloads the official artifacts and creates the GitHub release and tag.
5. The owner merges the trust-list pull request. The current release already embeds its own official plugin manifest, so this pull request keeps the release's plugin binaries Official in future releases.
The full test suite runs on normal pull requests to `master`. The release build does not rerun the full suite. It runs the manifest verification tests for the official build, publishes, verifies the published API assembly against the published plugin binaries, records the hashes and builds the release images from the verified publish output.
The repository pins the .NET SDK in `global.json`. The workflows install that exact SDK, and the Docker build stage uses the matching `10.0.100` SDK image, so root-level and container builds use the same toolchain.
The `release-api` artifact is a single framework-dependent publish built on `ubuntu-latest`. The bundled plugin deployment keeps the PDF plugin's native libraries for the supported runtime identifiers: `win-x64`, `win-arm64`, `linux-x64`, `linux-arm64`, `linux-musl-x64`, `osx-x64` and `osx-arm64`. The macOS packages also keep their shared SkiaSharp library in the `osx` fallback folder, which the build retains automatically even though no device reports that identifier. The list is defined by `BundledPluginRuntimeIdentifiers` in `plugins/Directory.Build.props`, and the PDF plugin validates its required native libraries for every identifier in it, accepting a library from either the identifier's own folder or its OS family fallback. The plugin resolves the matching native library at runtime from its dependency manifest. The release Docker images copy that same publish output.
The presentation host does not compile against the concrete plugin projects, and it does not own the bundled plugin catalog. The plugin projects are part of the solution and copy their outputs to the API plugin folder. `build.proj` owns the release catalog: it builds and hashes the plugin binaries, writes the current manifest, passes that manifest to the API publish, and copies the binaries into the published plugin folder. Adding or removing a bundled plugin changes the release catalog and the solution, not the host project.
## Required GitHub settings
### Release branch ruleset
Create a repository ruleset under **Settings > Rules > Rulesets > New branch ruleset**:
- Target branches: `refs/heads/release/*`.
- Enable **Restrict creations**, **Restrict updates**, **Restrict deletions**, and **Block force pushes**.
- Bypass list: add only the owner's user account. Do not add the repository admin role if more than one administrator exists.
This prevents write collaborators from creating or pushing release branches. The ruleset enforces who can create the branch. The owner can create it from the GitHub Branches page or by pushing it.
The `Publish Release` workflow runs only when a branch matching `release/x.y.z` is created, and only when the actor is the repository owner.
### Release environment
Create an environment under **Settings > Environments > New environment** named `release`:
- Required reviewers: the owner.
- Deployment branches: allow `master` and `release/*`. A `create` event runs on the branch that was created, so the `publish` job runs on the release branch; the `record-manifest` job checks out `master` in that same release-branch run.
- Environment secrets:
- `SIXLABORS_LICENSE_KEY`
- `RELEASE_PR_TOKEN`
The `publish` job uses the license secret and has a read-only token. The `record-manifest` job uses the pull request token and does not have the license secret. The environment approval is the gate for both jobs.
### Secrets
#### SIXLABORS_LICENSE_KEY
This is the Six Labors license key content.
- The value to be put in the secret is the content of the license file, or the value already stored in the existing repository secret used by `Run All Tests`.
- `Run All Tests` uses the repository secret `SIXLABORS_LICENSE_KEY`.
- `Publish Release` uses the environment secret `SIXLABORS_LICENSE_KEY` in the `release` environment.
- `Publish Release` also exposes the secret as the `SixLaborsLicenseKey` MSBuild environment property, so every project that references ImageSharp validates the license, not only `Nemera.Domain`.
If the key is missing or expired, the build fails with a message such as `No Six Labors license found` or an expired license error.
#### RELEASE_PR_TOKEN
This is a fine-grained GitHub personal access token owned by the repository owner.
Create it under **Settings > Developer settings > Personal access tokens > Fine-grained tokens > Generate new token**:
- Resource owner: the owner's account.
- Repository access: only `BinaryAlley/Nemera`.
- Permissions:
- `Contents: Read and write`
- `Pull requests: Read and write`
- `Metadata: Read-only` is added automatically.
- Expiration: set an explicit date, for example 90 days, and add a calendar reminder.
Copy the generated `github_pat_...` value immediately. GitHub shows it only once. Store it as the `RELEASE_PR_TOKEN` environment secret in the `release` environment.
Why a personal access token is needed: pull requests created with the workflow `GITHUB_TOKEN` do not trigger `pull_request` workflows. The trust-list pull request must run `Run All Tests` and the branch validators, so the `record-manifest` job pushes and creates the pull request with this token.
The token is used only by the `record-manifest` job. It is not available to the build job, and the build job's token is read-only. The `record-manifest` checkout uses the token as its git token, so the persisted git credential is the PAT and both `git push` and `gh pr create` authenticate with it.
## Workflows
- `Publish Release` runs when the owner creates a `release/x.y.z` branch. It has two jobs:
- `publish`: builds and publishes the official artifacts with `OfficialReleaseBuild=true`, runs the manifest verification tests, verifies the published API assembly against the published plugin binaries, records the released plugin hashes, builds the release images from the verified publish output, and uploads the `release-api`, `release-web` and `bundled-plugins-manifest` artifacts. It has the license secret and a read-only token.
- `record-manifest`: downloads the manifest artifact, appends only the release entries that are missing from master's current trust list, and opens the `other/record-release-x.y.z` pull request to `master` with the `RELEASE_PR_TOKEN`. It does not have the license secret.
- `Run All Tests` runs on pull requests to `master` and uses the repository `SIXLABORS_LICENSE_KEY` secret.
- `Branch Push Naming Convention Check` and `Pull Request Source Branch Validation Check` allow `feature/`, `bugfix/`, `hotfix/`, `documentation/`, `refactor/`, `other/`, and `release/x.y.z`.
The release branch is built from `master` after the normal pull request checks have passed. The release build does not rerun the full test suite. It runs the manifest verification tests, because that is the only part of the build that changes when the official plugin manifest and the official release marker are embedded. It then verifies the published API assembly against the published plugin binaries before recording hashes or building images. The trust-list pull request runs the full suite before it can be merged.
Recording is CI-only. The publish job checks that the worktree is clean and that `HEAD` matches `origin/master` before it appends to the trust list. A local `RecordBundledPlugins` run is rejected by the guard.
The trust list `build/BundledPlugins.manifest` is append-only. Never remove existing entries. The record job uses master's current file as the base and appends only the entries that are missing from it, skipping duplicates, so the record pull request diff contains additions only. Use the release workflow, which calls `RecordBundledPlugins`, instead of editing the file by hand. The deny list `build/BundledPlugins.deny.manifest` is the revocation path: add an entry to stop trusting a hash, and remove the entry to restore trust.
## Cutting a release
1. Ensure that everything you want in the release is on `master`, that the previous release's trust-list pull request is merged, and that the normal pull request checks have passed.
2. Verify that `SIXLABORS_LICENSE_KEY` and `RELEASE_PR_TOKEN` are present and current in the `release` environment, and that the repository `SIXLABORS_LICENSE_KEY` secret is current.
3. Create the `release/x.y.z` branch from the current `master` as the owner. The publish job requires the branch to point at the current `origin/master`. The check is exact: if anything merges to `master` before the job runs, the job fails and the branch must be recreated from the new `master`.
4. Approve the `release` environment for the `publish` and `record-manifest` jobs.
5. Wait for `Publish Release` to publish and verify the official artifacts, record the trust list and build the release images.
6. Download the `release-api` and `release-web` artifacts.
7. Create the GitHub release and tag manually from those artifacts. The workflow does not create the release.
8. Wait for `Run All Tests` and both branch validators on the `other/record-release-1.2.3` pull request. Review the trust-list diff and merge it.
9. The workflow builds the release images from the verified publish output to validate the image definitions, but it does not upload them. Build the images you ship from the downloaded artifacts, so they contain exactly the plugin binaries whose hashes were recorded:
```bash
docker build -t nemera-api:1.2.3 -f src/Nemera.Presentation.Api/Dockerfile.release <release-api-directory>
docker build -t nemera-web:1.2.3 -f src/Nemera.Presentation.Web/Dockerfile.release <release-web-directory>
```
To publish, verify and build in one local step instead, run:
```bash
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:Version=1.2.3
```
That target publishes from source, verifies the publish output and builds the images from it. Those images are not the exact released artifacts unless the build is byte-identical, so prefer the downloaded artifacts for the images you ship.
The local equivalent of the official build is verification only. Recording is CI-only. The release workflow checks that the checkout is clean and that `HEAD` matches `origin/master` exactly before it appends to the trust list.
```bash
dotnet msbuild build/build.proj -t:VerifyPublishedBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true
```
For a local Release build, set `SixLaborsLicenseKey` to the content of `src/Nemera.Domain/sixlabors.lic` first. The file alone is only discovered by `Nemera.Domain`, and projects that reference ImageSharp through it fail license validation otherwise.
## Revoking a bundled plugin hash
The main trust list is append-only, so revoke a bad hash instead of removing it:
1. Add a `<assembly file name>|<SHA-256>` line to `build/BundledPlugins.deny.manifest`.
2. Merge the change to `master`.
3. The next build embeds the deny list. The reader removes the hash from both the historical and the current trust lists, so a plugin with that hash is no longer marked Official. It still loads.
The deny list is intentionally not append-only. Remove the line to restore trust if the revocation was a mistake.
## Rotating credentials
### Six Labors license
When the license is renewed or replaced:
1. Put the new value in the repository secret `SIXLABORS_LICENSE_KEY` used by `Run All Tests`.
2. Put the same value in the environment secret `SIXLABORS_LICENSE_KEY` in the `release` environment.
3. Re-run the failed workflow.
The local `src/Nemera.Domain/sixlabors.lic` file is only a local copy. Update it for local Release builds, but never commit it.
### RELEASE_PR_TOKEN
When the token expires, is revoked or is compromised:
1. Generate a new fine-grained token with the same repository access and permissions.
2. Replace the `RELEASE_PR_TOKEN` environment secret in the `release` environment.
3. Re-create the release branch or re-run the failed `Publish Release` workflow, depending on where it failed.
4. Revoke the old token.
If the token is compromised, also review recent branches, pull requests and workflow runs. The token has only `Contents` and `Pull requests` write access to this repository.
## Troubleshooting
| Symptom | Cause | Fix |
| --- | --- | --- |
| `Publish Release` does not run | The created ref is not a `release/x.y.z` branch, or the actor is not the repository owner. | Create the branch as the owner using the three-part version. |
| The workflow waits for approval | The `release` environment has required reviewers. | Approve the `publish` and `record-manifest` jobs as the owner. |
| `No Six Labors license found` | The secret is missing or empty. | Check the repository secret and the `release` environment secret. |
| Six Labors license expired | The license key is no longer valid. | Renew it, update both secrets and re-run. |
| `git push` or `gh pr create` fails with 401 or 403 | `RELEASE_PR_TOKEN` is missing, expired or lacks `Contents` or `Pull requests` write, or the `record-manifest` checkout does not use it as the git token. | Generate a new token if needed, update the environment secret, and ensure the `record-manifest` checkout passes it as `token`. |
| The trust-list pull request has no CI | It was created with `GITHUB_TOKEN` instead of the PAT. | Verify that the `record-manifest` job uses `RELEASE_PR_TOKEN` and that the secret is current. |
| A release branch is rejected by the ruleset | The branch was not created by the owner. | Create it as the owner. The bypass list must contain only the owner's account. |
| The branch validator rejects a release branch | The branch is not `release/x.y.z`. | Use three numeric parts, for example `release/1.2.3`. |
| The branch validator rejects the trust-list pull request | The branch prefix is not allowed. | The workflow uses `other/record-release-x.y.z`, which is allowed. |
| `Official` is false in a release | The build did not use `OfficialReleaseBuild=true`, or the plugin binary does not match the trust manifest. | Use the `Publish Release` workflow, or pass `-p:OfficialReleaseBuild=true` with `Configuration=Release`. |
| `RecordBundledPlugins` fails | Recording is attempted outside GitHub Actions, from a dirty worktree, from a commit that is not the current `origin/master`, or without `Configuration=Release` and `OfficialReleaseBuild=true`. | Use the `Publish Release` workflow. Commit or stash changes, merge the previous trust-list pull request, and recreate the release branch from `master`, if the guard reports a tree or history problem. |
| `RecordBundledPlugins` fails because `master` moved | The release branch no longer matches the current `origin/master`. | Recreate the `release/x.y.z` branch from the new `master` and approve the new run. |
| The record-list pull request removes trust-list lines | The merge step was skipped, or master's current manifest was replaced with an older artifact. | The record job only appends missing entries and fails if the staged diff removes a line. Rerun the workflow. |
| A known good plugin is not Official | A deny-list entry matches its hash. | Remove the matching line from `build/BundledPlugins.deny.manifest`. |
| `VerifyPublishedBundledPlugins` fails | The manifest embedded in the published API assembly does not match the published plugin binaries. | Re-run the release build from the same commit. Do not mix artifacts from different builds. |
| The release image build fails with an official configuration error | `Docker` was called with `OfficialReleaseBuild=true` and a configuration other than `Release`. | Pass `-p:Configuration=Release`. |
@@ -66,6 +66,8 @@ GET api/v1/plugins
200 Ok
```
`isOfficial` is true when the plugin's main assembly matches a checksum from the append-only list of previous official releases, after the checksums in the deny list are removed. The checksum covers only the plugin's main assembly; the libraries and native files shipped next to it are not checksummed. An official release build also embeds and trusts the checksums of its own bundled plugins; a non-official build does not trust its own plugin binaries. A plugin that does not match, or whose checksum is denied, still loads and runs. The flag is informational only and never affects loading.
```json
[
{
@@ -76,6 +78,7 @@ GET api/v1/plugins
"description": "Retrieves artist, album and track metadata from MusicBrainz.",
"loadStatus": "Loaded",
"loadError": null,
"isOfficial": true,
"settings": {
"BaseUrl": "https://musicbrainz.org/ws/2/",
"DoesAllowPrivateBaseUrl": "false",