@basaltkit/deploy 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/bootstrap.d.ts +2 -0
- package/dist/bootstrap.js +5 -0
- package/dist/cli.js +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -586,7 +586,9 @@ environment to `~/.pm2/dump.pm2`).
|
|
|
586
586
|
- **The tool root runs is checked.** As root, `install` and `bootstrap` refuse
|
|
587
587
|
to run from files another user can change — `sudo node
|
|
588
588
|
node_modules/@basaltkit/deploy/dist/bin.js` from the checkout, a user's npm
|
|
589
|
-
cache, a per-user Node (nvm) — unless `--unsafe-tool`.
|
|
589
|
+
cache, a per-user Node (nvm) — unless `--unsafe-tool`. The check catches
|
|
590
|
+
that mistake; it cannot stop a copy someone already tampered with (its code
|
|
591
|
+
has run by then), so the defence is the copy itself. Run the pinned copy:
|
|
590
592
|
`cd / && sudo -H npx --yes --package=@basaltkit/deploy@<version> -- basalt-deploy …`
|
|
591
593
|
(`cd /`: inside the checkout npx would pick its own copy; `-H`: root's npm
|
|
592
594
|
cache, not the user's), or a root-owned global install (`sudo npm install -g
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export interface Action {
|
|
|
39
39
|
/** Runs as the app user: its output reaches root's terminal only through a pipe, line by line, sanitized. */
|
|
40
40
|
user?: boolean;
|
|
41
41
|
}
|
|
42
|
+
/** The oldest pnpm root installs globally (lockfile v9; the app user chooses the version, root sets the floor). */
|
|
43
|
+
export declare const MIN_PNPM: number[];
|
|
42
44
|
/**
|
|
43
45
|
* The checkout bootstrap works on — and may `chown -R` to the user — named
|
|
44
46
|
* with `--dir`, never taken from the working directory (root's commands run
|
package/dist/bootstrap.js
CHANGED
|
@@ -5,6 +5,8 @@ import { LineSplitter, sanitize } from './events.js';
|
|
|
5
5
|
import { install, parseInstallPlan } from './install-plan.js';
|
|
6
6
|
import { CHECKOUT_PATH, USER_NAME } from './trust.js';
|
|
7
7
|
const APT = ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get'];
|
|
8
|
+
/** The oldest pnpm root installs globally (lockfile v9; the app user chooses the version, root sets the floor). */
|
|
9
|
+
export const MIN_PNPM = [9, 0, 0];
|
|
8
10
|
// `/`, never a world-writable directory: a tool that reads project config from its working directory finds none there.
|
|
9
11
|
const OUTSIDE = { cwd: '/' };
|
|
10
12
|
const BIN = 'node_modules/@basaltkit/deploy/dist/bin.js';
|
|
@@ -92,6 +94,9 @@ export async function planSystem(host, dir, user) {
|
|
|
92
94
|
const version = (lockfile && lockedPnpm(lockfile)) ?? pkg.packageManager.slice('pnpm@'.length).split('+')[0];
|
|
93
95
|
if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(version))
|
|
94
96
|
throw new DeployError(`the pnpm version the project records ("${version}") is not a version`);
|
|
97
|
+
// The app user picks the version root installs globally: never one older than the floor.
|
|
98
|
+
if (below(minimumVersion(version), MIN_PNPM))
|
|
99
|
+
throw new DeployError(`the project records pnpm ${version}; bootstrap installs pnpm ${MIN_PNPM.join('.')} or newer globally, as root — update packageManager and the lockfile`);
|
|
95
100
|
const current = (await host.exec('pnpm', ['--version'], OUTSIDE)).stdout.trim();
|
|
96
101
|
if (current !== version)
|
|
97
102
|
actions.push({ what: `pnpm ${version}${current ? ` (this server has ${current})` : ''}`, commands: [['npm', 'install', '-g', `pnpm@${version}`]] });
|
package/dist/cli.js
CHANGED
|
@@ -121,7 +121,14 @@ const COMMANDS = ['init', 'check', 'plan', 'run', 'env', 'rollback', 'status', '
|
|
|
121
121
|
/** The commands that take the deploy lock, and so write a run log under --json. */
|
|
122
122
|
const LOCKED = new Set(['run', 'env', 'rollback']);
|
|
123
123
|
const usage = (message, hint) => new DeployError(message, [], 'usage', hint);
|
|
124
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* The files root is about to run: node, and this package's own (its directory
|
|
126
|
+
* and modules). A guard against the mistake — `sudo node node_modules/…` from
|
|
127
|
+
* the checkout, a user's npm cache, an nvm node — not against a tampered
|
|
128
|
+
* copy: every module is already loaded when this runs. The defence is to run
|
|
129
|
+
* a copy only root can change (the pinned `npx` line, or a root-owned global
|
|
130
|
+
* install).
|
|
131
|
+
*/
|
|
125
132
|
async function assertTrustedTool(host, unsafe) {
|
|
126
133
|
const dir = dirname(fileURLToPath(import.meta.url));
|
|
127
134
|
const modules = (await host.list(dir)).filter((name) => name.endsWith('.js')).map((name) => join(dir, name));
|