tools: update inside LXC and use the existing proxy (#22)

Use the operator's HTTPS proxy with a private backend on port 5187. Limit the Proxmox host script to container creation and install a self-updating command inside the LXC. Preserve keys/history during legacy proxy migration and keep root updater code isolated from unprivileged build output.

Closes #21
This commit was merged in pull request #22.
This commit is contained in:
2026-11-15 13:06:04 +01:00
parent c75446008c
commit 43caf1e412
20 changed files with 657 additions and 608 deletions
+131 -208
View File
@@ -1,95 +1,13 @@
# Proxmox LXC install and update
Run [tools/proxmox.sh](../tools/proxmox.sh) **as root on the Proxmox host**, from a trusted local
copy of this checkout. It creates the container itself; do not run it inside an existing LXC.
The default is a dashboard plus a collector/client in one new, unprivileged Debian 13 amd64 CT.
This follows [D14](decisions.md#d14--self-hosted-dashboard-and-workers).
Use the **Proxmox host only to create the container**. Updates run **inside the LXC**.
FinalToken uses your existing HTTPS reverse proxy and installs no Caddy or other proxy.
The private backend listens on **HTTP port 5187**. This follows
[D14](decisions.md#d14--self-hosted-dashboard-and-workers).
Use a checkout containing the web/worker and installer source. A public repository can be
[cloned and updated over HTTPS without a Git login](publication.md#anonymous-git-reads).
Alternatively copy the source to the host, including `tools/proxmox/`, `tools/proxmox.sh`, `tools/source_policy.py`,
`LICENSE`, root build files and the four Core/Fleet/Web/Worker source directories. Git metadata
and build artifacts are not needed. The installer snapshots the selected local source, including
uncommitted files; this local-source installer never pulls, commits or pushes Git changes.
The separate [one-command updater](../tools/proxmox-update.sh) refreshes a clean Git checkout
before invoking the installer.
The snapshot excludes recognized local configuration, key and runtime-data paths independently
of Git ignore rules; those files are not read or transferred with the source.
## Install the server
## Install dashboard and client
From the copied repository root on the Proxmox host:
```bash
bash tools/proxmox.sh install --ctid 201 --storage local-lvm \
--domain usage.example.com --email [email protected] --timezone Europe/Berlin
```
Replace the storage, CT id, domain and email. Omit `--ctid` to ask Proxmox for the next free id.
`--storage` is deliberately required: the installer does not choose where to allocate your disk.
Add `--dry-run` to print the validated plan without calling Proxmox or changing files.
The installer:
1. Downloads the latest available Debian 13 standard amd64 template to `local`, or uses the
filename selected with `--template`. `--template-storage` selects another template storage.
2. Creates an unprivileged CT, with on-boot startup, 2 cores, 4096 MiB RAM, 2048 MiB swap,
a 20 GiB root disk and DHCP on `vmbr0`. It does not enable nesting or privileged mode.
3. Uploads an allowlisted source archive and builds `linux-x64` NativeAOT **inside the CT**, as
the separate `finaltoken-build` OS user. Windows-built executables are never deployed to Linux.
4. Installs the .NET 10 SDK/native compiler prerequisites in the CT, Caddy for HTTPS, and the
official Claude native stable installer and Codex npm package as the `finaltoken` user.
Official CLI downloads run under that user, not root. No provider login is attempted.
5. Generates service keys, account/profile bindings, systemd services and a loopback web backend.
Caddy exposes `https://<domain>`. The new client is automatically registered with this server.
6. Checks local services and the dashboard HTTP response. Keys are not printed by the script.
The host needs Proxmox's `pct`, `pvesh`, `pveam`, `pvesm` and Python 3. Its package repositories
are not changed. The CT needs working DNS and outbound package/download access. Native builds
need time and memory; increase `--memory`, `--cores` or `--disk` for a slower/smaller host.
The first build restores .NET packages. Later updates also run package installation in the CT;
this is not a fully offline or byte-for-byte reproducible supply-chain build.
For static networking:
```bash
bash tools/proxmox.sh install --ctid 201 --storage local-lvm \
--bridge vmbr0 --ip 192.0.2.20/24 --gateway 192.0.2.1 --vlan 10 \
--domain usage.example.com --email [email protected]
```
`--vlan` is optional. Set DNS to point the chosen domain to the CT. Allow incoming TCP 80/443
through your Proxmox/network firewall and, for public ACME certificates, forward the required
ports. The script sets the CT interface's firewall flag; it does not modify cluster/host firewall
rules, DNS, NAT or routing. The public certificate/network path is not proven by the local
health check. Caddy's default ACME certificate issuance needs the domain to be reachable.
For a private LAN hostname, add `--tls internal`. Caddy then uses a private CA; explicitly trust
its root certificate on browsers and remote clients. Do not disable TLS verification.
The root certificate is inside the CT at:
```text
/var/lib/finaltoken-proxy/caddy/pki/authorities/local/root.crt
```
Read the dashboard access key from the Proxmox root console when you need to sign in:
```bash
pct exec 201 -- cat /etc/finaltoken/dashboard-key
```
Open the dashboard and use **Log in / renew** for each provider profile. This is the actual
official CLI login, bound to that CT's `finaltoken` user. The CLI still requires your browser
authorization. The client only observes coding activity in this CT's profiles; it cannot see
coding sessions on a desktop or a different CT unless a client is installed there too.
Claude quota probing remains subject to the [web integration limitations](web-dashboard.md#provider-usage-limitations).
## Client-only or server-only
For a **server-only** container, run this as root on the Proxmox host after these changes are
published to `master` and anonymous HTTPS reads are enabled. The host needs Git in addition to
the Proxmox commands and Python 3. Use a new checkout path and a free CT id; replace the storage,
domain and timezone for your setup:
As root on the Proxmox host, with Git and Python 3 installed:
```bash
git clone --branch master --single-branch https://git.finalfactory.de/FinalFactory/FinalToken.git /opt/finaltoken-src && \
@@ -97,18 +15,95 @@ git clone --branch master --single-branch https://git.finalfactory.de/FinalFacto
--storage local-lvm --domain usage.example.com --timezone Europe/Berlin
```
This installs only the dashboard and HTTPS proxy. No provider login or provider email is required
on the server. Optional `--email` seeds the provider accounts; accounts and remote machine
bindings can also be configured afterwards. Set the domain's DNS and TCP 80/443 access as
described above. Private-LAN deployments can add `--tls internal` and trust the private CA.
Use a free CT id and your storage, hostname and timezone. Omit `--ctid` for the next free id.
The hostname is the public hostname on **your existing proxy**, not a certificate request.
Add `--dry-run` to validate without creating a CT. Anonymous HTTPS clone needs no Git login.
Read the dashboard key with `pct exec 201 -- cat /etc/finaltoken/dashboard-key`.
Keep `/opt/finaltoken-src` as a dedicated deployment checkout for the update command below.
Configure your existing reverse proxy:
For a separate collector LXC, first configure an account/machine binding on the existing server
as described in [the dashboard setup](web-dashboard.md#run-locally). The machine's `osUser` must
be `finaltoken`, with the selected provider ids as its profile ids. Put that machine's matching
transport key in a root-readable host file (mode 0600); it is a FinalToken key, not a provider token.
- Public URL: `https://usage.example.com` (your chosen hostname).
- Backend: `http://<LXC-IP>:5187`.
- Preserve the public `Host` header. Restrict backend network access to your proxy/private network.
- Allow worker metadata POST bodies up to 32 MiB, matching the server's request-size limit.
- TLS/certificates stay on your existing proxy. The LXC needs no inbound 80/443 or certificates.
The server pins its public Host/Origin and uses secure browser cookies. Do not expose this private
HTTP backend directly to the Internet or remove authentication. No forwarded-header trust is enabled.
The proxy must not log authorization headers or request bodies containing login responses.
Read the dashboard key on the CT's root console:
```bash
cat /etc/finaltoken/dashboard-key
```
`--role server` installs no coding CLIs or worker. Optional `--email` seeds provider account
metadata; no provider email/login is needed to install the server. Configure account/machine
bindings and distinct machine keys as in [web setup](web-dashboard.md#run-locally).
## Update inside the container
Open the LXC console as root and run:
```bash
finaltoken-update
```
This fetches public `master` into temporary source, builds NativeAOT as the isolated build user,
and activates the update **inside this container**. It does not call `pct`, contact the Proxmox
host or require the original host checkout. It preserves the CT role, service keys, settings,
CLI profiles and history. Official provider CLIs keep their own update/login lifecycle.
The updater is included in each binary release, so switching/rolling back releases updates it too.
Its root-executed code comes directly from the verified source archive; build-user modifications
to extracted source or build output cannot replace the installed updater.
```bash
finaltoken-update --dry-run
```
Dry-run reads the managed marker and prints the plan without downloading or changing services.
Concurrent updates are refused. A new binary release is built before switching `current`;
only previously running services restart, and a failed local health check restores the old binaries.
Stopped services stay stopped. Package/configuration/history rollback is not implied by binary rollback.
### Existing 1.2.0 containers
The old installer did not install this command and bundled a proxy. Run the following **once as
root inside that LXC** to fetch the corrected updater and perform the update:
```bash
(
set -e
update_script=$(mktemp)
trap 'rm -f -- "$update_script"' EXIT
curl --fail --silent --show-error --location --proto '=https' --tlsv1.2 \
https://git.finalfactory.de/FinalFactory/FinalToken/raw/branch/master/tools/lxc_update.py \
--output "$update_script"
python3 "$update_script"
)
```
This installs Git in the CT if needed, updates the app, changes the old known loopback listener
to `0.0.0.0:5187` and disables **only** `finaltoken-proxy.service`. Point your existing proxy at
HTTP port 5187. Keys, public hostname, profiles, history, certificate files and installed packages
are retained. It does not stop an unrelated `caddy.service` or purge packages/configuration.
The old server environment is backed up as root-only `server.env.pre-external-proxy`. If the
backend health check fails, its listener and prior service states are restored. A custom listener
is retained and migration reports that it needs manual configuration. The application update
may already have succeeded when a later network migration fails; retry after fixing the cause.
Subsequent updates need only `finaltoken-update`. The old host updater refuses deployment and
points to this in-container command.
## Install dashboard and client
Omit `--role server` (or choose `--role both`) to create a CT that also collects its own coding
CLI usage. Add `--email [email protected]`; provider-specific emails override it independently.
The installer installs official CLIs as their own user and never performs provider login.
Open the dashboard and use **Log in / renew** for the selected profile.
It observes only coding activity inside this CT, not desktop activity on another machine.
For a worker-only CT, configure the matching machine/account/key on the existing server first:
```bash
bash tools/proxmox.sh install --ctid 202 --storage local-lvm --role worker \
@@ -116,108 +111,55 @@ bash tools/proxmox.sh install --ctid 202 --storage local-lvm --role worker \
--worker-key-file /root/lxc_202.key --email [email protected]
```
The script creates the client CT, installs its CLIs, configures profiles and starts its service.
The existing server must already authorize that machine id/key; this mode does not edit another
server's configuration. If the existing server uses a private CA, install that CA in the new CT's
system trust store with `update-ca-certificates` before expecting the worker to connect.
The enrollment file holds a FinalToken transport key, not a provider token. The worker's OS user
is `finaltoken`; selected provider names are its profile ids. Workers connect outbound over HTTPS.
Use `finaltoken-update` inside worker CTs too.
`--role server` omits the local client/CLIs and starts with no machine bindings. You can supply
`--email` to seed provider accounts, then configure remote machines in `/etc/finaltoken/server.json`
and add their distinct `FINALTOKEN_MACHINE_<id>` keys in `/etc/finaltoken/server.env`.
Restart the server after editing its configuration. The operator guide documents this static
configuration contract; there is no automatic remote enrollment HTTP API.
## Host and container requirements
Use `--providers codex` or `--providers claude` to install only one provider.
`--claude-email` and `--codex-email` override `--email` independently. Machine ids must begin with
a letter and use letters/digits/underscores, because they also name systemd environment variables.
The host needs `pct`, `pvesh`, `pveam`, `pvesm` and Python 3. Its package repositories are untouched.
Creation uses an unprivileged Debian 13 amd64 standard CT, DHCP on `vmbr0`, on-boot startup,
2 cores, 4096 MiB RAM, 2048 MiB swap and a 20 GiB root disk. No privileged mode/nesting is enabled.
The CT needs DNS/outbound HTTPS and working package repositories. Builds install .NET 10/native
prerequisites and Git in the CT and run under `finaltoken-build`, not root. Increase resources
when needed. This is not an offline or byte-for-byte reproducible dependency build.
## Update or resume a partial installation
For static IPv4, add `--ip 192.0.2.20/24 --gateway 192.0.2.1`; `--bridge`, `--vlan`,
`--template-storage` and `--template` select host-specific resources. No host firewall, DNS or NAT
rules are changed. Your existing proxy must reach the CT on port 5187.
For a clean clone at `/opt/finaltoken-src`, run this **single command as root on the host**
from any working directory. Change `201` to the installed CT id:
```bash
bash /opt/finaltoken-src/tools/proxmox-update.sh 201
```
It fetches the checkout's tracking branch with fast-forward-only/no-autostash rules, verifies that
HEAD matches that upstream, then enters the **newly fetched** installer. Re-running the command
with no new commit still retries deployment, which is useful after a package/build interruption.
The existing managed CT marker preserves the installed role, including server-only installations.
It refuses a detached branch, missing upstream, local-only commits and tracked/staged/untracked
changes; it never resets, stashes, commits or pushes local work. Upstream paths that would overwrite
ignored local files also stop the update. Ignored runtime state is retained
and filtered from source archives. Update failures return a nonzero exit status. Git failures
stop before deployment and do not echo remote URLs that might contain operator credentials.
The updater locks its checkout with `flock` (util-linux); the installer also holds its existing
host-wide deployment lock. Do not edit the dedicated clone during an update.
To validate the current source and deployment arguments without fetching or changing the CT:
```bash
bash /opt/finaltoken-src/tools/proxmox-update.sh 201 --dry-run
```
For a manually copied checkout or a deliberately selected local source snapshot, copy the
desired new source into place and use the original offline-source entry point:
```bash
bash tools/proxmox.sh update --ctid 201
```
Use `--source /absolute/path/to/another/checkout` to select a different local source snapshot.
Update requires a running CT with this installer's marker and matching CT id. It refuses foreign
or stopped containers. It does not overwrite identity settings; install-only identity flags are
rejected on update. Service keys, configuration, CLI profiles and usage history are preserved.
Updates do not reinstall/upgrade the official CLIs; they keep their normal CLI-owned lifecycle.
A new binary release is built before the `current` symlink changes. Only services that were
running are restarted; intentionally stopped services remain stopped. A local health failure
restores the previous binary release and attempts to restart the previously running services.
That is binary rollback, not a history/configuration/OS-package rollback. Old releases are kept;
no automatic pruning or container deletion takes place. A future incompatible data schema needs
an explicit migration/backup plan before deploying it.
Restarting a server/client interrupts pending login attempts; finish or cancel them first.
An interrupted package download or build leaves the CT for inspection. Once the guest marker
exists, the same `update` command resumes an incomplete initial installation without rotating
its enrollment key. If creation failed before the marker was written, inspect the CT and its
network rather than trying to overwrite it with another `install`.
The host installer snapshots the selected local checkout, including uncommitted source, through
the shared allowlist in `tools/proxmox/source_bundle.py`. It excludes recognized local config,
credentials and runtime data independently of Git ignore rules, rejects symlinks and bounds size.
`--source` selects a different local checkout. It never overwrites an existing CT.
## Files and service ownership
| Location | Purpose |
|---|---|
| `/etc/finaltoken/install.json` | Managed CT id, role, source checksum and last successful release |
| `/etc/finaltoken/server.json`, `worker.json` | Operator-editable account/profile configuration |
| `/etc/finaltoken/server.env`, `worker.env` | Root-only FinalToken service keys/environment |
| `/etc/finaltoken/transport-keys.json` | Root-only initial transport-key backup; not provider credentials |
| `/opt/finaltoken/releases/`, `/opt/finaltoken/current` | Root-owned staged/active native binaries |
| `/var/lib/finaltoken-server/` | Server data; owned by `finaltoken-server` |
| `/var/lib/finaltoken-worker/` | CLI profiles, per-provider history and collector state; owned by `finaltoken` |
| `/var/lib/finaltoken-proxy/` | Caddy state/certificates; owned by `finaltoken-proxy` |
| `/var/cache/finaltoken-build/` | Separate build user home/cache; per-build source directories are removed |
| `/etc/finaltoken/install.json` | Managed identity, role, source checksum and successful release |
| `/etc/finaltoken/server.json`, `worker.json` | Operator account/profile configuration |
| `/etc/finaltoken/server.env`, `worker.env` | Root-only service environment and transport keys |
| `/opt/finaltoken/releases/`, `/opt/finaltoken/current` | Root-owned native releases and updater |
| `/usr/local/sbin/finaltoken-update` | Link to the active release's in-container updater |
| `/var/lib/finaltoken-server/`, `/var/lib/finaltoken-worker/` | Metadata, history and CLI-owned profiles |
| `/var/cache/finaltoken-build/` | Separate build user's cache; temporary source is removed |
Generated units use separate non-root users, restrictive file permissions, no-new-privileges and
process-group shutdown. They avoid mount-namespace sandbox settings that require extra LXC
features. Unit files are created once and preserved on update; put site overrides in systemd
drop-ins. Default package `caddy.service` is disabled in favor of `finaltoken-proxy.service`.
No CT or old release is automatically deleted. A future incompatible schema needs its own
migration/backup plan. Update/restart interrupts pending CLI login attempts.
```bash
pct exec 201 -- systemctl status finaltoken-server finaltoken-worker finaltoken-proxy
pct exec 201 -- journalctl -u finaltoken-worker -u finaltoken-server --since today
systemctl status finaltoken-server finaltoken-worker
journalctl -u finaltoken-server -u finaltoken-worker --since today
```
Application stdout/stderr are discarded by these units to prevent CLI/login material entering
the journal. The journal still shows service exit/restart metadata. Inspect configuration and
CLI installation under the intended user when diagnosing a failed service. Do not dump provider
credential files into logs or support reports. For coding inside the worker CT, use
`pct enter 201`, then `su - finaltoken`; its official CLIs are in `~/.local/bin`.
Units use non-root users, restrictive permissions and process-group shutdown. Application output
is discarded to keep CLI/login material out of the journal; service lifecycle events remain.
Never dump provider credential files into support reports. For coding in a worker CT use
`su - finaltoken`; its installed CLIs are in `~/.local/bin`.
## Verification and limits
Run from the repository root:
```text
python -B tools/proxmox/test_installer.py
python -B tools/proxmox/test_update.py
@@ -226,28 +168,9 @@ bash -n tools/proxmox-update.sh
python -B tools/docs/check_docs.py
```
Installer tests mock Proxmox, package installation, native publishing and systemd. They cover
argument validation, CT refusal, command order, environment isolation, archive safety, preservation
of configuration/keys, partial setup, stopped services and activation rollback. They do not prove
a real Proxmox create/update, Linux build, certificate issuance or provider login. No Proxmox
host/container was changed while developing this script.
One installer regression uses real Node.js/npm with an offline synthetic package to check the
configured Codex launcher and repeat installation. It skips explicitly when Node.js/npm are
unavailable. On Windows its fixture adapts npm's global-prefix layout to the guest's Linux `bin`
path; that checks npm install mode and actual files without claiming Linux execution.
Updater tests use real local Git repositories and Bash with a synthetic installer. They verify
two-version fast-forward deployment, no-change retry, dirty/diverged/ahead/detached refusal,
fetch failure, dry-run, exit status, ignored-state retention and ignored-file collisions. Advisory lock command results
are substituted so the checks also run on Windows; real Linux locking is not exercised here.
References: [Proxmox CLI source](https://github.com/proxmox/pve-container/blob/master/src/PVE/CLI/pct.pm),
[.NET on Debian](https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian),
[NativeAOT prerequisites](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/),
[Caddy TLS](https://caddyserver.com/docs/caddyfile/directives/tls),
[Claude installation](https://code.claude.com/docs/en/setup),
[Codex installation](https://github.com/openai/codex/blob/main/README.md).
Source refresh uses [Git fetch](https://git-scm.com/docs/git-fetch),
[fast-forward merge](https://git-scm.com/docs/git-merge) and
[flock](https://man7.org/linux/man-pages/man1/flock.1.html).
Tests substitute Proxmox, systemd, native publishing, package operations and Linux locking.
They cover source safety, service/config/key preservation, failed activation and legacy proxy
migration rollback. Updater tests use real local Git clones with a synthetic guest provisioner.
The npm regression uses an offline synthetic package and real npm; Windows adapts its global
prefix boundary to the expected Linux launcher directory. It explicitly skips without Node/npm.
No real Linux/LXC update, NativeAOT publish, advisory locking or provider login is claimed by these tests.