@bakers-build/core 0.14.0 → 0.14.1-next.1
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/dist/src/cli/config-inventory.js +7 -0
- package/dist/src/cli/config-protected-paths.d.ts +9 -0
- package/dist/src/cli/config-protected-paths.js +59 -0
- package/dist/src/core/host-commands.d.ts +12 -0
- package/dist/src/core/host-commands.js +29 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/package.json +3 -3
|
@@ -4,6 +4,7 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { shellQuote } from '../core/shell.js';
|
|
6
6
|
import { findConfigProjectBbDir, homeBbDir, stemForConfigFile, } from './bakers-dir.js';
|
|
7
|
+
import { protectedPathProblems } from './config-protected-paths.js';
|
|
7
8
|
import { configRecheckCommand, finalizeConfigReport, } from './config-report.js';
|
|
8
9
|
import { inspectConfigSource, } from './config-source.js';
|
|
9
10
|
import { checkConfigText } from './config-validate.js';
|
|
@@ -390,6 +391,12 @@ export function inventoryConfig(options = {}) {
|
|
|
390
391
|
});
|
|
391
392
|
}
|
|
392
393
|
}
|
|
394
|
+
if (kind === 'project' && projectRoot) {
|
|
395
|
+
const flagged = new Set(report.findings.slice(startFindings).map((finding) => finding.key));
|
|
396
|
+
for (const problem of protectedPathProblems(source, sources.get(machinePath), projectRoot))
|
|
397
|
+
if (!flagged.has(problem.key))
|
|
398
|
+
add('invalid_value', problem.key, problem.expected, problem.remediation, 'schema', 'error', problem.property);
|
|
399
|
+
}
|
|
393
400
|
const findings = report.findings.slice(startFindings);
|
|
394
401
|
if (findings.some((finding) => finding.severity === 'error'))
|
|
395
402
|
file.state = 'partial';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConfigSourceInspection, ConfigSourceProperty } from './config-source.js';
|
|
2
|
+
export interface ProtectedPathProblem {
|
|
3
|
+
key: string;
|
|
4
|
+
expected: string;
|
|
5
|
+
remediation: string;
|
|
6
|
+
property: ConfigSourceProperty;
|
|
7
|
+
}
|
|
8
|
+
/** Statically visible faults the conductor would refuse at start or dispatch. */
|
|
9
|
+
export declare function protectedPathProblems(project: ConfigSourceInspection, machine: ConfigSourceInspection | undefined, projectRoot: string): ProtectedPathProblem[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { unprotectedEntryPoints } from '../core/host-commands.js';
|
|
4
|
+
const DOCS = 'https://bakers.build/provision/hooks#protect-host-executed-files';
|
|
5
|
+
const staticStrings = (source, pattern) => [...(source?.properties.values() ?? [])].filter((p) => pattern.test(p.key) &&
|
|
6
|
+
p.staticallyDetermined &&
|
|
7
|
+
typeof p.value === 'string');
|
|
8
|
+
/**
|
|
9
|
+
* shortcut: offline cannot import addons to read `isolates`, so any catalog
|
|
10
|
+
* runtime or `addon-runtime-*` addon counts as isolating (every shipped one
|
|
11
|
+
* does); upgrade once runtime addons declare `isolates` in package metadata.
|
|
12
|
+
*/
|
|
13
|
+
function isolating(project, machine) {
|
|
14
|
+
const machineRuntime = staticStrings(machine, /^runtime\.catalog\[\d+\]\.use$/).length > 0 ||
|
|
15
|
+
staticStrings(machine, /^addons\[\d+\](\.use)?$/).some((p) => String(p.value).includes('addon-runtime-'));
|
|
16
|
+
if (!machineRuntime)
|
|
17
|
+
return false;
|
|
18
|
+
if (!project.properties.has('runtime.enabled'))
|
|
19
|
+
return true;
|
|
20
|
+
return staticStrings(project, /^runtime\.enabled\[\d+\]$/).some((p) => p.value !== 'system');
|
|
21
|
+
}
|
|
22
|
+
/** Statically visible faults the conductor would refuse at start or dispatch. */
|
|
23
|
+
export function protectedPathProblems(project, machine, projectRoot) {
|
|
24
|
+
const problems = [];
|
|
25
|
+
const readOnly = staticStrings(project, /^runtime\.read_only\[\d+\]$/);
|
|
26
|
+
for (const property of readOnly) {
|
|
27
|
+
if (!existsSync(join(projectRoot, String(property.value))))
|
|
28
|
+
problems.push({
|
|
29
|
+
key: property.key,
|
|
30
|
+
expected: `runtime.read_only path ${property.value} exists in ${projectRoot}`,
|
|
31
|
+
remediation: `Create ${property.value} in ${projectRoot} or remove it from runtime.read_only.`,
|
|
32
|
+
property,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// A computed runtime block hides read_only or enabled: judge no hook against a guess.
|
|
36
|
+
const runtimeComputed = project.unknownKeys ||
|
|
37
|
+
[...project.properties.values()].some((p) => (p.key === 'runtime' ||
|
|
38
|
+
p.key.startsWith('runtime.read_only') ||
|
|
39
|
+
p.key.startsWith('runtime.enabled')) &&
|
|
40
|
+
!p.staticallyDetermined);
|
|
41
|
+
if (runtimeComputed || !isolating(project, machine))
|
|
42
|
+
return problems;
|
|
43
|
+
const commands = new Map();
|
|
44
|
+
for (const property of staticStrings(project, /^hooks\.[^.[\]]+(\.[^.[\]]+)?(\.command)?$/)) {
|
|
45
|
+
// Only `hooks.<name>.<key>.command` is an entry's field; `hooks.<name>.command` is an entry.
|
|
46
|
+
const key = property.key.split('.').length === 4
|
|
47
|
+
? property.key.replace(/\.command$/, '')
|
|
48
|
+
: property.key;
|
|
49
|
+
commands.set(key, property);
|
|
50
|
+
}
|
|
51
|
+
for (const { key, roots } of unprotectedEntryPoints([...commands].map(([key, p]) => [key, String(p.value)]), readOnly.map((p) => String(p.value))))
|
|
52
|
+
problems.push({
|
|
53
|
+
key,
|
|
54
|
+
expected: `${key}: under an isolating runtime a host command starts with a script in a protected path (${roots.join(', ')})`,
|
|
55
|
+
remediation: `Move the command into a script under .bakers (or a runtime.read_only path) and call it with bash; see ${DOCS}.`,
|
|
56
|
+
property: commands.get(key),
|
|
57
|
+
});
|
|
58
|
+
return problems;
|
|
59
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The script a host command starts: its first word, or the word after `bash`, `sh` or `node`. */
|
|
2
|
+
export declare function hostCommandEntry(command: string): string | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* The `[key, command]` pairs whose entry point lies outside `.bakers` and
|
|
5
|
+
* `protectedPaths`, with the roots they were checked against. Only the entry
|
|
6
|
+
* is checked: what that script calls is the project's responsibility.
|
|
7
|
+
*/
|
|
8
|
+
export declare function unprotectedEntryPoints(commands: Iterable<readonly [key: string, command: string]>, protectedPaths: readonly string[]): {
|
|
9
|
+
key: string;
|
|
10
|
+
command: string;
|
|
11
|
+
roots: string[];
|
|
12
|
+
}[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Under an isolating runtime the host runs only code the run cannot write:
|
|
2
|
+
// every project hook and provision command must start in a protected path.
|
|
3
|
+
import { posix } from 'node:path';
|
|
4
|
+
const INTERPRETERS = new Set(['bash', 'sh', 'node']);
|
|
5
|
+
/** The script a host command starts: its first word, or the word after `bash`, `sh` or `node`. */
|
|
6
|
+
export function hostCommandEntry(command) {
|
|
7
|
+
const [first, second] = command
|
|
8
|
+
.trim()
|
|
9
|
+
.split(/[\s;&|]+/)
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
return first !== undefined && INTERPRETERS.has(first) ? second : first;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The `[key, command]` pairs whose entry point lies outside `.bakers` and
|
|
15
|
+
* `protectedPaths`, with the roots they were checked against. Only the entry
|
|
16
|
+
* is checked: what that script calls is the project's responsibility.
|
|
17
|
+
*/
|
|
18
|
+
export function unprotectedEntryPoints(commands, protectedPaths) {
|
|
19
|
+
const roots = ['.bakers', ...protectedPaths].map((path) => posix.normalize(path));
|
|
20
|
+
const found = [];
|
|
21
|
+
for (const [key, command] of commands) {
|
|
22
|
+
const entry = hostCommandEntry(command);
|
|
23
|
+
const path = entry === undefined ? undefined : posix.normalize(entry);
|
|
24
|
+
if (path === undefined ||
|
|
25
|
+
!roots.some((root) => path === root || path.startsWith(`${root}/`)))
|
|
26
|
+
found.push({ key, command, roots });
|
|
27
|
+
}
|
|
28
|
+
return found;
|
|
29
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type { ConnectionConfig, MachineConfig, ProjectConfig, } from './config-t
|
|
|
20
20
|
export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, type RootGitExec, } from './core/checkout-root.js';
|
|
21
21
|
export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
|
|
22
22
|
export { type GitSandboxPaths, gitSandboxPaths, withoutGitDirs, } from './core/git-sandbox.js';
|
|
23
|
+
export { hostCommandEntry, unprotectedEntryPoints, } from './core/host-commands.js';
|
|
23
24
|
export { changedProtectedPaths, refreshRunTarget, runCloneTip, transferIsolatedCommit, } from './core/isolated-git.js';
|
|
24
25
|
export { type ConductorLiveness, type ConductorLivenessInput, deriveConductorLiveness, toUnixSeconds, } from './core/liveness.js';
|
|
25
26
|
export { type ConductorLogger, createLogger } from './core/logger.js';
|
package/dist/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export { discoverBbWorkspaces, loadReadyBbConnection, resolveWorkspaceSelector,
|
|
|
21
21
|
export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, } from './core/checkout-root.js';
|
|
22
22
|
export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
|
|
23
23
|
export { gitSandboxPaths, withoutGitDirs, } from './core/git-sandbox.js';
|
|
24
|
+
export { hostCommandEntry, unprotectedEntryPoints, } from './core/host-commands.js';
|
|
24
25
|
export { changedProtectedPaths, refreshRunTarget, runCloneTip, transferIsolatedCommit, } from './core/isolated-git.js';
|
|
25
26
|
export { deriveConductorLiveness, toUnixSeconds, } from './core/liveness.js';
|
|
26
27
|
export { createLogger } from './core/logger.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/core",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1-next.1",
|
|
4
4
|
"description": "bakers.build surface-agnostic kernel: host contract, split-config helpers, addon preset/discovery machinery, shared primitives.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"yaml": "^2.7.0"
|
|
41
41
|
},
|
|
42
42
|
"bakersBuild": {
|
|
43
|
-
"commit": "
|
|
44
|
-
"channel": "
|
|
43
|
+
"commit": "e6b3d200ba14c56b2fb9d3695f273ea349a97f65",
|
|
44
|
+
"channel": "next"
|
|
45
45
|
}
|
|
46
46
|
}
|