@basaltkit/deploy 0.5.2 → 0.5.3
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 +24 -9
- package/dist/apache.js +14 -2
- package/dist/bootstrap.d.ts +14 -0
- package/dist/bootstrap.js +31 -9
- package/dist/events.js +5 -1
- package/dist/init.js +1 -1
- package/dist/install-plan.js +26 -4
- package/dist/trust.d.ts +6 -0
- package/dist/trust.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -269,8 +269,12 @@ only NDJSON events, one per line:
|
|
|
269
269
|
- **No event carries a secret.** Every string is redacted before it is
|
|
270
270
|
written: the values of generated, asked-secret and secret-named `.env` keys,
|
|
271
271
|
passwords inside URLs, the infra passwords, secret-named variables of the
|
|
272
|
-
deploy's own environment, every secret answer — raw and URL-encoded
|
|
273
|
-
|
|
272
|
+
deploy's own environment, every secret answer — raw and URL-encoded, and a
|
|
273
|
+
multi-line value (a PEM key) also with its newlines escaped and line by
|
|
274
|
+
line — become `[redacted:KEY]`. A name is secret when it holds `SECRET`,
|
|
275
|
+
`TOKEN`, `PASSW`, `PRIVATE`, `APIKEY`, `CREDENTIAL`, a `KEY`, `SALT` or
|
|
276
|
+
`PWD` word, or ends in `_URL`/`_DSN`; declare any other with `generate` or
|
|
277
|
+
`ask.secret`. What the config prints while it loads waits until
|
|
274
278
|
its `.env` has been read. A bare origin in a `*_URL` key
|
|
275
279
|
(`APP_URL=https://app.example.com`) is the app's address and is not
|
|
276
280
|
redacted. A value shorter than 6 characters cannot be matched; a
|
|
@@ -553,18 +557,29 @@ environment to `~/.pm2/dump.pm2`).
|
|
|
553
557
|
loads `deploy.config.ts`, the checkout's `tsx` or `node_modules`, nor reads
|
|
554
558
|
the `.env`. Before writing it prints what it will do. Raw Caddy `extra` and a
|
|
555
559
|
non-default proxy root are shown and need a "yes" at the terminal; `extra`
|
|
556
|
-
may hold no control or
|
|
557
|
-
written) and no `import`.
|
|
560
|
+
may hold no control, direction or zero-width character (what is shown is
|
|
561
|
+
what is written) and no `import`.
|
|
558
562
|
- **A plan cannot take another site.** The managed vhost is `<app>.conf` (or
|
|
559
563
|
`<app>-….conf`), and `install` refuses a domain — or a name under its
|
|
560
564
|
wildcard, or a wildcard over it — that another Apache vhost or Caddy site
|
|
561
|
-
already serves.
|
|
565
|
+
already serves (Caddy `extra` site blocks included). The file it replaces
|
|
566
|
+
must be the app's own: written by `install` for it, or serving only its
|
|
567
|
+
names.
|
|
562
568
|
- **The served directory follows no planted link out of the user's files.**
|
|
563
569
|
The vhost sets `Options -FollowSymLinks +SymLinksIfOwnerMatch` and
|
|
564
|
-
`AllowOverride None` on the checkout and the web root
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
570
|
+
`AllowOverride None` on the checkout and the web root, and the link rule on
|
|
571
|
+
every directory above the checkout too — a parent the user can write
|
|
572
|
+
(`/home/<user>`) could otherwise hold a link swapped in for the checkout
|
|
573
|
+
itself. `install` refuses a checkout reached through a link, and the plan's
|
|
574
|
+
`dir` is letters, digits and `. _ @ + -` only. Caddy's `file_server` has no
|
|
575
|
+
such option: with `caddy()`, a link in the web root is followed to anything
|
|
576
|
+
the `caddy` user can read — keep secrets of other sites out of its reach,
|
|
577
|
+
and the checkout under a root-owned directory (`/srv/<app>`; `install` warns
|
|
578
|
+
otherwise).
|
|
579
|
+
- **A user step never gets root's terminal.** In `bootstrap`, the app user's
|
|
580
|
+
`pnpm install` (and `env` without a terminal) writes to a pipe, not to
|
|
581
|
+
root's terminal: a process a postinstall leaves behind cannot read root's
|
|
582
|
+
keystrokes. Its output is shown line by line, without escape sequences.
|
|
568
583
|
- **Root writes only where no other user can plant a link**: directories
|
|
569
584
|
only root can write (`/var/lib/basalt`, `/etc/basalt`, the Apache/Caddy
|
|
570
585
|
roots), or files changed through an `O_NOFOLLOW` descriptor.
|
package/dist/apache.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
2
|
import { vhostName } from './config.js';
|
|
3
3
|
import { DeployError, INSTALL_COMMAND } from './context.js';
|
|
4
4
|
import { lineDiff } from './diff.js';
|
|
@@ -27,6 +27,18 @@ export function renderVhost(ctx, port) {
|
|
|
27
27
|
const webRoot = join(ctx.dir, proxy.webRoot);
|
|
28
28
|
const prefix = proxy.apiPrefix.replace(/\/$/, '');
|
|
29
29
|
const cert = `/etc/letsencrypt/live/${proxy.certName ?? domain}`;
|
|
30
|
+
// Apache checks a link against the options of the directory that holds it:
|
|
31
|
+
// a parent the app user can write (/home/<user>) could hold a link swapped
|
|
32
|
+
// in for the checkout itself, judged by the server's <Directory /> (which
|
|
33
|
+
// follows links), not by the blocks below. Every directory above the
|
|
34
|
+
// checkout gets the same rule.
|
|
35
|
+
const above = [];
|
|
36
|
+
for (let parent = dirname(ctx.dir); parent !== '/' && parent !== '.'; parent = dirname(parent))
|
|
37
|
+
above.unshift(parent);
|
|
38
|
+
const parents = above.map((parent) => ` <Directory ${parent}>
|
|
39
|
+
Options -FollowSymLinks +SymLinksIfOwnerMatch
|
|
40
|
+
</Directory>
|
|
41
|
+
`).join('');
|
|
30
42
|
return `# Written by basalt-deploy install for "${app}". Deploys compare this file with
|
|
31
43
|
# what install would write and print the difference; they never rewrite it.
|
|
32
44
|
# To change it: edit deploy.config.ts, run ${INSTALL_COMMAND}
|
|
@@ -46,7 +58,7 @@ ${alias}
|
|
|
46
58
|
# The checkout is the app user's: a link it plants is followed only to a
|
|
47
59
|
# file it owns too (never to /, nor to another site's files), and no
|
|
48
60
|
# .htaccess turns that back on.
|
|
49
|
-
<Directory ${ctx.dir}>
|
|
61
|
+
${parents} <Directory ${ctx.dir}>
|
|
50
62
|
Options -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
|
|
51
63
|
AllowOverride None
|
|
52
64
|
</Directory>
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface Action {
|
|
|
36
36
|
interactive?: boolean;
|
|
37
37
|
/** Asked at the terminal before a real run runs it; a "no" (or no terminal) stops bootstrap. */
|
|
38
38
|
confirm?: string;
|
|
39
|
+
/** Runs as the app user: its output reaches root's terminal only through a pipe, line by line, sanitized. */
|
|
40
|
+
user?: boolean;
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
41
43
|
* The checkout bootstrap works on — and may `chown -R` to the user — named
|
|
@@ -60,6 +62,13 @@ export declare function planSystem(host: Host, dir: string, user: string): Promi
|
|
|
60
62
|
* of its own (`script`, run by root, relays the keys) — or, with no terminal
|
|
61
63
|
* to relay, runs like the others and fails closed on a missing answer.
|
|
62
64
|
*
|
|
65
|
+
* And never root's terminal as the step's stdout/stderr either: an inherited
|
|
66
|
+
* descriptor is the session's read-write pty, and a process the step leaves
|
|
67
|
+
* behind could keep it and read root's keystrokes for the rest of the SSH
|
|
68
|
+
* session. Its output comes through a pipe instead — split into lines, every
|
|
69
|
+
* escape sequence and control character stripped — and the pipe is closed
|
|
70
|
+
* once the step exits, whatever it left running.
|
|
71
|
+
*
|
|
63
72
|
* A Ctrl-C does not reach a step in its own session: bootstrap stops, the
|
|
64
73
|
* step finishes on its own.
|
|
65
74
|
*/
|
|
@@ -82,4 +91,9 @@ export declare function planBootstrap(host: Host, dir: string, options: Bootstra
|
|
|
82
91
|
}>;
|
|
83
92
|
/** The @basaltkit/deploy version the lockfile records — what root should be running. */
|
|
84
93
|
export declare function lockedDeployVersion(lockfile: string): string | undefined;
|
|
94
|
+
/** A user step's output, for root's terminal: whole lines, sanitized, nothing that can drive the terminal. */
|
|
95
|
+
export declare function relay(host: Host): {
|
|
96
|
+
write: (text: string, stream: 'stdout' | 'stderr') => void;
|
|
97
|
+
flush: () => void;
|
|
98
|
+
};
|
|
85
99
|
export declare function bootstrap(host: Host, dir: string, options: BootstrapOptions, tool?: string): Promise<number>;
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { tmpdir } from 'node:os';
|
|
2
1
|
import { join, normalize } from 'node:path';
|
|
3
2
|
import { below, lockedPnpm, minimumVersion } from './checks.js';
|
|
4
3
|
import { DeployError } from './context.js';
|
|
4
|
+
import { LineSplitter, sanitize } from './events.js';
|
|
5
5
|
import { install, parseInstallPlan } from './install-plan.js';
|
|
6
|
-
import { USER_NAME } from './trust.js';
|
|
6
|
+
import { CHECKOUT_PATH, USER_NAME } from './trust.js';
|
|
7
7
|
const APT = ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get'];
|
|
8
|
-
|
|
8
|
+
// `/`, never a world-writable directory: a tool that reads project config from its working directory finds none there.
|
|
9
|
+
const OUTSIDE = { cwd: '/' };
|
|
9
10
|
const BIN = 'node_modules/@basaltkit/deploy/dist/bin.js';
|
|
10
11
|
const sh = (script) => ['sh', '-c', script];
|
|
11
12
|
/** Read as data, as root, from the app user's checkout: no link followed, a size cap (a FIFO or /dev/zero must not hang root). */
|
|
@@ -29,8 +30,8 @@ const SYSTEM_TREES = ['/bin/', '/boot/', '/dev/', '/etc/', '/lib/', '/lib32/', '
|
|
|
29
30
|
* no link in it, not a system directory, holding package.json and .git.
|
|
30
31
|
*/
|
|
31
32
|
export async function checkoutProblem(host, dir) {
|
|
32
|
-
if (!
|
|
33
|
-
return `${dir} must be an absolute, normalized path
|
|
33
|
+
if (!CHECKOUT_PATH.test(dir) || normalize(dir) !== dir || (dir !== '/' && dir.endsWith('/')))
|
|
34
|
+
return `${dir} must be an absolute, normalized path of letters, digits and . _ @ + - only`;
|
|
34
35
|
if (SYSTEM_DIRS.has(dir) || SYSTEM_TREES.some((tree) => dir.startsWith(tree)))
|
|
35
36
|
return `${dir} is a system directory, not an app checkout`;
|
|
36
37
|
const stat = await host.stat(dir);
|
|
@@ -122,6 +123,13 @@ export async function planSystem(host, dir, user) {
|
|
|
122
123
|
* of its own (`script`, run by root, relays the keys) — or, with no terminal
|
|
123
124
|
* to relay, runs like the others and fails closed on a missing answer.
|
|
124
125
|
*
|
|
126
|
+
* And never root's terminal as the step's stdout/stderr either: an inherited
|
|
127
|
+
* descriptor is the session's read-write pty, and a process the step leaves
|
|
128
|
+
* behind could keep it and read root's keystrokes for the rest of the SSH
|
|
129
|
+
* session. Its output comes through a pipe instead — split into lines, every
|
|
130
|
+
* escape sequence and control character stripped — and the pipe is closed
|
|
131
|
+
* once the step exits, whatever it left running.
|
|
132
|
+
*
|
|
125
133
|
* A Ctrl-C does not reach a step in its own session: bootstrap stops, the
|
|
126
134
|
* step finishes on its own.
|
|
127
135
|
*/
|
|
@@ -132,8 +140,8 @@ export function userSteps(user, dir, tty) {
|
|
|
132
140
|
? ['script', '--quiet', '--return', '--command', asUser('node', BIN, 'env').join(' '), '/dev/null']
|
|
133
141
|
: ['setsid', '-w', ...asUser('node', BIN, 'env')];
|
|
134
142
|
return [
|
|
135
|
-
{ what: `as ${user}: dependencies`, cwd: dir, commands: [['setsid', '-w', ...asUser('env', '-u', 'NODE_ENV', 'pnpm', 'install', '--frozen-lockfile')]] },
|
|
136
|
-
{ what: `as ${user}: the .env (asks what it cannot generate)`, cwd: dir, ...(tty ? { interactive: true } : {}), commands: [env] },
|
|
143
|
+
{ what: `as ${user}: dependencies`, cwd: dir, user: true, commands: [['setsid', '-w', ...asUser('env', '-u', 'NODE_ENV', 'pnpm', 'install', '--frozen-lockfile')]] },
|
|
144
|
+
{ what: `as ${user}: the .env (asks what it cannot generate)`, cwd: dir, ...(tty ? { interactive: true } : { user: true }), commands: [env] },
|
|
137
145
|
];
|
|
138
146
|
}
|
|
139
147
|
/** The phase-2 command whose stdout is the install plan (JSON) — in its own session, like the other steps. */
|
|
@@ -208,6 +216,18 @@ export async function planBootstrap(host, dir, options) {
|
|
|
208
216
|
export function lockedDeployVersion(lockfile) {
|
|
209
217
|
return /['"]?@basaltkit\/deploy@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)['"]?:/.exec(lockfile)?.[1];
|
|
210
218
|
}
|
|
219
|
+
/** A user step's output, for root's terminal: whole lines, sanitized, nothing that can drive the terminal. */
|
|
220
|
+
export function relay(host) {
|
|
221
|
+
const splitters = { stdout: new LineSplitter(), stderr: new LineSplitter() };
|
|
222
|
+
const show = (lines) => {
|
|
223
|
+
for (const line of lines)
|
|
224
|
+
host.out.info(` ${sanitize(line.text)}${line.cut ? ' …' : ''}`);
|
|
225
|
+
};
|
|
226
|
+
return {
|
|
227
|
+
write: (text, stream) => show(splitters[stream].push(text)),
|
|
228
|
+
flush: () => { show(splitters.stdout.end()); show(splitters.stderr.end()); },
|
|
229
|
+
};
|
|
230
|
+
}
|
|
211
231
|
async function runActions(host, actions, dryRun) {
|
|
212
232
|
for (const action of actions) {
|
|
213
233
|
host.out.info(action.what);
|
|
@@ -218,10 +238,12 @@ async function runActions(host, actions, dryRun) {
|
|
|
218
238
|
host.out.info(` + ${command.join(' ')}${action.cwd ? ` (in ${action.cwd})` : ''}`);
|
|
219
239
|
if (dryRun)
|
|
220
240
|
continue;
|
|
241
|
+
const output = action.user && !action.interactive ? relay(host) : undefined;
|
|
221
242
|
const result = await host.exec(command[0], command.slice(1), {
|
|
222
243
|
cwd: action.cwd ?? OUTSIDE.cwd,
|
|
223
|
-
...(action.interactive ? { interactive: true } : { stream: true }),
|
|
244
|
+
...(action.interactive ? { interactive: true } : output ? { stream: true, onOutput: output.write } : { stream: true }),
|
|
224
245
|
});
|
|
246
|
+
output?.flush();
|
|
225
247
|
if (result.code !== 0)
|
|
226
248
|
throw new DeployError(`${action.what}: \`${command.join(' ')}\` failed (exit ${result.code}) — re-run bootstrap after fixing it; what is done is not redone`);
|
|
227
249
|
}
|
|
@@ -262,7 +284,7 @@ export async function bootstrap(host, dir, options, tool) {
|
|
|
262
284
|
host.out.info(`as ${user}: the install plan\n + ${command.join(' ')}`);
|
|
263
285
|
const written = await host.exec(command[0], command.slice(1), { cwd: dir });
|
|
264
286
|
if (written.code !== 0)
|
|
265
|
-
throw new DeployError(`install-plan as ${user} failed (exit ${written.code}): ${written.stderr.trim().split('\n').slice(-3).join(' ')}`);
|
|
287
|
+
throw new DeployError(`install-plan as ${user} failed (exit ${written.code}): ${sanitize(written.stderr.trim().split('\n').slice(-3).join(' '))}`);
|
|
266
288
|
const plan = parseInstallPlan(written.stdout, `the install plan from ${user}`);
|
|
267
289
|
if (plan.dir !== dir)
|
|
268
290
|
throw new DeployError(`the install plan names ${plan.dir}, not ${dir} — refused`);
|
package/dist/events.js
CHANGED
|
@@ -149,7 +149,11 @@ export class Redactor {
|
|
|
149
149
|
return 'short';
|
|
150
150
|
}
|
|
151
151
|
let added = false;
|
|
152
|
-
|
|
152
|
+
// A multi-line value (a PEM key) reaches the log line by line, or with its
|
|
153
|
+
// newlines escaped: each form, and each line long enough not to be common text.
|
|
154
|
+
const lines = value.includes('\n') ? value.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length >= 16) : [];
|
|
155
|
+
const escaped = lines.length ? [value.replace(/\r?\n/g, '\\n')] : [];
|
|
156
|
+
for (const form of new Set([value, encodeURIComponent(value), ...escaped, ...lines])) {
|
|
153
157
|
if (form.length < MIN_REDACTED_LENGTH || this.needles.has(form))
|
|
154
158
|
continue;
|
|
155
159
|
this.needles.set(form, key);
|
package/dist/init.js
CHANGED
|
@@ -4,7 +4,7 @@ const COMPOSE_FILES = ['docker/compose.prod.yml', 'docker/compose.prod.yaml', 'c
|
|
|
4
4
|
const PRISMA_CENTRAL = 'prisma.config.ts';
|
|
5
5
|
const PRISMA_TENANTS = 'prisma/tenants/prisma.config.ts';
|
|
6
6
|
/** Key names whose values are secrets (what `init` asks as `ask.secret`, what JSON mode redacts). */
|
|
7
|
-
export const SENSITIVE = /SECRET|TOKEN|
|
|
7
|
+
export const SENSITIVE = /SECRET|TOKEN|PASSW|PASS\b|_PWD(?:_|$)|(?:^|_)KEY(?:_|$)|APIKEY|PRIVATE|(?:^|_)SALT(?:_|$)|CREDENTIAL|_URL$|_DSN$/;
|
|
8
8
|
/**
|
|
9
9
|
* A `secret()` the app can mint for itself (signing, encryption): generated on
|
|
10
10
|
* the server. One a provider issues (S3, an API, SMTP) is asked instead — a
|
package/dist/install-plan.js
CHANGED
|
@@ -7,7 +7,7 @@ import { envValues } from './dotenv.js';
|
|
|
7
7
|
import { envFile, envMirrors, readEnv } from './env-step.js';
|
|
8
8
|
import { acquireLock } from './lock.js';
|
|
9
9
|
import { covers } from './checks.js';
|
|
10
|
-
import { API_PREFIX, ASK_PATH, assertRootOwnedDir, caddyExtraProblem, CERT_NAME, envLocationProblem, isConfigRoot, isWebRoot, USER_NAME, vhostFileProblem } from './trust.js';
|
|
10
|
+
import { API_PREFIX, ASK_PATH, assertRootOwnedDir, caddyExtraProblem, CERT_NAME, CHECKOUT_PATH, envLocationProblem, isConfigRoot, isWebRoot, untrustedAncestor, USER_NAME, vhostFileProblem } from './trust.js';
|
|
11
11
|
/**
|
|
12
12
|
* `install` in two halves (RFC 0006 §11.4), so that root never runs code the
|
|
13
13
|
* app user can change:
|
|
@@ -100,8 +100,8 @@ export function parseInstallPlan(text, source) {
|
|
|
100
100
|
if (plan['tenants'] !== 'subdomain' && plan['tenants'] !== 'none')
|
|
101
101
|
problems.push('tenants is subdomain or none');
|
|
102
102
|
const dir = plan['dir'];
|
|
103
|
-
if (typeof dir !== 'string' || !
|
|
104
|
-
problems.push('dir must be an absolute, normalized path
|
|
103
|
+
if (typeof dir !== 'string' || !CHECKOUT_PATH.test(dir) || dir === '/' || normalize(dir) !== dir || dir.endsWith('/')) {
|
|
104
|
+
problems.push('dir must be an absolute, normalized path of letters, digits and . _ @ + - only (not /)');
|
|
105
105
|
}
|
|
106
106
|
const port = plan['port'];
|
|
107
107
|
if (typeof port !== 'number' || !Number.isInteger(port) || port < 1 || port > 65535)
|
|
@@ -231,6 +231,9 @@ export async function install(host, plan, user, options = {}) {
|
|
|
231
231
|
throw new DeployError(`${plan.dir} is not a directory (a symbolic link is refused)`);
|
|
232
232
|
if (checkout.uid !== owner.uid)
|
|
233
233
|
throw new DeployError(`${plan.dir} is not ${user}'s (uid ${checkout.uid}): install serves ${user}'s checkout only`);
|
|
234
|
+
const real = await host.realpath(plan.dir);
|
|
235
|
+
if (real !== plan.dir)
|
|
236
|
+
throw new DeployError(`${plan.dir} goes through a symbolic link (it is ${real ?? 'unreadable'}): the plan must name the real directory`);
|
|
234
237
|
const stateRoot = options.stateRoot ?? '/var/lib/basalt';
|
|
235
238
|
await host.mkdir(stateRoot, 0o755);
|
|
236
239
|
await assertRootOwnedDir(host, stateRoot, 'state directory');
|
|
@@ -281,6 +284,10 @@ export async function install(host, plan, user, options = {}) {
|
|
|
281
284
|
await host.mkdir(caddyPaths(ctx).dir, 0o755);
|
|
282
285
|
await assertRootOwnedDir(host, caddyPaths(ctx).dir, 'Caddy');
|
|
283
286
|
await caddyInstall(ctx, plan.port, backups);
|
|
287
|
+
// Caddy follows links wherever they go (RFC 0006 §14.1): said, not hidden.
|
|
288
|
+
const open = await untrustedAncestor(host, dirname(plan.dir));
|
|
289
|
+
if (open)
|
|
290
|
+
host.out.warn(`${open} is writable by a user other than root: ${user} could swap ${plan.dir} for a link, and Caddy would serve wherever it points — keep checkouts under a root-owned directory (/srv/<app>)`);
|
|
284
291
|
}
|
|
285
292
|
if (plan.docker) {
|
|
286
293
|
const groups = (await host.exec('id', ['-nG', user])).stdout.split(/\s+/);
|
|
@@ -339,7 +346,22 @@ const overlap = (a, b) => a === b || (a.startsWith('*.') && covers(a, b)) || (b.
|
|
|
339
346
|
* its wildcard — would take that app's traffic and certificate.
|
|
340
347
|
*/
|
|
341
348
|
async function refuseTakenNames(host, plan, dirs, own, kind, main) {
|
|
342
|
-
|
|
349
|
+
// Caddy `extra` can open site blocks of its own: their addresses are names this site takes too.
|
|
350
|
+
const extra = plan.proxy.kind === 'caddy' && plan.proxy.managed && plan.proxy.extra !== undefined ? servedNames(plan.proxy.extra, 'caddy') : [];
|
|
351
|
+
const ours = [plan.domain, ...(plan.tenants === 'subdomain' ? [`*.${plan.domain}`] : []), ...extra];
|
|
352
|
+
// The file about to be replaced is this app's: written by install for it, or (hand-written,
|
|
353
|
+
// being adopted) serving nothing but its names — never another app's that `vhost` happens to name.
|
|
354
|
+
for (const dir of dirs) {
|
|
355
|
+
const file = join(dir, own);
|
|
356
|
+
const text = await host.readFile(file);
|
|
357
|
+
if (text === undefined)
|
|
358
|
+
continue;
|
|
359
|
+
const writer = /^# Written by basalt-deploy install for "([^"]*)"/m.exec(text)?.[1];
|
|
360
|
+
const foreign = servedNames(text, kind).filter((name) => !ours.some((mine) => overlap(mine, name)));
|
|
361
|
+
if ((writer !== undefined && writer !== plan.app) || (writer === undefined && foreign.length > 0)) {
|
|
362
|
+
throw new DeployError(`refused: ${file} is ${writer !== undefined ? `"${writer}"'s` : `a site for ${[...new Set(foreign)].join(', ')}`}, not "${plan.app}"'s — name another file (proxy.vhost)`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
343
365
|
const files = [...(main ? [main] : []), ...(await Promise.all(dirs.map(async (dir) => (await host.list(dir)).filter((name) => name !== own).map((name) => join(dir, name))))).flat()];
|
|
344
366
|
for (const file of files) {
|
|
345
367
|
const text = await host.readFile(file);
|
package/dist/trust.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ import type { Host } from './host.js';
|
|
|
11
11
|
*/
|
|
12
12
|
/** A login name: what `useradd` accepts, never an option or a path. */
|
|
13
13
|
export declare const USER_NAME: RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* A checkout path: a closed set of characters. It is written into the Apache
|
|
16
|
+
* vhost and the Caddy site, where `{ }` are placeholders, `* ? [ ]`
|
|
17
|
+
* wildcards and `#` a comment.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CHECKOUT_PATH: RegExp;
|
|
14
20
|
/** Directory served by the proxy, relative to the checkout: inside it, never the checkout itself, never a dot directory. */
|
|
15
21
|
export declare function isWebRoot(value: unknown): value is string;
|
|
16
22
|
/** `/api`, `/api/v1/`: URL path segments, no dot segments, nothing a config file would parse. */
|
package/dist/trust.js
CHANGED
|
@@ -12,6 +12,12 @@ import { DeployError } from './context.js';
|
|
|
12
12
|
*/
|
|
13
13
|
/** A login name: what `useradd` accepts, never an option or a path. */
|
|
14
14
|
export const USER_NAME = /^[a-z_][a-z0-9_-]{0,31}$/;
|
|
15
|
+
/**
|
|
16
|
+
* A checkout path: a closed set of characters. It is written into the Apache
|
|
17
|
+
* vhost and the Caddy site, where `{ }` are placeholders, `* ? [ ]`
|
|
18
|
+
* wildcards and `#` a comment.
|
|
19
|
+
*/
|
|
20
|
+
export const CHECKOUT_PATH = /^\/[A-Za-z0-9._@+/-]*$/;
|
|
15
21
|
/** A path segment with no leading dot: never `.`, `..`, `.git`, `.env`, `.basalt`. */
|
|
16
22
|
const SEGMENT = /^[A-Za-z0-9_][A-Za-z0-9._-]*$/;
|
|
17
23
|
/** Directory served by the proxy, relative to the checkout: inside it, never the checkout itself, never a dot directory. */
|
|
@@ -30,10 +36,11 @@ export const ASK_PATH = /^(\/[A-Za-z0-9_~-][A-Za-z0-9._~-]*)+$/;
|
|
|
30
36
|
export const CERT_NAME = /^[A-Za-z0-9][A-Za-z0-9-]*(\.[A-Za-z0-9-]+)*$/;
|
|
31
37
|
/**
|
|
32
38
|
* Characters a terminal acts on instead of showing (CR, ESC and the C1 CSI,
|
|
33
|
-
* line separators, bidirectional overrides)
|
|
39
|
+
* line separators, bidirectional overrides), or shows as nothing (zero-width
|
|
40
|
+
* spaces and joiners, soft hyphen, BOM): `install` shows raw Caddy
|
|
34
41
|
* `extra` before root writes it, and what is shown must be what is written.
|
|
35
42
|
*/
|
|
36
|
-
const HIDDEN = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/;
|
|
43
|
+
const HIDDEN = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u00ad\u061c\u180e\u200b-\u200f\u2028\u2029\u202a-\u202e\u2060-\u2064\u2066-\u2069\ufeff]/;
|
|
37
44
|
/**
|
|
38
45
|
* Raw Caddy `extra`: no character that hides text on a terminal, and no
|
|
39
46
|
* `import` — a file the app user can change later would be configuration
|