shadok-ai 0.17.57 → 0.17.58
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/git-exec.d.ts +59 -0
- package/dist/git-exec.js +101 -0
- package/dist/git-exec.js.map +1 -0
- package/dist/selfrepo.js +12 -3
- package/dist/selfrepo.js.map +1 -1
- package/dist/worktree.js +18 -4
- package/dist/worktree.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ExecFileSyncOptionsWithStringEncoding } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Running git from the SERVER on a repository someone else owns.
|
|
4
|
+
*
|
|
5
|
+
* Under multi-tenant the server is root and the checkouts it manages belong to
|
|
6
|
+
* the drop users: the Tweak self-clone is chowned to `main`, an agent's worktree
|
|
7
|
+
* to its group user. git (≥ 2.35.2) refuses to operate in a repository owned by
|
|
8
|
+
* another user — "detected dubious ownership" — so the second click on *Tweak
|
|
9
|
+
* Shadok-AI* failed on the refresh of a clone the first click had created, and
|
|
10
|
+
* `isGitRepo` quietly answered `false` for the same directory (no worktree).
|
|
11
|
+
*
|
|
12
|
+
* The tempting fix is `-c safe.directory=<dir>`, and it is the wrong one. That
|
|
13
|
+
* check exists precisely so root never runs configuration planted by another
|
|
14
|
+
* user: a repo's `.git/config` can name `core.fsmonitor`, `core.sshCommand`, a
|
|
15
|
+
* checkout filter or a hook, each of which git EXECUTES. The directory is
|
|
16
|
+
* writable by an agent, so whitelisting it would hand any agent (or a prompt
|
|
17
|
+
* injection driving one) a command run as root — across the very wall the
|
|
18
|
+
* isolation builds. Instead the command is re-run AS THE REPO'S OWNER, which is
|
|
19
|
+
* what git's refusal is asking for: it then executes nothing its owner could not
|
|
20
|
+
* already execute.
|
|
21
|
+
*
|
|
22
|
+
* It is a FALLBACK on that one refusal, never the first attempt, so every
|
|
23
|
+
* invocation that works today — mono-tenant, a root-owned repo, a non-root
|
|
24
|
+
* server, an image that whitelists its workspace — runs exactly as before.
|
|
25
|
+
*/
|
|
26
|
+
/** Pure: is this a git "dubious ownership" refusal? */
|
|
27
|
+
export declare function isDubiousOwnership(e: unknown): boolean;
|
|
28
|
+
export interface Owner {
|
|
29
|
+
uid: number;
|
|
30
|
+
gid: number;
|
|
31
|
+
name: string | null;
|
|
32
|
+
home: string | null;
|
|
33
|
+
}
|
|
34
|
+
/** Pure: the passwd row for `uid` (name + home), or nulls when absent. */
|
|
35
|
+
export declare function passwdEntry(passwd: string, uid: number): {
|
|
36
|
+
name: string | null;
|
|
37
|
+
home: string | null;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Pure: the `setpriv` argv + env that run `git -C cwd …args` as `owner`. Numeric
|
|
41
|
+
* ids so a uid with no passwd row still works; `--init-groups` only when there is
|
|
42
|
+
* a name to read the groups of, else `--clear-groups` (never root's groups).
|
|
43
|
+
* HOME is the owner's: git reads `$HOME/.gitconfig`, and root's 0700 home is
|
|
44
|
+
* unreadable to them. With no home known, HOME points at the repo itself rather
|
|
45
|
+
* than staying `/root`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function ownerGitCommand(owner: Owner, cwd: string, args: readonly string[]): {
|
|
48
|
+
cmd: string;
|
|
49
|
+
argv: string[];
|
|
50
|
+
env: Record<string, string>;
|
|
51
|
+
};
|
|
52
|
+
/** Who owns `dir`, when the server is root and that is someone else; else null. */
|
|
53
|
+
export declare function foreignOwner(dir: string): Owner | null;
|
|
54
|
+
/**
|
|
55
|
+
* `git -C cwd …args`, retried as the repository's owner when git refuses it for
|
|
56
|
+
* dubious ownership (see above). Same return and throw contract as the plain
|
|
57
|
+
* `execFileSync` it replaces.
|
|
58
|
+
*/
|
|
59
|
+
export declare function gitIn(cwd: string, args: readonly string[], opts?: Omit<ExecFileSyncOptionsWithStringEncoding, "encoding">): string;
|
package/dist/git-exec.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
/**
|
|
4
|
+
* Running git from the SERVER on a repository someone else owns.
|
|
5
|
+
*
|
|
6
|
+
* Under multi-tenant the server is root and the checkouts it manages belong to
|
|
7
|
+
* the drop users: the Tweak self-clone is chowned to `main`, an agent's worktree
|
|
8
|
+
* to its group user. git (≥ 2.35.2) refuses to operate in a repository owned by
|
|
9
|
+
* another user — "detected dubious ownership" — so the second click on *Tweak
|
|
10
|
+
* Shadok-AI* failed on the refresh of a clone the first click had created, and
|
|
11
|
+
* `isGitRepo` quietly answered `false` for the same directory (no worktree).
|
|
12
|
+
*
|
|
13
|
+
* The tempting fix is `-c safe.directory=<dir>`, and it is the wrong one. That
|
|
14
|
+
* check exists precisely so root never runs configuration planted by another
|
|
15
|
+
* user: a repo's `.git/config` can name `core.fsmonitor`, `core.sshCommand`, a
|
|
16
|
+
* checkout filter or a hook, each of which git EXECUTES. The directory is
|
|
17
|
+
* writable by an agent, so whitelisting it would hand any agent (or a prompt
|
|
18
|
+
* injection driving one) a command run as root — across the very wall the
|
|
19
|
+
* isolation builds. Instead the command is re-run AS THE REPO'S OWNER, which is
|
|
20
|
+
* what git's refusal is asking for: it then executes nothing its owner could not
|
|
21
|
+
* already execute.
|
|
22
|
+
*
|
|
23
|
+
* It is a FALLBACK on that one refusal, never the first attempt, so every
|
|
24
|
+
* invocation that works today — mono-tenant, a root-owned repo, a non-root
|
|
25
|
+
* server, an image that whitelists its workspace — runs exactly as before.
|
|
26
|
+
*/
|
|
27
|
+
/** Pure: is this a git "dubious ownership" refusal? */
|
|
28
|
+
export function isDubiousOwnership(e) {
|
|
29
|
+
const err = e;
|
|
30
|
+
return /detected dubious ownership/i.test(String(err?.stderr ?? ""));
|
|
31
|
+
}
|
|
32
|
+
/** Pure: the passwd row for `uid` (name + home), or nulls when absent. */
|
|
33
|
+
export function passwdEntry(passwd, uid) {
|
|
34
|
+
for (const line of passwd.split("\n")) {
|
|
35
|
+
const f = line.split(":");
|
|
36
|
+
if (f.length >= 6 && Number(f[2]) === uid && f[2] !== "")
|
|
37
|
+
return { name: f[0] || null, home: f[5] || null };
|
|
38
|
+
}
|
|
39
|
+
return { name: null, home: null };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pure: the `setpriv` argv + env that run `git -C cwd …args` as `owner`. Numeric
|
|
43
|
+
* ids so a uid with no passwd row still works; `--init-groups` only when there is
|
|
44
|
+
* a name to read the groups of, else `--clear-groups` (never root's groups).
|
|
45
|
+
* HOME is the owner's: git reads `$HOME/.gitconfig`, and root's 0700 home is
|
|
46
|
+
* unreadable to them. With no home known, HOME points at the repo itself rather
|
|
47
|
+
* than staying `/root`.
|
|
48
|
+
*/
|
|
49
|
+
export function ownerGitCommand(owner, cwd, args) {
|
|
50
|
+
const groups = owner.name ? ["--init-groups"] : ["--clear-groups"];
|
|
51
|
+
const env = { HOME: owner.home ?? cwd };
|
|
52
|
+
if (owner.name)
|
|
53
|
+
Object.assign(env, { USER: owner.name, LOGNAME: owner.name });
|
|
54
|
+
return {
|
|
55
|
+
cmd: "setpriv",
|
|
56
|
+
argv: ["--reuid", String(owner.uid), "--regid", String(owner.gid), ...groups, "--", "git", "-C", cwd, ...args],
|
|
57
|
+
env,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Who owns `dir`, when the server is root and that is someone else; else null. */
|
|
61
|
+
export function foreignOwner(dir) {
|
|
62
|
+
if (typeof process.getuid !== "function" || process.getuid() !== 0)
|
|
63
|
+
return null;
|
|
64
|
+
let st;
|
|
65
|
+
try {
|
|
66
|
+
st = fs.statSync(dir);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (st.uid === 0)
|
|
72
|
+
return null;
|
|
73
|
+
let passwd = "";
|
|
74
|
+
try {
|
|
75
|
+
passwd = fs.readFileSync("/etc/passwd", "utf8");
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
/* no passwd: numeric ids only */
|
|
79
|
+
}
|
|
80
|
+
return { uid: st.uid, gid: st.gid, ...passwdEntry(passwd, st.uid) };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* `git -C cwd …args`, retried as the repository's owner when git refuses it for
|
|
84
|
+
* dubious ownership (see above). Same return and throw contract as the plain
|
|
85
|
+
* `execFileSync` it replaces.
|
|
86
|
+
*/
|
|
87
|
+
export function gitIn(cwd, args, opts = {}) {
|
|
88
|
+
try {
|
|
89
|
+
return execFileSync("git", ["-C", cwd, ...args], { ...opts, encoding: "utf8" });
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
if (!isDubiousOwnership(e))
|
|
93
|
+
throw e;
|
|
94
|
+
const owner = foreignOwner(cwd);
|
|
95
|
+
if (!owner)
|
|
96
|
+
throw e;
|
|
97
|
+
const run = ownerGitCommand(owner, cwd, args);
|
|
98
|
+
return execFileSync(run.cmd, run.argv, { ...opts, encoding: "utf8", env: { ...process.env, ...run.env } });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=git-exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-exec.js","sourceRoot":"","sources":["../src/git-exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8C,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,uDAAuD;AACvD,MAAM,UAAU,kBAAkB,CAAC,CAAU;IAC3C,MAAM,GAAG,GAAG,CAAwC,CAAC;IACrD,OAAO,6BAA6B,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;AACvE,CAAC;AASD,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,GAAW;IACrD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAA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EAAE,IAAI,CAAC,CAAC;QAC9C,OAAO,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7G,CAAC;AACH,CAAC"}
|
package/dist/selfrepo.js
CHANGED
|
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { gitIn } from "./git-exec.js";
|
|
5
6
|
/**
|
|
6
7
|
* A working copy of shadok-ai's own source, so a user who installed the cockpit
|
|
7
8
|
* with `npx shadok-ai` — no clone, no rights on the repo — can still have an
|
|
@@ -43,12 +44,20 @@ export function gitFailReason(e) {
|
|
|
43
44
|
return line ? line.slice(0, 120) : "git failed";
|
|
44
45
|
}
|
|
45
46
|
function git(args, cwd) {
|
|
46
|
-
|
|
47
|
-
encoding: "utf8",
|
|
47
|
+
const opts = {
|
|
48
48
|
// A cold clone over a slow link is minutes, not seconds.
|
|
49
49
|
timeout: 180_000,
|
|
50
50
|
stdio: ["ignore", "pipe", "pipe"],
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
|
+
// An existing clone is chowned to the commons drop user under multi-tenant, so
|
|
53
|
+
// the refresh goes through `gitIn`, which re-runs it as that owner when git
|
|
54
|
+
// refuses root for "dubious ownership" (src/git-exec.ts) — never by
|
|
55
|
+
// whitelisting the directory, which would let an agent's `.git/config` run
|
|
56
|
+
// commands as root.
|
|
57
|
+
if (cwd)
|
|
58
|
+
gitIn(cwd, args, opts);
|
|
59
|
+
else
|
|
60
|
+
execFileSync("git", args, { ...opts, encoding: "utf8" });
|
|
52
61
|
}
|
|
53
62
|
/**
|
|
54
63
|
* Makes sure the source checkout exists and its `main` matches the remote, so a
|
package/dist/selfrepo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selfrepo.js","sourceRoot":"","sources":["../src/selfrepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"selfrepo.js","sourceRoot":"","sources":["../src/selfrepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,4CAA4C,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,SAAS,GAAW,EAAE,CAAC,OAAO,EAAE;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC;AAID,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,MAAe,EAAE,MAAe;IAC3D,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,CAAU;IACtC,MAAM,GAAG,GAAG,CAAuD,CAAC;IACpE,IAAI,GAAG,EAAE,IAAI,KAAK,QAAQ;QAAE,OAAO,sBAAsB,CAAC;IAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,GA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AK,QAAQ,EAAE,CAAC;YACtB,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;YACzC,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;YAC/B,wEAAwE;YACxE,6DAA6D;YAC7D,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACrD,GAAG,CAAC,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IACrC,CAAC;AACH,CAAC"}
|
package/dist/worktree.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { listSessions } from "./extract.js";
|
|
5
|
+
import { foreignOwner, gitIn } from "./git-exec.js";
|
|
6
|
+
// Through `gitIn`: under multi-tenant the server is root and these checkouts
|
|
7
|
+
// belong to a drop user, which git refuses as "dubious ownership" (src/git-exec.ts).
|
|
6
8
|
function git(cwd, args) {
|
|
7
|
-
return
|
|
8
|
-
encoding: "utf8",
|
|
9
|
+
return gitIn(cwd, args, {
|
|
9
10
|
timeout: 15_000,
|
|
10
11
|
maxBuffer: 16 * 1024 * 1024,
|
|
11
12
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -70,7 +71,20 @@ export function createWorktree(repo, tag, stateHome = os.homedir()) {
|
|
|
70
71
|
const head = git(repo, ["rev-parse", "HEAD"]);
|
|
71
72
|
const branch = `shadok-ai/${tag}`;
|
|
72
73
|
const dir = worktreeDir(stateHome, repo, tag);
|
|
73
|
-
fs.mkdirSync(path.dirname(dir), { recursive: true });
|
|
74
|
+
const created = fs.mkdirSync(path.dirname(dir), { recursive: true });
|
|
75
|
+
// A repo another user owns is driven AS that user (`gitIn`), so the parent the
|
|
76
|
+
// root server just made must be theirs too, or `worktree add` dies on
|
|
77
|
+
// "could not create leading directories … Permission denied". Only what THIS
|
|
78
|
+
// call created, and only when the repo is not root's: a root-owned repo keeps
|
|
79
|
+
// today's path (the caller chowns the finished checkout).
|
|
80
|
+
const owner = created ? foreignOwner(repo) : null;
|
|
81
|
+
if (created && owner) {
|
|
82
|
+
for (let d = path.dirname(dir);; d = path.dirname(d)) {
|
|
83
|
+
fs.chownSync(d, owner.uid, owner.gid);
|
|
84
|
+
if (d === created || d === path.dirname(d))
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
74
88
|
git(repo, ["worktree", "add", "-b", branch, dir, head]);
|
|
75
89
|
return { path: dir, branch, repo };
|
|
76
90
|
}
|
package/dist/worktree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../src/worktree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../src/worktree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAWpD,6EAA6E;AAC7E,qFAAqF;AAC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