Files
BetterDesk/web-nodejs/scripts/write-installer-env-subst.js
T
Knienartowicz 61729eed9d fix(update): generate a missing PANEL_TRUST_SECRET on install and update
The panel trust bridge is off unless `PANEL_TRUST_SECRET` has a value, and
the template shipped it blank. The updater appends missing keys from the
template, so an install that predates the bridge ended up with
`PANEL_TRUST_SECRET=` and the console could not sign panel statements.
The Agents page then reported that address-book names were unavailable
because the console could not securely reach the Go address-book service.

`mergeEnvFile` now fills empty auto-generated secrets after merging, and
`buildEnvSubstitutions` resolves the template placeholder so fresh installs
get a real key. A non-empty value is never overwritten, and the key is
listed in PROTECTED_KEYS so a later overwrite cannot happen. Co-located
console and Go need nothing else: loopback is always allowed by
`panelTrustPeerAllowed`. Only split deployments need
`PANEL_TRUST_ALLOWED_HOSTS`, which the template now says explicitly instead
of implying it is required everywhere.

Ships via panel update (Settings -> Updates). Verify: on an install whose
`.env` has a blank `PANEL_TRUST_SECRET`, run an update and confirm the key
has a 64-character value and the Go log shows
`[panel-trust] enabled for panel-originated requests`.

Thanks: INSOLVE (Honorary); betterde.sk (@trybetterdesk, Bronze); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
2026-11-23 11:30:54 +01:00

33 lines
971 B
JavaScript

#!/usr/bin/env node
'use strict';
/**
* Write JSON substitution file for merge-env.js (safe for special chars in passwords/paths).
* Reads BD_SUBST_* environment variables set by betterdesk.sh / betterdesk.ps1.
*
* Usage: node write-installer-env-subst.js /path/to/subst.json
*/
const fs = require('fs');
const KEYS = [
'RUSTDESK_DIR', 'PUB_KEY_PATH', 'API_KEY_PATH', 'DB_TYPE', 'DB_PATH', 'DATABASE_URL',
'DATA_DIR', 'GO_API_PORT', 'HBBS_API_URL', 'BETTERDESK_API_URL', 'API_PORT',
'DEFAULT_ADMIN_PASSWORD', 'SESSION_SECRET', 'REMOTE_TARGET_VAULT_KEY',
'PANEL_TRUST_SECRET',
'GUACD_ADDRESS', 'SSL_CERT_PATH', 'SSL_KEY_PATH'
];
const outPath = process.argv[2];
if (!outPath) {
console.error('Usage: node write-installer-env-subst.js OUTPUT.json');
process.exit(2);
}
const subs = {};
for (const key of KEYS) {
subs[key] = process.env[`BD_SUBST_${key}`] || '';
}
fs.writeFileSync(outPath, JSON.stringify(subs), { mode: 0o600 });