SepoDesk update packages
The authoritative description of what a package is, who builds it, and who installs it. Phases 1 to 3 of the automation plan are implemented; phases 4 to 8 are not, and the last section says what each still needs.
The one rule
There is one updater. SystemUpdater::updateByManifest() receives packages,
backs up, applies, rolls back, restores and flushes caches. Nothing else in the
system installs files. GithubSync builds packages; SystemUpdateManager registers
and serves them; SystemUpdater installs them.
The manifest format
The plan's section 11 was wrong and has been corrected here. It proposed:
"operations": { "write": [], "delete": [] }
SystemUpdater::updateByManifest() does not read that. It reads:
$manifest['files'] map: ZIP-internal path => destination path $manifest['delete'] list: destination paths
Section 10 says not to invent a second manifest format, and section 11 then did.
The updater is the authority, so the builder emits files and delete. The
release metadata rides alongside in the same JSON and the updater ignores it.
A package looks like this:
package.zip ├── update-manifest.json └── files/ └── SepoEngine/App/Kernel.php
And the manifest like this:
{
"files": {
"files/SepoEngine/App/Kernel.php": "SepoEngine/App/Kernel.php",
"files/SepoEngine/App/Brand.php": "SepoEngine/App/Brand.php"
},
"delete": [
"SepoEngine/App/Legacy.php"
],
"package": "sepodesk",
"version": "2.4.0",
"previous_version": "2.3.0",
"release_type": "update",
"title": "Autumn release",
"description": "What changed and what to expect.",
"author": "SepoDesk",
"created_at": "2026-09-04T16:00:00+00:00",
"built_by": "uid-42",
"source": {
"repo": "Happy984/sepodesk",
"branch": "main",
"connection": "happy984-sepodesk-main",
"from": "9a1c...",
"to": "c0de...",
"basis": "compare"
},
"summary": { "added": 1, "modified": 2, "deleted": 1, "skipped": 3, "bytes": 8402 },
"skipped": [ { "path": ".env", "reason": "This file is on the protected list." } ]
}
Only files and delete change behaviour. Everything else is displayed.
Destinations are relative to the project root, because that is what
SystemUpdater::safeResolve() resolves against. A GithubSync connection mapped
to a sub-folder has its paths prefixed accordingly, so the documentation
connection targeting Content/ produces Content/Pages/intro.md. A connection
pointing outside the project cannot build a package at all and says so.
What can never enter a package
The builder applies the connection's own rules before anything is added:
- Protected paths —
.env,wp-config.php,.htpasswd,.git/— are always excluded, whatever the repository contains. - Files whose extension is outside
GITHUB_SYNC_ALLOW_EXTare excluded. - Files outside the connection's mapped folder are excluded.
Everything excluded is listed in the manifest under skipped and shown in the
console before you publish, so an omission is visible rather than silent.
After the ZIP is written it is re-opened and validated the way the updater will
read it: manifest parses, every files entry actually exists in the archive
(case-sensitively — a Linux host rejects what Windows matched), no absolute
destinations, no .. segments. A package that fails is deleted, not registered.
Phase 1 — the package registry
SystemUpdateManagerModel and SystemUpdateManagerController are rewritten.
What changed and why:
Registration is now one path. registerUpdate() called
move_uploaded_file(), which only succeeds for a file that arrived over HTTP —
a package generated on the server could never be registered through it. There is
now registerPackage() for any file on disk and registerUpload() wrapping it
for the browser. Same validation, same storage, same row.
registerUpdate() remains as a shim so existing callers keep working.
Activation is transactional. Every insert set sp_is_active = 1 and nothing
was ever deactivated, so the table accumulated active rows and
getLatestActiveUpdate() only picked the right one because of its ORDER BY.
Now: deactivate all, insert active, commit — or roll back. There is never a
moment with no active package, which would report "no update available" to every
installation.
Re-registering the same bytes is not an error. Same SHA-256 means the same package; it is reactivated rather than duplicated.
The stored file is re-hashed. A copy that truncated would otherwise be published under a hash no client could ever match.
getUpdateFileByHash() no longer trusts the URL. It validates against
^[a-f0-9]{64}$ and checks containment on the resolved path — the pattern
makes traversal impossible, the containment check keeps that true if the pattern
is ever loosened.
Statements are checked. PDO runs in ERRMODE_SILENT here, so query()
returns false and false->fetch() is a fatal Error rather than something a
catch can see. The same bug class you already fixed in SystemUpdateController.
The connection opens on first use. The old constructor spent a connection
slot even on downloadUpdate(), which needs none.
Downloads stream. readfile() after Content-Length pulled the whole
package through memory; it is fpassthru now, with buffers dropped first.
Extra metadata without a migration
The table has no column for title, previous version or source commit, so that
metadata is written to release.json beside the package
(SystemUpdates/by-hash/<hash>/release.json). It travels with the file and
needs no schema change. If you would rather have columns, these are the ones
worth adding, and readMetadata() can then be dropped:
sp_title, sp_previous_version, sp_release_type, sp_package_size, sp_source_commit, sp_activated_at
Phase 3 — the builder
SepoEngine/App/Modules/GithubSync/PackageBuilder.php.
preview() works out what a release would contain without building anything:
the commit range, every file operation, everything excluded and why, the byte
total, and a suggested next version. build() produces the ZIP, validates it,
and returns it. Registration is a separate step, so a package can be inspected
before it is published.
The starting point comes from releases.json in the connection's storage
folder — what this connection last published and at which commit. No previous
release means the first package is the entire mapped tree, and the console
labels it as such rather than quietly shipping everything.
A rebased or force-pushed branch makes the old commit unreachable; GitHub's compare fails and the builder says so instead of producing an empty package.
Limits: 60 MB uncompressed, 3000 operations. Both are refusals with a reason, not silent truncation.
The database is only touched when a release is actually published, so browsing, diffing and previewing still cost no connection.
Using it
A Release tab in the console shows the range since your last release, the counts, the file list, everything left out, and the form. Version is prefilled with the next patch number. Description is required — it is what someone reads before deciding to install.
Publishing builds the package, validates it, registers it as the active release
and records it in the ledger. The previous release stays in the registry, so
activatePackage() can put it back.
Who may download a release
The distribution endpoints stay in MiddlewareHelper::PUBLIC_ROUTES — a remote
installation has no session on your server, and isPublic() is tested before
the role prefix, so '/system/updates' => 'admin' never applied to them anyway.
Authentication moved into the request instead.
Every installation's owner has an account here, and that account has a key pair
in tsp_sys_api_keys. That pair is the credential.
A public key on its own is not enough. It is called public for a reason: it rides in a header on every ordinary API call that customer makes, so anything that ever logged one of those requests would hold a working credential for your entire source archive. So the installation signs instead, and the secret never crosses the wire:
api-public-key: <sp_api_public_key> x-sepo-timestamp: <unix seconds> x-sepo-signature: hmac_sha256(secret, "<public>\n<ts>\n<action>[\n<resource>]")
The server looks the secret up by public key and recomputes with hash_equals.
The action is a fixed string, not the URL. Signing the URL looks tidier and
then breaks the first time an install sits under a sub-path, behind a proxy that
rewrites, or on a host that differs about trailing slashes. check and
download cannot drift. For a download the package hash is bound in too, so a
captured credential cannot be replayed to fetch a different package.
The timestamp window is 300 seconds by default (UPDATE_AUTH_WINDOW). Out-of-
window requests are almost always a wrong clock, and the log says so rather than
just "denied".
A key is refused when it is unknown, not active, or past sp_api_expires_at —
a column setExpiration() has always written and nothing has ever read, so an
expired key used to authenticate exactly like a live one.
Rolling it out
Installations already in the field cannot sign: the code that signs is inside
the update they have not received yet. UPDATE_AUTH_MODE handles that.
signed— the default. Signature required.keypair— also accepts public + secret in headers, so an install that has not been updated can still fetch the update that teaches it to sign. Each such request is logged as "has not been updated to sign yet", so you can watch that number reach zero before switching back.open— no authentication. Logs a warning on every single hit, deliberately, because this is the setting that serves your source to anyone who asks and it should not be the one that quietly stays on.
Signed requests are accepted in all three modes, so nothing has to be
coordinated: turn on keypair, publish the release, watch the log, switch to
signed.
What the caller is told
"Not authorised to download updates." — nothing more. The reason goes to the log with the key prefix, IP and user agent. A scanner should not be able to learn which part of its guess was wrong.
Every served package is logged with the client uid, so "which customers are on which release" is answerable from the log today, and from a table later.
Files
SepoEngine/App/Services/UpdateAuthenticator.php vendor side, the gate SepoEngine/App/Services/UpdateClientAuth.php client side, the signer SepoEngine/App/Models/ApiKeyModel.php + getAuthRecord, isExpired
CLIENT-WIRING.md has the three edits needed in SystemUpdateController.
One bug worth knowing about while you are in this code:
ApiKeyModel::validateKey() returns an array, so if ($model->validateKey($k))
is always true — a non-empty array is truthy. It has to be
['valid']. Worth grepping for.
Still open
Phase 4, version manager. Needs the authoritative installed-version
constant, which I do not have. PackageBuilder::compareVersions() is written
and handles 2.10.0 > 2.9.0 correctly; it needs somewhere to read the current
version from.
Phase 5, update checker. The endpoint already returns everything needed
(version, plus title, previous_version, size, summary). A checker only
has to compare and cache; it must not download the ZIP to decide.
Phase 6, notification. TURN_ON_UPDATE_NOTIFICATION. Read it through the
raw-env helper, not SpEnvLoader::bool() — env() rewrites 1 to true
before coercion.
Phases 7 and 8 are already implemented in SystemUpdateController and
SystemUpdater; they need connecting to the UI, not rebuilding.
Verified
- A built package installed correctly through a line-for-line transcription of
SystemUpdater::updateByManifest()'s manifest read, pre-flight and apply loop: three files written, one deleted, permissions preserved. .env,wp-config.phpand disallowed extensions excluded from a package whose repository contained them.- Renames produce a delete of the old path and a write of the new one.
- A connection mapped to
Content/producedContent/-prefixed destinations; a connection outside the project was refused. - Version comparison: 2.10.0 > 2.9.0.
- The console Release view: preview, prefilled version, the description guard, the confirmation, and the published notice.
Not verified against a live server: the DI binding name for PDO in the release
route (it tries 'PDO' then PDO::class and reports a clear error if neither
resolves), and SystemUpdateManagerModel's SQL against your real table.