Provision US-16 dependencies credentials HTTPS and native service configurations

This commit is contained in:
Steffen committed 2026-10-06 09:11:28 +02:00
1 parent 950f67d8b7
commit eedf2a941b
34 files changed
+1703 -373

No files matched your search

+217 -163
View File
@@ -1,198 +1,252 @@
# US-16 — Independent Linux installation
# US-16 — Provision and install HealthApp
The installer supports one service, a comma-separated subset, or `all`. The same
published application executables work for colocated and distributed deployments.
Each service retains its own process, environment file and systemd registration.
No additional service, shared persistence, shared application library or communication
shortcut is introduced. Application services continue communicating through the API Gateway.
The installer provisions a working prototype topology. A normal installation no longer
requires prepared application configuration, database roles/passwords, service keys,
or HTTPS certificates. Select one service, a comma-separated subset, or `all`.
## Supported host and prerequisites
The application DLLs and shared C# provisioning utility are portable. OS adapters
perform package installation and native service registration: systemd on supported
Linux hosts, Windows Services on Windows, and launchd on macOS. Deployment location
and OS do not combine services, introduce shared persistence or change gateway-routed
communication. There is no container/orchestration requirement.
Use a Linux host with Bash 4 or later, GNU core utilities/grep/sed, a running systemd
system manager with systemd-run, and the .NET 10 ASP.NET Core runtime. Live installation
requires root and the standard `getent`, `groupadd`, `useradd` and `id` tools. Network
verification additionally requires curl. Building a release requires the .NET 10 SDK
and the repository's NuGet dependencies; deployment hosts do not need the SDK/source.
## Build the release
Provision PostgreSQL for Patient/Profile and Observation separately, with independent
database names/users and credentials matching each service's configuration. The DBs
may be on remote hosts. Insights and Health Overview have no databases. Provision
trusted HTTPS certificates and the externally configured accounts/service credentials
before starting production services. The installer does not install an identity
provider, PostgreSQL, runtime packages or certificates and does not generate accounts.
These remain administrator-supplied prerequisites, as in the existing deployment model.
## Build a release
From the repository root:
A build machine needs the .NET 10 SDK and package access. It is distinct from a target
machine, where the installer supplies missing runtime/dependencies.
```bash
bash deploy/build-release.sh --output /tmp/healthapp-release
# Or publish only the service(s) needed on a particular host:
bash deploy/build-release.sh --output /tmp/healthapp-insights-release --services insights
# Optional: build just a selected application's payload plus the provisioning utility.
bash deploy/build-release.sh --output /tmp/healthapp-insights --services insights
```
Output must be a new directory. Optionally set `HEALTHAPP_DOTNET` to the SDK executable.
The release contains selected payloads under `services/`, their systemd units,
configuration examples, installation/verification scripts and this guide. Transfer it
to the target Linux host using your normal deployment transport. Release contents
are trusted executable deployment input; configuration secrets are not part of it.
On a Windows build machine, use `deploy/build-release.ps1 -Output NEW_DIRECTORY`
from PowerShell with the same optional `-Services` selection.
## Prepare independent configuration
The bundle includes the application DLLs, provisioning utility, OS installers, units,
examples and this guide. Windows services invoke `dotnet Application.dll`, so they do
not depend on a Linux-generated apphost executable. The small Microsoft WindowsServices
hosting dependency lets the same ASP.NET Core applications respond to Windows service
control; it is inactive on Linux/macOS. No production service references another service.
Copy each selected `examples/NAME.env.example` to a protected administrator directory
as `NAME.env`. Replace placeholders with actual values. Existing examples deliberately
use remote hostnames and separate DB credentials; they are not usable credentials.
Transfer the release by normal administrative deployment transport. Public release
files contain no generated secrets. Build output must be a new directory.
Service names and resulting paths:
## Normal Ubuntu/Debian installation
| Selection name | Application | Configuration | systemd unit |
| --- | --- | --- | --- |
| api-gateway | ApiGateway.dll | /etc/healthapp/api-gateway.env | healthapp-api-gateway.service |
| patient-profile | PatientProfileService.dll | /etc/healthapp/patient-profile.env | healthapp-patient-profile.service |
| observation | ObservationService.dll | /etc/healthapp/observation.env | healthapp-observation.service |
| insights | InsightsService.dll | /etc/healthapp/insights.env | healthapp-insights.service |
| health-overview | HealthOverviewService.dll | /etc/healthapp/health-overview.env | healthapp-health-overview.service |
Automatic Linux package provisioning currently supports Ubuntu 24.04 and Debian 12/13,
with a running systemd manager and administrative access. This is the implemented
Linux adapter's supported set, not a restriction in the application binaries. Other
Linux distributions need corresponding package-manager integration before the installer
can claim native dependency provisioning there. Internet access to the signed OS/.NET
package feeds is needed when dependencies are absent.
Supply each service's own network binding via `ASPNETCORE_URLS`, its needed endpoints,
credentials and (where applicable) DB connection string. The gateway needs all service
origins/keys even when their services are deployed on other machines. Other services
need only their documented dependencies; installation does not require them locally.
Use distinct service credentials in both directions, matching the gateway and service
settings described in `src/AUTHENTICATION.md`. Never reuse example placeholders.
Keep production `ASPNETCORE_ENVIRONMENT=Production` and configure HTTPS origins,
certificate path/password and trust chains on each host. Certificate files must be
readable by the `healthapp` service identity. For example, externally provision files
under `/etc/healthapp` with group `healthapp` and mode `0640`. The installer makes that
directory root-owned with group access, and environment files root-only `0600`;
systemd reads environment files and passes values into the relevant process.
`Authentication__KeyDirectory` belongs to the gateway host alone. The gateway unit's
StateDirectory creates `/var/lib/healthapp-api-gateway`; its `keys` child is created
by data protection. Other machines never require that directory or another service's
local application/configuration files. Only configured network APIs cross machines.
For local development tests, Development permits HTTP; production still requires
HTTPS. No deployment path/hostname is hard-coded in an application.
## Install selected services
From the transferred release directory, assuming prepared config in `/root/healthapp-config`:
From the release directory:
```bash
# One service, with dependencies running on independently configured hosts:
sudo bash install.sh --services insights --config-dir /root/healthapp-config
# A subset (use this instead of the preceding command on a fresh host):
sudo bash install.sh --services patient-profile,observation --config-dir /root/healthapp-config --migrate
# Complete fresh installation:
sudo bash install.sh --services all --config-dir /root/healthapp-config --migrate --start
sudo bash install.sh --services all --host 192.168.1.20
```
`--bundle DIRECTORY` selects a release explicitly. `--dotnet /absolute/runtime/path`
changes only ExecStart in selected units, when dotnet is not installed at `/usr/bin/dotnet`.
The installer checks the .NET 10 ASP.NET Core runtime on a live host.
Use the target's reachable DNS name/IP for `--host`. The default `localhost` is useful
for a wholly local prototype; use a reachable address for another computer to access
it. No later application-file editing is required.
Installation creates the conventional `healthapp` service user/group if absent,
copies selected independent applications to `/opt/healthapp/NAME`, copies selected
configurations to `/etc/healthapp/NAME.env`, registers selected units under
`/etc/systemd/system`, reloads systemd and enables only those units for boot.
It preflights the full selection before writing files. Unselected service files,
configuration and registrations are untouched; no service dependency/PartOf/BindsTo
relationships are introduced between HealthApp units.
Default installation does not start services or modify schemas. `--migrate` explicitly
runs the selected Patient/Profile and/or Observation application's existing migration
mode, under its service identity/configuration, using a transient systemd unit. It
never migrates Insights/Overview or another service's DB. `--start` explicitly starts
the selected units after successful installation/migrations. For migrations run
separately, use the existing published `--migrate` commands with that service's
configuration, then start its unit.
Existing installation directories, env files or units cause refusal before writes.
This is a first-install mechanism, not an upgrade/uninstall tool. It never overwrites
existing configuration, removes persistent data or guesses how to rotate credentials.
A live copy/migration/systemd error can leave installed files or earlier selected units
configured; the command fails and those files/data are retained for administrator
inspection. There is no cross-service deployment transaction or automatic rollback.
`--root /absolute/staging/directory` stages an offline filesystem tree without root,
user creation, runtime checks or systemctl calls. It is for testing/image preparation,
not a completed live installation. It refuses `--start`/`--migrate`. Provision the
runtime, healthapp user/group, config-directory group/certificate access and gateway
state-directory ownership on the target, then reload/enable/start the selected units.
The paths *inside* each unit refer to the target's `/opt` and `/etc`, not to the
staging directory. Never mistake successful staging for successful startup.
## Manage and verify installation
Each unit can be independently managed using, for example:
For an individual service, use its name and an existing matching generated deployment
from the overall topology, which already specifies its remote dependencies/keys:
```bash
sudo systemctl start healthapp-insights.service
sudo systemctl stop healthapp-insights.service
sudo systemctl restart healthapp-insights.service
sudo journalctl -u healthapp-insights.service
sudo bash install.sh --services insights --deployment /secure/generated-deployment
```
Stopping a dependency may cause application requests needing it to fail; it does not
stop peer processes. Services need no local process-start ordering or shared memory.
Names: `api-gateway`, `patient-profile`, `observation`, `insights`, `health-overview`.
Prepare a protected probe directory with `NAME.curl` files for each selected service.
These are curl data configuration files (not shell scripts), containing the actual
HTTPS URL, trusted CA and credentials appropriate for a *read-only* HTTP 200 request.
For example, Insights can use a configured patient/period that has observation data:
The installer:
```text
url = "https://insights.example.test:5083/api/patients/PATIENT_ID/insights?from=2026-09-01&to=2026-09-10"
header = "X-Gateway-Key: ACTUAL_INSIGHTS_GATEWAY_CREDENTIAL"
cacert = "/etc/healthapp/trusted-ca.pem"
1. Detects .NET 10 ASP.NET Core runtime and local PostgreSQL availability; installs
missing dependencies from supported package feeds. PostgreSQL is provisioned only
when Patient/Profile or Observation is selected.
2. Generates a private deployment plan, independent service keys and synthetic
prototype accounts. No hard-coded passwords or hand-written password hashes are used.
3. Creates a private prototype CA and separate service certificates, installs the
public CA into OS trust, and configures Production HTTPS endpoints.
4. Creates separate PostgreSQL databases and login roles for the selected persistent
services. Roles cannot administer the server/create roles/databases or connect to
the other service's database. Schema ownership supports that service's migrations.
5. Creates independent service identities, application/configuration directories and
service registrations. Runs the selected persistent services' migrations, enables
and starts every selected application, then verifies startup and topology.
Linux application/configuration paths are `/opt/healthapp/NAME` and
`/etc/healthapp/NAME/service.env`. Env files are root-only; systemd passes their values
to the owning process. Certificate private keys are readable only by root and the
respective service identity. Units use `healthapp-NAME` users/groups, not a shared
application identity. Gateway key state remains gateway-owned.
Generated material normally resides at `/var/lib/healthapp-installation/deployment`
with a private directory and private files. `accounts.json` contains generated
`prototype-patient`, `prototype-professional` and `installation-check` passwords.
The professional starts without assignments. Do not put generated material in Git.
Only the CA's public certificate is installed/exported publicly; its signing private
key is not retained. Certificates expire after one year; the prototype CA after two.
## Topology and distributed installation
A topology specifies addresses, ports and native platforms, not credentials. Defaults
are HTTPS ports 5443/5081/5082/5083/5084. Colocated applications need different ports.
For example:
```json
{
"hosts": {
"api-gateway": "192.168.1.20",
"patient-profile": "192.168.1.21",
"observation": "192.168.1.22",
"insights": "192.168.1.23",
"health-overview": "192.168.1.24"
},
"platforms": {
"api-gateway": "linux",
"patient-profile": "linux",
"observation": "linux",
"insights": "macos",
"health-overview": "windows"
}
}
```
Use corresponding profile GET, latest-observation GET and Overview GET probes on
those services. For API Gateway use a bearer-authenticated Overview GET. For a
complete installation that probe must select a prepared patient/period with profile,
latest reading and calculated insight, thereby exercising the documented gateway
and all four application services. Ensure representative records exist through the
normal APIs before verification. Public guidance alone cannot verify dependencies.
Keep probes root-only; their credentials do not belong in the release or repository.
Do not disable certificate verification. Select test/deployment data appropriate to
the environment rather than letting installation create patient information.
Optional `ports` uses the same service keys and integer values. Hostnames/IPs must
resolve/reach the corresponding target. Supply existing administrative SSH access;
Unix hosts need passwordless sudo for the installer, Windows SSH sessions must be
elevated administrators. Host administration credentials are distinct from generated
HealthApp/database credentials and are not invented by the application installer.
Generate one consistent deployment and automatically distribute matching, scoped
material to each host:
```bash
sudo bash verify.sh --services all --probe-dir /root/healthapp-probes
# Explicitly permits independently stopping/starting/restarting every selected unit:
sudo bash verify.sh --services all --probe-dir /root/healthapp-probes --cycle
sudo bash install.sh --services all --prepare-only --topology topology.json \
--deployment /secure/healthapp-deployment --dotnet /path/to/available/dotnet
bash distribute.sh --deployment /secure/healthapp-deployment --ssh-user administrator
```
Verification checks active units, distinct real PIDs and each configured network
probe's HTTP 200 response. `--cycle` checks peer units stay active during each stop,
then starts/restarts that service and probes it again. HTTP response bodies and
credentials are suppressed. Probes fail on connection errors, unexpected status or
an exited process. Verification fails rather than treating unavailable sources as
missing data. Use the same mechanism on every host for a distributed deployment;
the complete-system gateway probe checks the configured remote communication paths.
Use an administrative session able to read the protected deployment material. The
preparation machine needs an available .NET 10 runtime/SDK for the C# utility.
Distribution uses SSH/SCP, installs only selected applications per host, and exports
only their private material plus necessary remote origins. It starts nodes first,
then verifies the complete topology over its real HTTPS endpoints. No credentials
are manually invented, copied into application files or distributed individually.
Services never depend on a shared runtime directory/file across machines.
## Automated evidence and limits
A node started with the orchestrator's `--defer-topology-check` has verified local
process/HTTPS/database readiness but pending cross-node verification. It is not
reported as a verified complete topology until the orchestrator's final check passes.
For incremental installation, reuse the same deployment; independently generated
plans deliberately have different keys and cannot authenticate to each other.
`tests/Deployment.AcceptanceTests` publishes a release, installs into temporary roots,
and launches the installed assemblies as separate OS processes against temporary,
independent PostgreSQL databases. It covers selection, preflight failures, independent
config files/permissions/units, standalone startup for every service, multiple/all
processes, authenticated profile/observation/Overview workflow, per-service graceful
stop/restart, retained data and separate persistence. There are no production service
project references in this test project and no test authentication replacement.
## Windows and macOS adapters
Run with Linux, Bash, .NET 10 SDK, and `TEST_POSTGRES_CONNECTION` referencing a DB
account allowed to create isolated test databases. `HEALTHAPP_DOTNET` may select the
SDK/runtime executable. Ordinary acceptance tests remain available in the solution.
On Windows, from an elevated PowerShell session in the release:
This development execution environment has no running systemd manager. Automated
process tests therefore use direct process launch and SIGINT (the same configured
stop signal); live systemctl registration/boot cycling and production certificates
must be verified with the supplied verifier on a supported target Linux host. The
suite does not claim that localhost testing alone proves a deployment on separate
physical machines. Remote origins and independent configuration are preserved by
installation, and the target-host gateway probe is the distributed-system check.
```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File .\install.ps1 -Services all -HostName 192.168.1.20
```
The adapter installs the .NET runtime automatically, resolves and checksum-verifies
an EDB PostgreSQL installer from Microsoft's package manifest, creates an owned
PostgreSQL service when needed, and generates its administrator secret in protected
files. Existing application/data files are not overwritten. An existing externally
managed PostgreSQL server can instead be used with `-PostgresAdminFile`; the installer
still generates application database roles/passwords automatically.
Applications have separate native Windows Services and virtual service identities,
protected per-service JSON configuration, state and certificate ACLs. Their Production
configuration is installed automatically; certificates are trusted in LocalMachine
Root. HTTPS firewall rules cover only selected application ports. No IIS is required.
Windows uses `-Deployment`, `-Topology`, `-Certificates` for the same shared material.
Default application root is `%ProgramData%\HealthApp`.
On macOS, from a sudo administrator session:
```bash
sudo bash install.sh --services all --host 192.168.1.20
```
The Darwin adapter installs the ASP.NET Core runtime, provisions Homebrew/PostgreSQL
and required Apple build tools where available through softwareupdate, initializes
an installer-owned PostgreSQL cluster with SCRAM passwords, and creates separate
hidden service identities and launchd daemons. It configures system-keychain CA trust,
private environment/launchd files and selected migrations automatically. Default root
is `/Library/Application Support/HealthApp`. macOS package/tool installation requires
an administrator user session, network access, and acceptance of OS/vendor licensing.
The adapters target supported .NET desktop/server operating systems. Portability does
not claim support for every OS/kernel/version/CPU where .NET itself is unavailable.
The live Windows/macOS registration paths need native-host validation; see evidence
limits below. The Linux execution environment cannot run Windows SCM or macOS launchd.
## Verification and management
Installation verifies distinct native processes, configured HTTPS endpoints, selected
databases using their dedicated credentials, actual service keys and outgoing gateway
access. The complete-system check logs in with the generated `installation-check`
account and exercises profile/observation/Overview through all deployed services.
It creates at most one clearly labelled synthetic check profile/observation if absent.
This is prototype test data, not a clinical reading; repeated verification reuses it.
The verifier trusts the generated public CA, validates certificate chains/server names,
and never disables TLS validation. Existing HTTPS trust is retained. All step failures
identify the failed operation/service and retain existing data/material for inspection.
Sensitive SQL/credentials are not printed. Existing applications/configuration cause
refusal rather than silent replacement; this remains a first-install mechanism,
not an upgrade/uninstall/data-removal tool. Deployment is not a cross-service transaction.
Linux may rerun `sudo bash verify.sh --services all --deployment DIRECTORY` from the
bundle. Manage selected units with `systemctl start/stop/restart healthapp-NAME`.
Windows uses `Start-Service`, `Stop-Service`, `Restart-Service`; macOS uses
`launchctl bootstrap`, `bootout`, `kickstart` on `healthapp-NAME` labels. Stopping a
service does not directly stop peer processes; requests needing it may fail.
External trusted certificates can be supplied during preparation with `--certificates`
or `-Certificates`. The directory supplies `NAME.pfx`, `NAME.password` for all five
planned services and `healthapp-ca.crt`. Supplied PFX certificate chains are retained;
private keys/passwords are protected and configured automatically. Prototype browser
clients may import the exported public CA for trust; server-side service trust is
configured automatically by installation.
`--root DIRECTORY` on Linux is explicitly offline staging: it generates the same
settings/material but cannot install host packages or register/start systemd. It is
not reported as a live verified installation. `--postgres-admin-file` allows automated
DB provisioning against an externally managed/test server, not manual application
DB/user preparation. Normal Linux installation administers local PostgreSQL through
its OS postgres identity without inventing a PostgreSQL administrator password.
## Evidence and dependencies
The xUnit deployment suite builds the release, calls the actual provisioner/installer,
creates database roles/databases in an isolated PostgreSQL server and runs all five
installed services in separate Production-mode HTTPS processes. Tests cover generated
key matching/uniqueness, certificate private-key output, private configuration, database
isolation/permissions, migrations, native-format configuration, independent restart,
representative functionality and repeated non-destructive verification. Package command
contracts are tested with controlled command doubles; no host package installation
is performed by the tests. The ordinary application tests remain unchanged.
Linux HTTPS/interservice/database execution is verified here. Live systemd package/
registration behaviour needs a supported Linux host; Windows/macOS service registration
needs those native hosts. Native configuration formats are exercised by the shared
utility tests; shell/PowerShell syntax validation is separate from a native end-to-end
run. The manual `.github/workflows/prototype-native-install.yml` workflow provisions
and verifies fresh Ubuntu, Windows and macOS runners; it is supplied for native
validation and has not been executed remotely in this session. These limits must not be described as verified production deployment on every OS.
The provisioning tool uses standard .NET X.509/password hashing and Npgsql for creating
and checking databases. Its dependency is not a shared service runtime library.
Microsoft.Extensions.Hosting.WindowsServices is added to the five services solely for
native Windows service lifetime integration; Linux/macOS responsibilities are unchanged.
Package/lifetime references reviewed during implementation:
[Ubuntu runtime installation](https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install),
[Debian runtime installation](https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian),
[Windows service hosting](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-10.0),
[EDB unattended installer parameters](https://www.enterprisedb.com/docs/supported-open-source/postgresql/installing/command_line_parameters/).