Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,234 @@
|
||||
# Template Store Supply-Chain Signing
|
||||
|
||||
The template store syncs hourly from `antonndev/ADTemplates` (with jsDelivr as
|
||||
a fallback co-anchor) and its templates compile directly into container launch
|
||||
configuration: installer scripts run in a networked container with a host bind
|
||||
mount, plus the runtime image and managed startup script every server start
|
||||
executes. Whoever controls that repo — or compromises it — controls code
|
||||
execution on every panel that installs a store template.
|
||||
|
||||
TLS to `raw.githubusercontent.com` / `cdn.jsdelivr.net` only authenticates the
|
||||
transport, not the publisher. This document describes the trust anchor added
|
||||
on top: a pinned Ed25519 vendor key that signs the exact upstream content set.
|
||||
|
||||
## Threat model and what each layer covers
|
||||
|
||||
| Attack | Control |
|
||||
|---|---|
|
||||
| Repo account / maintainer compromise pushing a malicious template | Vendor signature over the content set fails; in `enforce` mode the sync refuses to promote content, keeping the last verified cache |
|
||||
| Compromise of the CDN fallback returning different bytes | Same signature gate; additionally every fetched file is cross-checked against the hash declared by the listing — git blob SHA-1 (GitHub tree API) or base64 SHA-256 (jsDelivr flat listing) — via `verifyListedContentHash` |
|
||||
| Listing/hash mismatch (truncated, stale or cache-poisoned raw fetch) | The listed-hash cross-check fails for that file and the sync fails closed — the previous cache is kept; a declared hash in neither recognizable format is accepted only with a loud sync warning |
|
||||
| Template planted directly into the panel's `Templates/` cache dir, or a torn sync leaving an orphan file | Read path drops files not tracked by the manifest, and tracked files whose bytes no longer match the manifest sha256 |
|
||||
| Install request smuggling template fields past the review dialog | Install takes a reference (`category + fileName + entryIndex + sha256`); the panel resolves content from its own cache and pins it to the reviewed hash — unchanged, and now backed by manifest hashes |
|
||||
| Arbitrarily-registered images (`attacker.io/img`) in store/manual templates | Registry allowlist at panel ingestion (400) **and** mirrored at every node sink (create 400, start, reinstall pull, installer preflight) |
|
||||
| Silent drive-by store updates changing content between reviews | Per-file sha256 in the manifest; optional auto-update review gate; the store UI shows the last update diff |
|
||||
|
||||
Residual risk: the private signing key itself. It lives in the vendor's CI
|
||||
secret; key rotation is a documented, operator-driven procedure (below). Local
|
||||
override templates (`github/` dir, opt-in via
|
||||
`ADPANEL_TEMPLATE_STORE_LOCAL_OVERRIDES`) are intentionally outside the
|
||||
signature — they are local, flagged `untrusted`, and never shadow upstream.
|
||||
|
||||
## How signing works
|
||||
|
||||
1. The vendor computes, for every `category/file.json` in the repo, the
|
||||
SHA-256 of the **raw committed bytes** (no normalization — the panel
|
||||
verifies exactly the bytes it fetches). The per-file digests are folded
|
||||
into a canonical digest bound to the repo name
|
||||
(`canonicalStoreDigestInput` in `utils/template-store-trust.js`).
|
||||
2. The vendor signs a canonical payload binding `repo`, the content `digest`,
|
||||
and the snapshot's `generatedAt` timestamp with an Ed25519 key and commits
|
||||
`store-signature.json` at the repo root:
|
||||
`{ version: 2, repo, digest, generatedAt, publicKeyFingerprint, signature }`.
|
||||
Binding `generatedAt` into the signature (v2) is what makes the panel's
|
||||
rollback/replay refusal cryptographic: old signed snapshots cannot be
|
||||
re-dated and passed off as fresh by whoever controls the transport.
|
||||
3. The panel (when a public key is pinned) fetches the signature file through
|
||||
the same raw path as templates, recomputes the digest over what it actually
|
||||
fetched, and verifies the Ed25519 signature **before any byte reaches the
|
||||
cache**. The sync is two-phase: fetch+verify in memory, then promote.
|
||||
|
||||
Panel-side files:
|
||||
- `utils/template-store-trust.js` — primitives (digest, verification,
|
||||
allowlist, trust-config resolution), unit-tested in
|
||||
`utils/template-store-trust.test.js`.
|
||||
- `index.js` — two-phase sync, signature gate, manifest sha256, read-path
|
||||
integrity gate, ingestion allowlist.
|
||||
- `main.go` — node-side mirrors: `validateTemplateImageRef` at the create /
|
||||
start / reinstall / installer sinks; installer network pin.
|
||||
- `scripts/sign-template-store.js` — vendor tooling (`keygen`, `sign`,
|
||||
`verify`).
|
||||
|
||||
## Vendor: signing a release
|
||||
|
||||
The signing keypair was generated once with `node scripts/sign-template-store.js
|
||||
keygen`; in CI it exists only as the ADTemplates repo's Actions secret
|
||||
`TEMPLATE_STORE_SIGNING_KEY` (the offline master copy lives in the vendor's
|
||||
own key custody, outside any repo), and the public key is pinned inside the
|
||||
panel distribution itself (`BUILTIN_VENDOR_PUBLIC_KEY` in
|
||||
`utils/template-store-trust.js`). That makes the panel repo the trust anchor —
|
||||
the same anchor as the panel code — so stock panels verify store content with
|
||||
zero operator configuration.
|
||||
|
||||
```bash
|
||||
# one-time: generate the keypair
|
||||
node scripts/sign-template-store.js keygen
|
||||
# -> private key goes into the ADTemplates CI secret TEMPLATE_STORE_SIGNING_KEY
|
||||
# -> public key is pinned in the panel (BUILTIN_VENDOR_PUBLIC_KEY) and published
|
||||
# in release notes
|
||||
```
|
||||
|
||||
Signing runs automatically: `.github/workflows/sign-store.yml` in the
|
||||
ADTemplates repo re-signs on every push to `main` and commits the fresh
|
||||
`store-signature.json`. The repo carries a vendored copy of the signing tool
|
||||
(`scripts/sign-template-store.js` + `scripts/template-store-trust.js` —
|
||||
identical logic to the panel's, vendored with a require-path shim) so CI never
|
||||
fetches the tool at runtime, and a CI step re-verifies the signature against
|
||||
the embedded public key before pushing it. Protect the pipeline: branch
|
||||
protection on `main`, the Actions environment `signing` restricted to `main`
|
||||
(optionally with required reviewers, so a stolen maintainer token cannot sign
|
||||
without an interactive approval).
|
||||
|
||||
Requirements that keep signatures verifiable:
|
||||
|
||||
- `.gitattributes` with `* -text`: hashes cover the committed bytes, so the
|
||||
repo must not rewrite line endings — otherwise a CRLF checkout produces a
|
||||
different digest than what raw serving returns.
|
||||
- The signing workflow triggers only on `push` to `main` (never
|
||||
`pull_request_target` — fork PRs must never see the secret).
|
||||
|
||||
Notes:
|
||||
- `verify` re-checks a checkout against `TEMPLATE_STORE_SIGNING_PUBKEY` and is
|
||||
suitable as a CI post-step (the signing workflow does exactly that).
|
||||
|
||||
## Operator: verification on a panel
|
||||
|
||||
Stock panels ship with the vendor's public key pinned in the distribution
|
||||
(`BUILTIN_VENDOR_PUBLIC_KEY` in `utils/template-store-trust.js`) and mode
|
||||
`enforce`: out of the box, every panel verifies store content against the
|
||||
vendor signature and needs no configuration. The store UI states plainly when
|
||||
a sync is refused and why.
|
||||
|
||||
Override the anchor only for key rotation or a self-signed store fork, via env
|
||||
or `data/template-store-trust.json` (env wins):
|
||||
|
||||
```json
|
||||
{
|
||||
"publicKey": "<base64 raw Ed25519 public key>",
|
||||
"mode": "enforce",
|
||||
"autoUpdate": true,
|
||||
"pinnedRef": ""
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Env | Meaning |
|
||||
|---|---|---|
|
||||
| `publicKey` | `ADPANEL_TEMPLATE_STORE_SIGNING_PUBKEY` | Base64 raw 32-byte Ed25519 key (or base64 SPKI DER). Defaults to the built-in vendor key; an explicit pin replaces it (self-hosted fork, rotation). |
|
||||
| `mode` | `ADPANEL_TEMPLATE_STORE_SIGNATURE_MODE` | `enforce` (the default): unverified content is never promoted — the previous verified cache is kept and syncs fail loudly. `warn` is an explicit operator opt-in and a security downgrade: content is served unauthenticated but flagged in the manifest, API and store UI. |
|
||||
| `autoUpdate` | `ADPANEL_TEMPLATE_STORE_AUTO_UPDATE` | `false` stops scheduled/stale syncs on an existing cache: the store stays pinned to the reviewed snapshot until an admin runs a forced sync (step-up protected). First population always syncs. |
|
||||
| `pinnedRef` | `ADPANEL_TEMPLATE_STORE_PINNED_REF` | Pin the store to a tag/commit instead of a moving branch head. |
|
||||
|
||||
`autoUpdate`/`pinnedRef` default sensibly without a trust file (autoUpdate +
|
||||
branch head). `mode` defaults to `enforce` with or without a key; the
|
||||
permissive `warn` mode must be spelled out, never fallen into.
|
||||
|
||||
The signature file names its key fingerprint; a signature produced by any
|
||||
other key is refused before crypto even runs. Verified snapshots are recorded
|
||||
in `data/template-store-trust-state.json`; a signed snapshot **older** than
|
||||
the last accepted one is surfaced as a possible replay/rollback.
|
||||
|
||||
## Image registry allowlist
|
||||
|
||||
Template images (installer and runtime) are execution content. Both ingestion
|
||||
paths (panel) and every execution sink (node agent) enforce the registry
|
||||
allowlist below; templates referencing other registries answer 400 on
|
||||
create/update/store-install, and the node refuses to pull/run/install them
|
||||
even if stored earlier.
|
||||
|
||||
Default registries: `docker.io`, `ghcr.io`, `gcr.io`, `quay.io`,
|
||||
`registry.k8s.io`, `public.ecr.aws`.
|
||||
|
||||
- Panel: `ADPANEL_TEMPLATE_ALLOWED_REGISTRIES` (comma-separated; replaces the
|
||||
default when set).
|
||||
- Node: `ADPANEL_ALLOWED_TEMPLATE_IMAGE_REGISTRIES` (same semantics; keep both
|
||||
consistent).
|
||||
- Node installer network: `ADPANEL_TEMPLATE_INSTALL_NETWORK` optionally pins
|
||||
the installer container to a specific (e.g. egress-filtered) docker network
|
||||
instead of the default bridge.
|
||||
|
||||
Stored legacy templates referencing a now-disallowed registry keep serving
|
||||
existing servers but log a panel-side warning and fail at the node sink; edit
|
||||
and re-save the template to migrate it.
|
||||
|
||||
## Reinstalling custom templates
|
||||
|
||||
**Reinstall Server** rebuilds from the server's saved configuration, including
|
||||
per-server runtime selections that override the original template. After
|
||||
correcting a template, an administrator can select the current template in the
|
||||
server's template picker and choose **Reapply Latest Template** to deploy the
|
||||
new definition. Both actions replace the server directory, so verify a backup
|
||||
first. Template mounts must use a server-directory placeholder such as
|
||||
`{SERVER_DIR}:/data` and have distinct container destinations. Existing containers
|
||||
with Docker-managed volumes (including anonymous image volumes) are refused
|
||||
before teardown. Migrate persistent data into server-directory binds first.
|
||||
Replacement images must cover each declared volume with a server bind or a
|
||||
bounded tmpfs. Files stored only in a container's writable layer are not backed up.
|
||||
|
||||
- Reinstall runs template installers with a read-only container root and
|
||||
bounded scratch space. The image must provide `/bin/sh` and `tar` and must
|
||||
not declare extra writable volumes. Installer output must contain regular
|
||||
files and directories, not links or special files. The default scratch is
|
||||
a Docker tmpfs with a 1,024 MiB maximum, reduced by the server and disk
|
||||
storage budgets. The container memory limit still applies.
|
||||
- For larger installers, set `ADPANEL_REINSTALL_INSTALLER_SCRATCH` on the node
|
||||
to an absolute path on a separate, capacity-limited filesystem. It must be
|
||||
empty apart from `lost+found`, mounted with `nodev,nosuid`, and writable by
|
||||
`adaemon`. The node refuses to use a directory on a server, backup, Docker,
|
||||
or root filesystem. With systemd, add the mount to `ReadWritePaths` if it is
|
||||
outside the service's existing writable paths. Only one installer at a time
|
||||
can use this filesystem.
|
||||
- `ADPANEL_REINSTALL_INSTALLER_MAX_MB` sets the maximum staged output, which
|
||||
defaults to 131,072 MiB with dedicated scratch. A template whose declared
|
||||
minimum cannot fit is refused before installation. The node rechecks the
|
||||
copied output against its storage budget before replacing server files.
|
||||
- When a custom runtime needs initial files from its image, the node stages
|
||||
them as regular files and directories under the same server and disk budgets.
|
||||
The daemon launches the image ID it inspected in preflight, not a mutable tag.
|
||||
|
||||
Upgrade the node daemon before the panel. The panel refuses destructive
|
||||
rebuilds if the node does not support durable reinstall results. The panel
|
||||
creates `server_reinstall_dispatch` during schema initialization; deployments
|
||||
that manage schema changes separately must apply the updated schema first.
|
||||
Keep panel and node clocks synchronized for the request admission deadline.
|
||||
|
||||
After an unconfirmed result, the panel keeps both port allocations reserved
|
||||
while it checks the daemon's operation record. Once Docker is reachable, the
|
||||
daemon can confirm a verified replacement from the same attempt after observing
|
||||
a stable Docker run. If startup fails or was interrupted before it could be
|
||||
verified, the daemon can stop and remove that attempt's container by ID and
|
||||
restore the previous files and configuration. Restoring files leaves the server
|
||||
stopped. The startup observation does not replace an application health check.
|
||||
If neither outcome can be verified, check the daemon logs for the retained
|
||||
rollback directory and resolve the recovery before retrying. Do not clear the
|
||||
reservation or discard the retained files based only on a lost HTTP reply.
|
||||
|
||||
## Key rotation
|
||||
|
||||
1. Vendor: `keygen` a new pair; embed the new public key in the panel
|
||||
(`BUILTIN_VENDOR_PUBLIC_KEY`) and ship that panel release **before** signing
|
||||
anything with the new private key. During the overlap, panels on the old
|
||||
release keep serving their last verified cache — degraded freshness, never
|
||||
broken integrity.
|
||||
2. Vendor: update the `TEMPLATE_STORE_SIGNING_KEY` secret and start signing
|
||||
releases with the new private key.
|
||||
3. Operators who pinned an explicit key (self-hosted forks) update `publicKey`
|
||||
in `data/template-store-trust.json` (or env) and restart the panel; stock
|
||||
panels pick the new anchor up with the panel update. The next sync verifies
|
||||
against the new key; the first post-rotation signed snapshot replaces the
|
||||
trust state.
|
||||
4. Because `generatedAt` rollback detection is per accepted-key, rotation
|
||||
resets the replay baseline — acceptable, and rotation should be announced.
|
||||
|
||||
In `enforce` mode a missed step (panel not yet updated while the vendor
|
||||
already signs with the new key) fails closed — content is served from the last
|
||||
verified cache until the operator completes the rotation.
|
||||
Reference in new issue
Block a user