@codyswann/lisa 4.23.28 → 4.23.30
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/all/copy-overwrite/scripts/lib/process-tree-runner.mjs +16 -4
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +2 -0
- package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +25 -5
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +3 -3
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/envfile.mjs +2 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs +262 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-setup-remote-env/assets/session-start.sh +21 -10
- package/plugins/lisa/.codex-plugin/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +5 -1
- package/plugins/lisa/skills/lisa-secrets-access/scripts/envfile.mjs +2 -0
- package/plugins/lisa/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs +262 -0
- package/plugins/lisa/skills/lisa-setup-remote-env/assets/session-start.sh +21 -10
- package/plugins/lisa/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +5 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/envfile.mjs +2 -0
- package/plugins/lisa-agy/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs +262 -0
- package/plugins/lisa-agy/skills/lisa-setup-remote-env/assets/session-start.sh +21 -10
- package/plugins/lisa-agy/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +5 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/envfile.mjs +2 -0
- package/plugins/lisa-copilot/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs +262 -0
- package/plugins/lisa-copilot/skills/lisa-setup-remote-env/assets/session-start.sh +21 -10
- package/plugins/lisa-copilot/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +5 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/envfile.mjs +2 -0
- package/plugins/lisa-cursor/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs +262 -0
- package/plugins/lisa-cursor/skills/lisa-setup-remote-env/assets/session-start.sh +21 -10
- package/plugins/lisa-cursor/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +5 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/src/base/skills/lisa-secrets-access/scripts/envfile.mjs +2 -0
- package/plugins/src/base/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs +262 -0
- package/plugins/src/base/skills/lisa-setup-remote-env/assets/session-start.sh +21 -10
- package/plugins/src/base/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +5 -1
- package/scripts/lisa-remote-env/materialized-env-authority.mjs +262 -0
- package/scripts/lisa-remote-env/session-start.sh +21 -10
|
@@ -538,7 +538,11 @@ const PHASES = ["toolchain", "secrets", "hook"];
|
|
|
538
538
|
export const INSTALL_DIR = join("scripts", "lisa-remote-env");
|
|
539
539
|
|
|
540
540
|
/** Assets a host project needs on disk before any remote session can start. */
|
|
541
|
-
const INSTALLABLE = [
|
|
541
|
+
const INSTALLABLE = [
|
|
542
|
+
"setup.sh",
|
|
543
|
+
"session-start.sh",
|
|
544
|
+
"materialized-env-authority.mjs",
|
|
545
|
+
];
|
|
542
546
|
|
|
543
547
|
/**
|
|
544
548
|
* Copy this skill's assets into the host project that will run them.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fail-closed authority for Lisa's materialized remote environment.
|
|
4
|
+
*
|
|
5
|
+
* SessionStart sources secret-bearing shell text, so it must first prove that
|
|
6
|
+
* the path still has the exact type, mode, owner, and writer format Lisa owns.
|
|
7
|
+
* This asset is self-contained because a freshly cloned remote host has no
|
|
8
|
+
* plugin module graph yet.
|
|
9
|
+
* @module materialized-env-authority
|
|
10
|
+
*/
|
|
11
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
12
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
const HEADER = [
|
|
16
|
+
"# Generated by lisa-secrets-access. Contains secret values.",
|
|
17
|
+
"# Do not print, inspect, summarize, commit, or copy this file.",
|
|
18
|
+
];
|
|
19
|
+
const SAFE_NAMESPACE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
20
|
+
const EXPORT_LINE = /^export ([A-Za-z_]\w*)='(.*)'$/u;
|
|
21
|
+
const AUTHORITY_REFUSAL = 77;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decide whether both materialized filesystem objects belong to this user.
|
|
25
|
+
* @param {{directoryUid: number, expectedUid: number, fileUid: number}} facts
|
|
26
|
+
* Immutable owner identities.
|
|
27
|
+
* @returns {boolean} Whether both objects have the expected owner.
|
|
28
|
+
*/
|
|
29
|
+
export function materializedOwnersMatch(facts) {
|
|
30
|
+
return (
|
|
31
|
+
facts.directoryUid === facts.expectedUid &&
|
|
32
|
+
facts.fileUid === facts.expectedUid
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create the pure filesystem authority decision around one owner predicate.
|
|
38
|
+
* @param {(facts: object) => boolean} ownersMatch Owner authority.
|
|
39
|
+
* @returns {(facts: object) => {accepted: boolean, reason?: string}} Verdict.
|
|
40
|
+
*/
|
|
41
|
+
export function createMaterializedEnvAuthority(ownersMatch) {
|
|
42
|
+
return facts => {
|
|
43
|
+
if (facts.directoryType === "symlink" || facts.fileType === "symlink") {
|
|
44
|
+
return { accepted: false, reason: "materialized environment symlink" };
|
|
45
|
+
}
|
|
46
|
+
if (facts.directoryType !== "directory") {
|
|
47
|
+
return {
|
|
48
|
+
accepted: false,
|
|
49
|
+
reason: "materialized environment directory type mismatch",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (facts.fileType !== "file") {
|
|
53
|
+
return {
|
|
54
|
+
accepted: false,
|
|
55
|
+
reason: "materialized environment regular file type mismatch",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (facts.directoryMode !== 0o700) {
|
|
59
|
+
return {
|
|
60
|
+
accepted: false,
|
|
61
|
+
reason: "materialized environment directory mode is not 0700",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (facts.fileMode !== 0o600) {
|
|
65
|
+
return {
|
|
66
|
+
accepted: false,
|
|
67
|
+
reason: "materialized environment file mode is not 0600",
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (!ownersMatch(facts.ownership)) {
|
|
71
|
+
return {
|
|
72
|
+
accepted: false,
|
|
73
|
+
reason: "materialized environment file ownership mismatch",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { accepted: true };
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const validateMaterializedEnvAuthority = createMaterializedEnvAuthority(
|
|
81
|
+
materializedOwnersMatch
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Identify one lstat result without following a symbolic link.
|
|
86
|
+
* @param {import("node:fs").Stats} stat Immutable lstat observation.
|
|
87
|
+
* @returns {"symlink" | "directory" | "file" | "other"} Object kind.
|
|
88
|
+
*/
|
|
89
|
+
function statType(stat) {
|
|
90
|
+
if (stat.isSymbolicLink()) return "symlink";
|
|
91
|
+
if (stat.isDirectory()) return "directory";
|
|
92
|
+
if (stat.isFile()) return "file";
|
|
93
|
+
return "other";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Capture the complete immutable authority decision before reading bytes.
|
|
98
|
+
* @param {string} valuesFile Absolute materialized artifact path.
|
|
99
|
+
* @param {object} dependencies Injected filesystem and identity boundary.
|
|
100
|
+
* @returns {Readonly<object>} Frozen authority facts.
|
|
101
|
+
*/
|
|
102
|
+
function authorityFacts(valuesFile, dependencies) {
|
|
103
|
+
const expectedUid = dependencies.getuid();
|
|
104
|
+
const directory = dependencies.lstat(dirname(valuesFile));
|
|
105
|
+
const file = dependencies.lstat(valuesFile);
|
|
106
|
+
const ownership = Object.freeze({
|
|
107
|
+
directoryUid: directory.uid,
|
|
108
|
+
expectedUid,
|
|
109
|
+
fileUid: file.uid,
|
|
110
|
+
});
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
directoryMode: directory.mode & 0o777,
|
|
113
|
+
directoryType: statType(directory),
|
|
114
|
+
directoryUid: directory.uid,
|
|
115
|
+
expectedUid,
|
|
116
|
+
fileMode: file.mode & 0o777,
|
|
117
|
+
fileType: statType(file),
|
|
118
|
+
fileUid: file.uid,
|
|
119
|
+
ownership,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Prove text is exactly the sorted, newline-terminated Lisa writer format.
|
|
125
|
+
* @param {string} text Candidate shell artifact content.
|
|
126
|
+
* @returns {boolean} Whether the complete artifact matches the writer format.
|
|
127
|
+
*/
|
|
128
|
+
function materializedFormatValid(text) {
|
|
129
|
+
if (typeof text !== "string" || !text.endsWith("\n")) return false;
|
|
130
|
+
const lines = text.split("\n");
|
|
131
|
+
lines.pop();
|
|
132
|
+
if (lines[0] !== HEADER[0] || lines[1] !== HEADER[1]) return false;
|
|
133
|
+
const names = [];
|
|
134
|
+
for (const line of lines.slice(2)) {
|
|
135
|
+
const match = EXPORT_LINE.exec(line);
|
|
136
|
+
if (!match || match[2].replaceAll("'\\''", "").includes("'")) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
names.push(match[1]);
|
|
140
|
+
}
|
|
141
|
+
return names.every((name, index) => index === 0 || names[index - 1] < name);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Read the configured safe namespace and resolve its exact values artifact.
|
|
146
|
+
* @param {string} configFile Absolute project configuration path.
|
|
147
|
+
* @param {string} configRoot Absolute per-user configuration root.
|
|
148
|
+
* @param {object} dependencies Injected filesystem boundary.
|
|
149
|
+
* @returns {string} Absolute materialized values path.
|
|
150
|
+
*/
|
|
151
|
+
function valuesFileFromConfig(configFile, configRoot, dependencies) {
|
|
152
|
+
let config = {};
|
|
153
|
+
try {
|
|
154
|
+
config = JSON.parse(dependencies.readFile(configFile, "utf8"));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error?.code !== "ENOENT") throw new Error("configuration is invalid");
|
|
157
|
+
}
|
|
158
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
159
|
+
throw new Error("configuration is invalid");
|
|
160
|
+
}
|
|
161
|
+
const secrets = config.secrets ?? {};
|
|
162
|
+
if (!secrets || typeof secrets !== "object" || Array.isArray(secrets)) {
|
|
163
|
+
throw new Error("configuration secrets are invalid");
|
|
164
|
+
}
|
|
165
|
+
const namespace = secrets.namespace ?? "lisa";
|
|
166
|
+
if (
|
|
167
|
+
typeof namespace !== "string" ||
|
|
168
|
+
namespace === ".." ||
|
|
169
|
+
!SAFE_NAMESPACE.test(namespace)
|
|
170
|
+
) {
|
|
171
|
+
throw new Error("unsafe materialized environment namespace");
|
|
172
|
+
}
|
|
173
|
+
if (!isAbsolute(configRoot)) {
|
|
174
|
+
throw new Error("materialized environment config root is not absolute");
|
|
175
|
+
}
|
|
176
|
+
return join(configRoot, namespace, "secrets.env");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Convert a caught failure into a bounded, value-free reason.
|
|
181
|
+
* @param {unknown} error Refusal caught at the CLI boundary.
|
|
182
|
+
* @returns {string} Public diagnostic reason without artifact content.
|
|
183
|
+
*/
|
|
184
|
+
function refusalReason(error) {
|
|
185
|
+
if (error?.code === "ENOENT") return "file is missing";
|
|
186
|
+
if (error?.code === "EACCES") return "file is unreadable";
|
|
187
|
+
if (error instanceof Error && error.message.startsWith("materialized ")) {
|
|
188
|
+
return error.message;
|
|
189
|
+
}
|
|
190
|
+
if (error instanceof Error && error.message.startsWith("unsafe ")) {
|
|
191
|
+
return error.message;
|
|
192
|
+
}
|
|
193
|
+
if (error instanceof Error && error.message.startsWith("configuration ")) {
|
|
194
|
+
return error.message;
|
|
195
|
+
}
|
|
196
|
+
return "authority check failed";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Default synchronous boundary; injection is reserved for executable tests. */
|
|
200
|
+
const DEFAULT_DEPENDENCIES = Object.freeze({
|
|
201
|
+
getuid: () => (typeof process.getuid === "function" ? process.getuid() : -1),
|
|
202
|
+
lstat: lstatSync,
|
|
203
|
+
readFile: readFileSync,
|
|
204
|
+
writeError: diagnostic => process.stderr.write(diagnostic),
|
|
205
|
+
writeOutput: output => process.stdout.write(output),
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Validate one materialized file, or resolve it from the project config.
|
|
210
|
+
* @param {readonly string[]} argv Direct file or `--resolve` arguments.
|
|
211
|
+
* @param {object} [injected] Test-owned filesystem and diagnostic boundary.
|
|
212
|
+
* @returns {number} Zero only after complete authority and format validation.
|
|
213
|
+
*/
|
|
214
|
+
export function runMaterializedEnvAuthorityCli(argv, injected = {}) {
|
|
215
|
+
const dependencies = { ...DEFAULT_DEPENDENCIES, ...injected };
|
|
216
|
+
try {
|
|
217
|
+
const resolving = argv[0] === "--resolve";
|
|
218
|
+
if ((!resolving && argv.length !== 1) || (resolving && argv.length !== 3)) {
|
|
219
|
+
throw new Error("materialized environment arguments are invalid");
|
|
220
|
+
}
|
|
221
|
+
const valuesFile = resolving
|
|
222
|
+
? valuesFileFromConfig(argv[1], argv[2], dependencies)
|
|
223
|
+
: argv[0];
|
|
224
|
+
if (!isAbsolute(valuesFile)) {
|
|
225
|
+
throw new Error("materialized environment path is not absolute");
|
|
226
|
+
}
|
|
227
|
+
const facts = authorityFacts(valuesFile, dependencies);
|
|
228
|
+
const decision = validateMaterializedEnvAuthority(facts);
|
|
229
|
+
if (!decision.accepted) throw new Error(decision.reason);
|
|
230
|
+
const text = dependencies.readFile(valuesFile, "utf8");
|
|
231
|
+
if (!materializedFormatValid(text)) {
|
|
232
|
+
throw new Error("materialized environment format is invalid");
|
|
233
|
+
}
|
|
234
|
+
if (resolving) dependencies.writeOutput(`${valuesFile}\n`);
|
|
235
|
+
return 0;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
const reason = refusalReason(error);
|
|
238
|
+
dependencies.writeError(`Lisa materialized environment ${reason}\n`);
|
|
239
|
+
return AUTHORITY_REFUSAL;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Decide whether this module is the process entrypoint.
|
|
245
|
+
* @param {string} moduleUrl Current module URL.
|
|
246
|
+
* @param {string | undefined} argv1 Invoked script path, when present.
|
|
247
|
+
* @returns {boolean} Whether the CLI driver must run.
|
|
248
|
+
*/
|
|
249
|
+
function invokedAsScript(moduleUrl, argv1 = process.argv[1]) {
|
|
250
|
+
if (!argv1) return false;
|
|
251
|
+
try {
|
|
252
|
+
return (
|
|
253
|
+
realpathSync(resolve(argv1)) === realpathSync(fileURLToPath(moduleUrl))
|
|
254
|
+
);
|
|
255
|
+
} catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (invokedAsScript(import.meta.url)) {
|
|
261
|
+
process.exitCode = runMaterializedEnvAuthorityCli(process.argv.slice(2));
|
|
262
|
+
}
|
|
@@ -57,15 +57,26 @@ esac
|
|
|
57
57
|
|
|
58
58
|
bash "${here}/setup.sh" --phase=secrets "$@"
|
|
59
59
|
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
# Validate the exact Lisa-owned secrets.env before sourcing any bytes. The
|
|
61
|
+
# profile is unrelated host startup code and may return before Lisa's managed
|
|
62
|
+
# block, mutate the environment, or run arbitrary user commands. The authority
|
|
63
|
+
# process resolves the same configured namespace as the materializer and emits
|
|
64
|
+
# only the fully validated absolute artifact path.
|
|
65
|
+
project_root="$(CDPATH='' cd -- "${here}/../.." && pwd)"
|
|
66
|
+
config_root="${XDG_CONFIG_HOME:-$HOME/.config}"
|
|
67
|
+
values_file="$(
|
|
68
|
+
node "${here}/materialized-env-authority.mjs" \
|
|
69
|
+
--resolve "${project_root}/.lisa.config.json" "${config_root}"
|
|
70
|
+
)"
|
|
71
|
+
|
|
72
|
+
# Match the managed block's AWS poison removal, then export the artifact's
|
|
73
|
+
# values only for this session-start process and its project-hook child.
|
|
74
|
+
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
|
|
75
|
+
set -a
|
|
76
|
+
# The authority process proved this exact path and its complete writer format.
|
|
77
|
+
# shellcheck disable=SC1090
|
|
78
|
+
. "${values_file}"
|
|
79
|
+
set +a
|
|
69
80
|
|
|
70
81
|
# A project hook is part of the remote toolchain contract too. It covers tools
|
|
71
82
|
# that cannot be expressed by the pinned manifest, so skipping it on a cached
|
|
@@ -73,4 +84,4 @@ fi
|
|
|
73
84
|
# Run it last, matching the full setup order, and exec so its failure becomes
|
|
74
85
|
# the SessionStart result the host can surface. SessionStart remains fail-open;
|
|
75
86
|
# this reports an incomplete bootstrap but does not block the agent session.
|
|
76
|
-
exec bash "${here}/setup.sh" --phase=hook "$@"
|
|
87
|
+
exec /bin/bash "${here}/setup.sh" --phase=hook "$@"
|
|
@@ -538,7 +538,11 @@ const PHASES = ["toolchain", "secrets", "hook"];
|
|
|
538
538
|
export const INSTALL_DIR = join("scripts", "lisa-remote-env");
|
|
539
539
|
|
|
540
540
|
/** Assets a host project needs on disk before any remote session can start. */
|
|
541
|
-
const INSTALLABLE = [
|
|
541
|
+
const INSTALLABLE = [
|
|
542
|
+
"setup.sh",
|
|
543
|
+
"session-start.sh",
|
|
544
|
+
"materialized-env-authority.mjs",
|
|
545
|
+
];
|
|
542
546
|
|
|
543
547
|
/**
|
|
544
548
|
* Copy this skill's assets into the host project that will run them.
|
package/plugins/lisa-copilot/skills/lisa-setup-remote-env/assets/materialized-env-authority.mjs
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fail-closed authority for Lisa's materialized remote environment.
|
|
4
|
+
*
|
|
5
|
+
* SessionStart sources secret-bearing shell text, so it must first prove that
|
|
6
|
+
* the path still has the exact type, mode, owner, and writer format Lisa owns.
|
|
7
|
+
* This asset is self-contained because a freshly cloned remote host has no
|
|
8
|
+
* plugin module graph yet.
|
|
9
|
+
* @module materialized-env-authority
|
|
10
|
+
*/
|
|
11
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
12
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
const HEADER = [
|
|
16
|
+
"# Generated by lisa-secrets-access. Contains secret values.",
|
|
17
|
+
"# Do not print, inspect, summarize, commit, or copy this file.",
|
|
18
|
+
];
|
|
19
|
+
const SAFE_NAMESPACE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
20
|
+
const EXPORT_LINE = /^export ([A-Za-z_]\w*)='(.*)'$/u;
|
|
21
|
+
const AUTHORITY_REFUSAL = 77;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decide whether both materialized filesystem objects belong to this user.
|
|
25
|
+
* @param {{directoryUid: number, expectedUid: number, fileUid: number}} facts
|
|
26
|
+
* Immutable owner identities.
|
|
27
|
+
* @returns {boolean} Whether both objects have the expected owner.
|
|
28
|
+
*/
|
|
29
|
+
export function materializedOwnersMatch(facts) {
|
|
30
|
+
return (
|
|
31
|
+
facts.directoryUid === facts.expectedUid &&
|
|
32
|
+
facts.fileUid === facts.expectedUid
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create the pure filesystem authority decision around one owner predicate.
|
|
38
|
+
* @param {(facts: object) => boolean} ownersMatch Owner authority.
|
|
39
|
+
* @returns {(facts: object) => {accepted: boolean, reason?: string}} Verdict.
|
|
40
|
+
*/
|
|
41
|
+
export function createMaterializedEnvAuthority(ownersMatch) {
|
|
42
|
+
return facts => {
|
|
43
|
+
if (facts.directoryType === "symlink" || facts.fileType === "symlink") {
|
|
44
|
+
return { accepted: false, reason: "materialized environment symlink" };
|
|
45
|
+
}
|
|
46
|
+
if (facts.directoryType !== "directory") {
|
|
47
|
+
return {
|
|
48
|
+
accepted: false,
|
|
49
|
+
reason: "materialized environment directory type mismatch",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (facts.fileType !== "file") {
|
|
53
|
+
return {
|
|
54
|
+
accepted: false,
|
|
55
|
+
reason: "materialized environment regular file type mismatch",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (facts.directoryMode !== 0o700) {
|
|
59
|
+
return {
|
|
60
|
+
accepted: false,
|
|
61
|
+
reason: "materialized environment directory mode is not 0700",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (facts.fileMode !== 0o600) {
|
|
65
|
+
return {
|
|
66
|
+
accepted: false,
|
|
67
|
+
reason: "materialized environment file mode is not 0600",
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (!ownersMatch(facts.ownership)) {
|
|
71
|
+
return {
|
|
72
|
+
accepted: false,
|
|
73
|
+
reason: "materialized environment file ownership mismatch",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { accepted: true };
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const validateMaterializedEnvAuthority = createMaterializedEnvAuthority(
|
|
81
|
+
materializedOwnersMatch
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Identify one lstat result without following a symbolic link.
|
|
86
|
+
* @param {import("node:fs").Stats} stat Immutable lstat observation.
|
|
87
|
+
* @returns {"symlink" | "directory" | "file" | "other"} Object kind.
|
|
88
|
+
*/
|
|
89
|
+
function statType(stat) {
|
|
90
|
+
if (stat.isSymbolicLink()) return "symlink";
|
|
91
|
+
if (stat.isDirectory()) return "directory";
|
|
92
|
+
if (stat.isFile()) return "file";
|
|
93
|
+
return "other";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Capture the complete immutable authority decision before reading bytes.
|
|
98
|
+
* @param {string} valuesFile Absolute materialized artifact path.
|
|
99
|
+
* @param {object} dependencies Injected filesystem and identity boundary.
|
|
100
|
+
* @returns {Readonly<object>} Frozen authority facts.
|
|
101
|
+
*/
|
|
102
|
+
function authorityFacts(valuesFile, dependencies) {
|
|
103
|
+
const expectedUid = dependencies.getuid();
|
|
104
|
+
const directory = dependencies.lstat(dirname(valuesFile));
|
|
105
|
+
const file = dependencies.lstat(valuesFile);
|
|
106
|
+
const ownership = Object.freeze({
|
|
107
|
+
directoryUid: directory.uid,
|
|
108
|
+
expectedUid,
|
|
109
|
+
fileUid: file.uid,
|
|
110
|
+
});
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
directoryMode: directory.mode & 0o777,
|
|
113
|
+
directoryType: statType(directory),
|
|
114
|
+
directoryUid: directory.uid,
|
|
115
|
+
expectedUid,
|
|
116
|
+
fileMode: file.mode & 0o777,
|
|
117
|
+
fileType: statType(file),
|
|
118
|
+
fileUid: file.uid,
|
|
119
|
+
ownership,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Prove text is exactly the sorted, newline-terminated Lisa writer format.
|
|
125
|
+
* @param {string} text Candidate shell artifact content.
|
|
126
|
+
* @returns {boolean} Whether the complete artifact matches the writer format.
|
|
127
|
+
*/
|
|
128
|
+
function materializedFormatValid(text) {
|
|
129
|
+
if (typeof text !== "string" || !text.endsWith("\n")) return false;
|
|
130
|
+
const lines = text.split("\n");
|
|
131
|
+
lines.pop();
|
|
132
|
+
if (lines[0] !== HEADER[0] || lines[1] !== HEADER[1]) return false;
|
|
133
|
+
const names = [];
|
|
134
|
+
for (const line of lines.slice(2)) {
|
|
135
|
+
const match = EXPORT_LINE.exec(line);
|
|
136
|
+
if (!match || match[2].replaceAll("'\\''", "").includes("'")) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
names.push(match[1]);
|
|
140
|
+
}
|
|
141
|
+
return names.every((name, index) => index === 0 || names[index - 1] < name);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Read the configured safe namespace and resolve its exact values artifact.
|
|
146
|
+
* @param {string} configFile Absolute project configuration path.
|
|
147
|
+
* @param {string} configRoot Absolute per-user configuration root.
|
|
148
|
+
* @param {object} dependencies Injected filesystem boundary.
|
|
149
|
+
* @returns {string} Absolute materialized values path.
|
|
150
|
+
*/
|
|
151
|
+
function valuesFileFromConfig(configFile, configRoot, dependencies) {
|
|
152
|
+
let config = {};
|
|
153
|
+
try {
|
|
154
|
+
config = JSON.parse(dependencies.readFile(configFile, "utf8"));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error?.code !== "ENOENT") throw new Error("configuration is invalid");
|
|
157
|
+
}
|
|
158
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
159
|
+
throw new Error("configuration is invalid");
|
|
160
|
+
}
|
|
161
|
+
const secrets = config.secrets ?? {};
|
|
162
|
+
if (!secrets || typeof secrets !== "object" || Array.isArray(secrets)) {
|
|
163
|
+
throw new Error("configuration secrets are invalid");
|
|
164
|
+
}
|
|
165
|
+
const namespace = secrets.namespace ?? "lisa";
|
|
166
|
+
if (
|
|
167
|
+
typeof namespace !== "string" ||
|
|
168
|
+
namespace === ".." ||
|
|
169
|
+
!SAFE_NAMESPACE.test(namespace)
|
|
170
|
+
) {
|
|
171
|
+
throw new Error("unsafe materialized environment namespace");
|
|
172
|
+
}
|
|
173
|
+
if (!isAbsolute(configRoot)) {
|
|
174
|
+
throw new Error("materialized environment config root is not absolute");
|
|
175
|
+
}
|
|
176
|
+
return join(configRoot, namespace, "secrets.env");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Convert a caught failure into a bounded, value-free reason.
|
|
181
|
+
* @param {unknown} error Refusal caught at the CLI boundary.
|
|
182
|
+
* @returns {string} Public diagnostic reason without artifact content.
|
|
183
|
+
*/
|
|
184
|
+
function refusalReason(error) {
|
|
185
|
+
if (error?.code === "ENOENT") return "file is missing";
|
|
186
|
+
if (error?.code === "EACCES") return "file is unreadable";
|
|
187
|
+
if (error instanceof Error && error.message.startsWith("materialized ")) {
|
|
188
|
+
return error.message;
|
|
189
|
+
}
|
|
190
|
+
if (error instanceof Error && error.message.startsWith("unsafe ")) {
|
|
191
|
+
return error.message;
|
|
192
|
+
}
|
|
193
|
+
if (error instanceof Error && error.message.startsWith("configuration ")) {
|
|
194
|
+
return error.message;
|
|
195
|
+
}
|
|
196
|
+
return "authority check failed";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Default synchronous boundary; injection is reserved for executable tests. */
|
|
200
|
+
const DEFAULT_DEPENDENCIES = Object.freeze({
|
|
201
|
+
getuid: () => (typeof process.getuid === "function" ? process.getuid() : -1),
|
|
202
|
+
lstat: lstatSync,
|
|
203
|
+
readFile: readFileSync,
|
|
204
|
+
writeError: diagnostic => process.stderr.write(diagnostic),
|
|
205
|
+
writeOutput: output => process.stdout.write(output),
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Validate one materialized file, or resolve it from the project config.
|
|
210
|
+
* @param {readonly string[]} argv Direct file or `--resolve` arguments.
|
|
211
|
+
* @param {object} [injected] Test-owned filesystem and diagnostic boundary.
|
|
212
|
+
* @returns {number} Zero only after complete authority and format validation.
|
|
213
|
+
*/
|
|
214
|
+
export function runMaterializedEnvAuthorityCli(argv, injected = {}) {
|
|
215
|
+
const dependencies = { ...DEFAULT_DEPENDENCIES, ...injected };
|
|
216
|
+
try {
|
|
217
|
+
const resolving = argv[0] === "--resolve";
|
|
218
|
+
if ((!resolving && argv.length !== 1) || (resolving && argv.length !== 3)) {
|
|
219
|
+
throw new Error("materialized environment arguments are invalid");
|
|
220
|
+
}
|
|
221
|
+
const valuesFile = resolving
|
|
222
|
+
? valuesFileFromConfig(argv[1], argv[2], dependencies)
|
|
223
|
+
: argv[0];
|
|
224
|
+
if (!isAbsolute(valuesFile)) {
|
|
225
|
+
throw new Error("materialized environment path is not absolute");
|
|
226
|
+
}
|
|
227
|
+
const facts = authorityFacts(valuesFile, dependencies);
|
|
228
|
+
const decision = validateMaterializedEnvAuthority(facts);
|
|
229
|
+
if (!decision.accepted) throw new Error(decision.reason);
|
|
230
|
+
const text = dependencies.readFile(valuesFile, "utf8");
|
|
231
|
+
if (!materializedFormatValid(text)) {
|
|
232
|
+
throw new Error("materialized environment format is invalid");
|
|
233
|
+
}
|
|
234
|
+
if (resolving) dependencies.writeOutput(`${valuesFile}\n`);
|
|
235
|
+
return 0;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
const reason = refusalReason(error);
|
|
238
|
+
dependencies.writeError(`Lisa materialized environment ${reason}\n`);
|
|
239
|
+
return AUTHORITY_REFUSAL;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Decide whether this module is the process entrypoint.
|
|
245
|
+
* @param {string} moduleUrl Current module URL.
|
|
246
|
+
* @param {string | undefined} argv1 Invoked script path, when present.
|
|
247
|
+
* @returns {boolean} Whether the CLI driver must run.
|
|
248
|
+
*/
|
|
249
|
+
function invokedAsScript(moduleUrl, argv1 = process.argv[1]) {
|
|
250
|
+
if (!argv1) return false;
|
|
251
|
+
try {
|
|
252
|
+
return (
|
|
253
|
+
realpathSync(resolve(argv1)) === realpathSync(fileURLToPath(moduleUrl))
|
|
254
|
+
);
|
|
255
|
+
} catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (invokedAsScript(import.meta.url)) {
|
|
261
|
+
process.exitCode = runMaterializedEnvAuthorityCli(process.argv.slice(2));
|
|
262
|
+
}
|