diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c8eb2..45224c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ versions follow [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [2.3.3] - 2026-11-19 + +### Fixed + +- **A server setting the apps can't start with is refused up front.** With `TRUST_PROXY=TRUE` in + a server's configuration, an Events install built for minutes and then failed: the backend + crashed at startup (`invalid IP address: TRUE`) and the install was removed. Saving a server's + configuration now refuses such a value, saying what to use instead (`loopback` behind frp), and + installs and updates are refused (`CONFIG_INVALID`) while a configuration saved before this + still has one. The rules are `agent.checkEnvValue` in `@crosscode/contracts` 1.6.0 (now + vendored); the crosscode script checks again on the server. + ## [2.3.2] - 2026-11-19 ### Fixed diff --git a/backend/package-lock.json b/backend/package-lock.json index e04c97c..a60a0d1 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,16 +1,16 @@ { "name": "events-hub-backend", - "version": "2.3.2", + "version": "2.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "events-hub-backend", - "version": "2.3.2", + "version": "2.3.3", "hasInstallScript": true, "dependencies": { "@anthropic-ai/sdk": "^1.3.0", - "@crosscode/contracts": "file:vendor/crosscode-contracts-1.5.0.tgz", + "@crosscode/contracts": "file:vendor/crosscode-contracts-1.6.0.tgz", "@prisma/adapter-pg": "^7.10.1", "@prisma/client": "^7.10.1", "bcryptjs": "^2.4.3", @@ -609,9 +609,9 @@ "license": "MIT" }, "node_modules/@crosscode/contracts": { - "version": "1.5.0", - "resolved": "file:vendor/crosscode-contracts-1.5.0.tgz", - "integrity": "sha512-J3t9tUjPBfyS2UL2wKi49Bc7Ci/Qfy3V6HRj4Z25mNDs4bagi3LqsDwlsxT+Tq9Gxo/GJrIkn73KpDdAGZ2aSw==", + "version": "1.6.0", + "resolved": "file:vendor/crosscode-contracts-1.6.0.tgz", + "integrity": "sha512-uAgoeo0eVUrQtklucztwXxRaawf33ITGqvob7i1C4BcgEkm4hIKbOHWp1qZxW3xT0vkZPfjoeLKtCHp8j1/rSg==", "license": "UNLICENSED", "dependencies": { "zod": "^4.6.7" diff --git a/backend/package.json b/backend/package.json index 91dda11..675c161 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "events-hub-backend", - "version": "2.3.2", + "version": "2.3.3", "private": true, "description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats", "main": "src/index.js", @@ -20,7 +20,7 @@ }, "dependencies": { "@anthropic-ai/sdk": "^1.3.0", - "@crosscode/contracts": "file:vendor/crosscode-contracts-1.5.0.tgz", + "@crosscode/contracts": "file:vendor/crosscode-contracts-1.6.0.tgz", "@prisma/adapter-pg": "^7.10.1", "@prisma/client": "^7.10.1", "bcryptjs": "^2.4.3", diff --git a/backend/src/routes/servers.js b/backend/src/routes/servers.js index 6529047..6c200a6 100644 --- a/backend/src/routes/servers.js +++ b/backend/src/routes/servers.js @@ -4,6 +4,7 @@ */ const express = require('express'); +const { agent } = require('@crosscode/contracts'); const prisma = require('../config/db'); const { protect } = require('../middleware/auth'); const { audit } = require('../utils/audit'); @@ -119,6 +120,9 @@ router.put('/servers/:id/config', wrap(async (req, res) => { const current = servers.serverConfig(s); const next = {}; for (const [k, v] of Object.entries(req.body?.values || {})) next[k] = v === MASK ? current[k] : v; + // A value the apps can't start with (TRUST_PROXY=TRUE crashed Events after a whole build). + const invalid = agent.invalidValues(next); + if (Object.keys(invalid).length) throw Object.assign(bad(Object.values(invalid).join(' ')), { code: 'CONFIG_INVALID' }); const saved = await servers.setServerConfig(s.id, next); await audit(req, 'server_config_changed', s.id, { keys: Object.keys(saved) }); res.json({ config: masked(saved) }); diff --git a/backend/src/utils/envTemplates.js b/backend/src/utils/envTemplates.js index 5cf64c3..0e3e159 100644 --- a/backend/src/utils/envTemplates.js +++ b/backend/src/utils/envTemplates.js @@ -40,4 +40,13 @@ async function missingFor(product, version, serverValues, defaults) { return { server: agent.missingRequired(template, 'server', serverValues), defaults: agent.missingRequired(template, 'defaults', defaults) }; } -module.exports = { envTemplate, missingFor, _cache: cache, getSettings }; +/** + * Values the apps can't start with, as sentences (e.g. TRUST_PROXY=TRUE, which crashed the Events + * backend after an install's build). Saving a configuration checks them too, but configurations + * saved before Hub 2.3.3 weren't checked. + */ +function invalidFor(serverValues, defaults) { + return [...Object.values(agent.invalidValues(serverValues || {})), ...Object.values(agent.invalidValues(defaults || {}))]; +} + +module.exports = { envTemplate, missingFor, invalidFor, _cache: cache, getSettings }; diff --git a/backend/src/utils/jobs.js b/backend/src/utils/jobs.js index 69945e1..7583545 100644 --- a/backend/src/utils/jobs.js +++ b/backend/src/utils/jobs.js @@ -22,7 +22,7 @@ const { generateLicence } = require('./licences'); const { unmetRequirementsFor } = require('./releases'); const { compareVersions } = require('./alerts'); const servers = require('./servers'); -const { missingFor } = require('./envTemplates'); +const { missingFor, invalidFor } = require('./envTemplates'); const MIN = 60 * 1000; const HOUR = 60 * MIN; @@ -384,6 +384,8 @@ async function preflight(server, product, version, now) { if (missing.server.length) parts.push(`${server.name}'s configuration needs ${missing.server.join(', ')}`); if (missing.defaults.length) parts.push(`Install defaults need ${missing.defaults.join(', ')}`); if (parts.length) throw fail(409, 'CONFIG_MISSING', `${parts.join('; ')} (Servers → ${server.name} → Configuration).`); + const invalid = invalidFor(servers.serverConfig(server), await servers.installDefaults()); + if (invalid.length) throw fail(409, 'CONFIG_INVALID', `${server.name}'s configuration: ${invalid.join(' ')} (Servers → ${server.name} → Configuration).`); } /** Products the Hub can install so far (Accounts from Hub 2.3.0, docs/ACCOUNTS-1.0-PLAN.md §9). */ @@ -519,6 +521,8 @@ async function scheduleUpdate({ deploymentIds, version, at, emergency = false, r } const missing = await missingFor(product, release.version, servers.serverConfig(d.server), await servers.installDefaults()); if (missing.server.length || missing.defaults.length) throw fail(409, 'CONFIG_MISSING', `${d.shortName}: set ${[...missing.server, ...missing.defaults].join(', ')} first.`); + const invalid = invalidFor(servers.serverConfig(d.server), await servers.installDefaults()); + if (invalid.length) throw fail(409, 'CONFIG_INVALID', `${d.shortName}: fix ${d.server.name}'s configuration first. ${invalid.join(' ')}`); warnings.push(...scheduleWarnings(when, d)); } const batchId = deployments.length > 1 ? servers.newId('batch') : null; diff --git a/backend/tests/servers.test.js b/backend/tests/servers.test.js index cdef632..6d04a9c 100644 --- a/backend/tests/servers.test.js +++ b/backend/tests/servers.test.js @@ -118,6 +118,16 @@ describe('jobs', () => { expect((await jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.0.0', mode: 'church', runningJobId: null }, NOW)).jobs).toEqual([]); }); + test('a new install is refused while a server setting is one the apps can\'t start with (TRUST_PROXY=TRUE)', async () => { + const { server } = await joinServer(); + // Saved before Hub 2.3.3, which refuses it on save. + await servers.setServerConfig(server.id, { TRUST_PROXY: 'TRUE' }); + await expect(jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW)) + .rejects.toMatchObject({ code: 'CONFIG_INVALID', message: expect.stringContaining('loopback') }); + await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); + await expect(jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW)).resolves.toBeTruthy(); + }); + test('a new install is refused while required server settings are missing, or the agent is offline', async () => { const { server } = await joinServer(); await expect(jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'CONFIG_MISSING', message: expect.stringContaining('TRUST_PROXY') }); diff --git a/backend/vendor/crosscode-contracts-1.5.0.tgz b/backend/vendor/crosscode-contracts-1.5.0.tgz deleted file mode 100644 index 33524c7..0000000 Binary files a/backend/vendor/crosscode-contracts-1.5.0.tgz and /dev/null differ diff --git a/backend/vendor/crosscode-contracts-1.6.0.tgz b/backend/vendor/crosscode-contracts-1.6.0.tgz new file mode 100644 index 0000000..e57b6bd Binary files /dev/null and b/backend/vendor/crosscode-contracts-1.6.0.tgz differ diff --git a/deployment.md b/deployment.md index 8458991..196f599 100644 --- a/deployment.md +++ b/deployment.md @@ -413,7 +413,8 @@ or FASTPANEL: agents reach the Hub on its normal address. every FASTPANEL site still answers after restarting frps), then Servers → Add server → Central, and run the command it shows as root. 5. **Each church server:** Add server → Church, run the command, then on its page set its - configuration: `TRUST_PROXY` (`loopback` behind frp) and the database (`DB_HOST`, `DB_PORT`, + configuration: `TRUST_PROXY` (`loopback` behind frp, lowercase: the Hub refuses a value the apps + can't start with, such as `TRUE`) and the database (`DB_HOST`, `DB_PORT`, `DB_ADMIN_URL`, or nothing for the local PostgreSQL). 6. **Existing installs:** Servers → Installs → Link existing (server, folder name, its two ports). Installs still on 2.1.x from `hope-events` then get a **Move onto the monorepo** (an `adopt` job, diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 74fe853..725d5e2 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "events-hub-frontend", - "version": "2.3.2", + "version": "2.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "events-hub-frontend", - "version": "2.3.2", + "version": "2.3.3", "dependencies": { "lucide-react": "^0.536.0", "next": "^15.5.24", diff --git a/frontend/package.json b/frontend/package.json index b41aeb2..13a5263 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "events-hub-frontend", - "version": "2.3.2", + "version": "2.3.3", "private": true, "scripts": { "dev": "next dev -p 3200", diff --git a/frontend/src/app/(hub)/servers/[id]/page.tsx b/frontend/src/app/(hub)/servers/[id]/page.tsx index a42adce..5f0a641 100644 --- a/frontend/src/app/(hub)/servers/[id]/page.tsx +++ b/frontend/src/app/(hub)/servers/[id]/page.tsx @@ -23,7 +23,7 @@ type Detail = { /** The settings a church server's jobs need (§5); others can be added. */ const SUGGESTED: { key: string; hint: string }[] = [ - { key: "TRUST_PROXY", hint: "Behind frp: loopback" }, + { key: "TRUST_PROXY", hint: "Behind frp: loopback (lowercase; checked when saved)" }, { key: "DB_HOST", hint: "The PostgreSQL server the sites use (default localhost)" }, { key: "DB_PORT", hint: "Default 5432" }, { key: "DB_ADMIN_URL", hint: "postgresql://admin:…@host/postgres: may create databases and roles. Blank: the local PostgreSQL via sudo -u postgres" },