shadok-ai 0.17.47 → 0.17.49

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.
@@ -123,6 +123,43 @@ export declare function rewriteCronCheckHome(check: string, oldHome: string, new
123
123
  * custom-named one — reintroducing the exact silent breakage this closes.
124
124
  */
125
125
  export declare const SHADOK_INTERNAL_DIRS: readonly string[];
126
+ /**
127
+ * Shadok's OWN credential and identity state under `~/.shadok-ai`, which the
128
+ * SERVER must keep OWNING across the commons chown. `migChownTreeToCommons` runs
129
+ * an unbounded `chown -R main:main ~/.shadok-ai` on purpose — the commons agent
130
+ * has to keep working on what it already worked on — but that sweeps the
131
+ * credential stores along with the working state, and "who may read this" is not
132
+ * the same question as "who owns this".
133
+ *
134
+ * Nothing LEAKS from it: the server's HOME stays 0700, so `main` cannot even
135
+ * traverse `/root` (the same wall that stranded the cron guards #419-#421 healed).
136
+ * What breaks is the SERVER's own use of its files, and the SSH identity is where
137
+ * that bites first: `~/.ssh` is a symlink to `~/.shadok-ai/ssh` (invariant 19,
138
+ * the only path that survives a container recreate), so once the key and its
139
+ * config belonged to `main`, every root-side `ssh` refused to run at all —
140
+ * `Bad owner or permissions on /root/.ssh/config`, because OpenSSH checks the
141
+ * OWNER of those files, not just their mode. Measured on the dogfood instance:
142
+ * `git` over SSH and every `ssh` to the host were dead while looking configured,
143
+ * and no merge noticed because `gh` speaks HTTPS.
144
+ *
145
+ * So this is re-asserted at EVERY capable boot rather than only right after the
146
+ * migration — an instance already migrated by an older build heals on its next
147
+ * update instead of needing a hand repair. Twin of `healCommonsStrandedScripts`.
148
+ *
149
+ * Every DIRECTORY here is also in `SHADOK_INTERNAL_DIRS`, the list that keeps the
150
+ * heal from COPYING it into a group HOME. The two halves answer the same question
151
+ * by different means — ownership in place, and relocation — so a test pins the
152
+ * pairing: otherwise they drift apart one entry at a time, and a credential store
153
+ * added to one list only would be half-protected in silence.
154
+ */
155
+ export declare const SERVER_OWNED_STATE: readonly string[];
156
+ /**
157
+ * Absolute paths of `SERVER_OWNED_STATE` under `home`. PURE: whether a path
158
+ * exists is the caller's business, so this needs no filesystem to test. A blank
159
+ * home yields nothing rather than paths rooted at `/.shadok-ai` — a chown there
160
+ * would be aimed at the wrong machine entirely.
161
+ */
162
+ export declare function serverOwnedStatePaths(home: string): string[];
126
163
  /**
127
164
  * The `~/.claude/<dir>` subtrees NEVER carried by the heal. `.credentials` is a
128
165
  * FILE, not a dir, so it can't match anyway — the real entries are the big
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  /**
2
3
  * Automatic migration of a running SINGLE-TENANT instance into isolated groups,
3
4
  * on the first boot of a CAPABLE (multi-tenant) instance. It is ADDITIVE: today
@@ -160,6 +161,62 @@ export const SHADOK_INTERNAL_DIRS = [
160
161
  "worktrees",
161
162
  "wt",
162
163
  ];
164
+ /**
165
+ * Shadok's OWN credential and identity state under `~/.shadok-ai`, which the
166
+ * SERVER must keep OWNING across the commons chown. `migChownTreeToCommons` runs
167
+ * an unbounded `chown -R main:main ~/.shadok-ai` on purpose — the commons agent
168
+ * has to keep working on what it already worked on — but that sweeps the
169
+ * credential stores along with the working state, and "who may read this" is not
170
+ * the same question as "who owns this".
171
+ *
172
+ * Nothing LEAKS from it: the server's HOME stays 0700, so `main` cannot even
173
+ * traverse `/root` (the same wall that stranded the cron guards #419-#421 healed).
174
+ * What breaks is the SERVER's own use of its files, and the SSH identity is where
175
+ * that bites first: `~/.ssh` is a symlink to `~/.shadok-ai/ssh` (invariant 19,
176
+ * the only path that survives a container recreate), so once the key and its
177
+ * config belonged to `main`, every root-side `ssh` refused to run at all —
178
+ * `Bad owner or permissions on /root/.ssh/config`, because OpenSSH checks the
179
+ * OWNER of those files, not just their mode. Measured on the dogfood instance:
180
+ * `git` over SSH and every `ssh` to the host were dead while looking configured,
181
+ * and no merge noticed because `gh` speaks HTTPS.
182
+ *
183
+ * So this is re-asserted at EVERY capable boot rather than only right after the
184
+ * migration — an instance already migrated by an older build heals on its next
185
+ * update instead of needing a hand repair. Twin of `healCommonsStrandedScripts`.
186
+ *
187
+ * Every DIRECTORY here is also in `SHADOK_INTERNAL_DIRS`, the list that keeps the
188
+ * heal from COPYING it into a group HOME. The two halves answer the same question
189
+ * by different means — ownership in place, and relocation — so a test pins the
190
+ * pairing: otherwise they drift apart one entry at a time, and a credential store
191
+ * added to one list only would be half-protected in silence.
192
+ */
193
+ export const SERVER_OWNED_STATE = [
194
+ // Stores (directories).
195
+ "ssh", // the persistent SSH identity; `~/.ssh` points here (invariant 19)
196
+ "users", // account hashes + the per-instance session-signing key (invariant 33)
197
+ "peers", // the inbound peer tokens this instance minted for other cockpits
198
+ "keys",
199
+ "secrets",
200
+ "tokens",
201
+ // Files.
202
+ "config.json", // the GUI password and the per-launch-dir Telegram tokens
203
+ "secrets.json", // the vault
204
+ "secret-origin.json",
205
+ "secret-audit.jsonl",
206
+ "profiles.json", // the GUARDRAILS, which an agent must never write (invariant 26)
207
+ "profiles-declined.json",
208
+ ];
209
+ /**
210
+ * Absolute paths of `SERVER_OWNED_STATE` under `home`. PURE: whether a path
211
+ * exists is the caller's business, so this needs no filesystem to test. A blank
212
+ * home yields nothing rather than paths rooted at `/.shadok-ai` — a chown there
213
+ * would be aimed at the wrong machine entirely.
214
+ */
215
+ export function serverOwnedStatePaths(home) {
216
+ if (!home)
217
+ return [];
218
+ return SERVER_OWNED_STATE.map((rel) => path.join(home, ".shadok-ai", rel));
219
+ }
163
220
  /**
164
221
  * The `~/.claude/<dir>` subtrees NEVER carried by the heal. `.credentials` is a
165
222
  * FILE, not a dir, so it can't match anyway — the real entries are the big
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-groups.js","sourceRoot":"","sources":["../src/migrate-groups.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;kDACkD;AAClD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AAEnC;;;;;;;;;;;;GAYG;AACH,MAAM,C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AAC,CAAC;IAC/G,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzC,MAAM,IAAI,CAAC,gCAAgC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;IACD,MAAM,IAAI,CAAC,uCAAuC,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAE/G,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,GAAG,CAAC,yFAAyF,CAAC,CAAC;QACjG,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,uCAAwC,CAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,iGAAiG,CAAC,CAAC;IACzG,CAAC;AACH,CAAC"}
package/dist/server.js CHANGED
@@ -34,7 +34,7 @@ import { readGroundAt } from "./ground.js";
34
34
  import { homeGreetingBrief } from "./greeting.js";
35
35
  import { ensureSshIdentity } from "./ssh.js";
36
36
  import { accountsEnabled, deploymentMode, probeCanProvision } from "./capability.js";
37
- import { migrationPlan, runMigration, respawnPlan, commonsOsUser, COMMONS_USER, MIGRATION_MARKER_FILE, rewriteCronCheckHome, strandedCheckDirs, } from "./migrate-groups.js";
37
+ import { migrationPlan, runMigration, respawnPlan, commonsOsUser, COMMONS_USER, MIGRATION_MARKER_FILE, rewriteCronCheckHome, strandedCheckDirs, serverOwnedStatePaths, } from "./migrate-groups.js";
38
38
  import { relayOAuthCallback } from "./oauth-relay.js";
39
39
  import { openBrowser } from "./open-browser.js";
40
40
  import { parseSkillMeta, prepromptParts, prepromptFingerprint, stalenessReasons, LEGACY_FINGERPRINT, } from "./preprompt.js";
@@ -3014,6 +3014,9 @@ async function ensureGroupsProvisioned() {
3014
3014
  // And heal the commons agent's own helper scripts + cron guards, which the HOME
3015
3015
  // move off /root left stranded (see below).
3016
3016
  await healCommonsStrandedScripts();
3017
+ // Then take back the ownership of the server's OWN credentials, which the
3018
+ // commons chown swept (see below) — the SSH identity first of all.
3019
+ await healServerOwnedState();
3017
3020
  }
3018
3021
  /**
3019
3022
  * Boot self-heal for the commons agent's OWN helper scripts and cron guards after
@@ -3113,6 +3116,68 @@ async function healCommonsStrandedScripts() {
3113
3116
  console.error(`heal: rewriting cron guard paths failed (best-effort): ${e?.message ?? e}`);
3114
3117
  }
3115
3118
  }
3119
+ /**
3120
+ * Boot self-heal, twin of `healCommonsStrandedScripts`: give the SERVER back the
3121
+ * ownership of its own credential and identity state, which the migration's
3122
+ * unbounded `chown -R main:main ~/.shadok-ai` swept along with the working state
3123
+ * (`SERVER_OWNED_STATE` carries the full reasoning and the measured symptom —
3124
+ * every root-side `ssh` dying on `Bad owner or permissions on /root/.ssh/config`,
3125
+ * because OpenSSH checks the OWNER of a key and a config, not only its mode).
3126
+ *
3127
+ * Runs on EVERY capable boot, independent of the migration marker, so an instance
3128
+ * already migrated by an older build heals on its next update. Idempotent and
3129
+ * cheap in the normal case: a few `lstat`s and NO privileged spawn once everything
3130
+ * is ours again — which is what makes it safe to run unconditionally.
3131
+ *
3132
+ * A directory is judged on itself AND its immediate entries, because a hand repair
3133
+ * typically re-owns the directory and leaves the key inside it foreign — the one
3134
+ * state in which `ssh` still refuses and the top-level check alone would call it
3135
+ * healed. Best-effort per path: a failure here must never take down the boot, and
3136
+ * it is reported rather than swallowed (a silent chown is indistinguishable from
3137
+ * one that never ran — the lesson of `src/claude-home.ts`).
3138
+ */
3139
+ async function healServerOwnedState() {
3140
+ if (DEPLOYMENT_MODE !== "multi-tenant")
3141
+ return;
3142
+ const uid = process.getuid?.() ?? 0;
3143
+ const gid = process.getgid?.() ?? 0;
3144
+ const owner = `${uid}:${gid}`;
3145
+ // Is anything under `p` owned by someone else? One level deep is enough: the
3146
+ // chown that causes this is `-R`, so a subtree moves as a whole, and a partial
3147
+ // tree is a hand repair, whose usual shape is "dir re-owned, contents not".
3148
+ const foreign = (p) => {
3149
+ try {
3150
+ if (fs.lstatSync(p).uid !== uid)
3151
+ return true;
3152
+ if (!fs.statSync(p).isDirectory())
3153
+ return false;
3154
+ for (const e of fs.readdirSync(p)) {
3155
+ try {
3156
+ if (fs.lstatSync(path.join(p, e)).uid !== uid)
3157
+ return true;
3158
+ }
3159
+ catch {
3160
+ /* raced away — nothing to re-own */
3161
+ }
3162
+ }
3163
+ return false;
3164
+ }
3165
+ catch {
3166
+ return false; // unreadable or gone: not ours to repair
3167
+ }
3168
+ };
3169
+ for (const p of serverOwnedStatePaths(os.homedir())) {
3170
+ if (!fs.existsSync(p) || !foreign(p))
3171
+ continue;
3172
+ try {
3173
+ await runPrivileged("chown", ["-R", owner, p], { timeoutMs: TREE_OP_TIMEOUT_MS });
3174
+ console.log(`heal: ${p} was owned by another user; given back to the server (${owner})`);
3175
+ }
3176
+ catch (e) {
3177
+ console.error(`heal: could not re-own ${p} (best-effort): ${e?.message ?? e}`);
3178
+ }
3179
+ }
3180
+ }
3116
3181
  /** Step 1 — create the non-root commons user `main` (+ HOME). Idempotent. */
3117
3182
  async function migCreateCommonsUser() {
3118
3183
  if (osUserExistsSync(COMMONS_USER))