Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): refuse a non-writable directory before the merge moves it
Alfredo Lopezd518ba67d183
diff --git a/docs/architecture/host-storage-layout.md b/docs/architecture/host-storage-layout.mdindex 8a9f228dc..2a1ec1435 100644--- a/docs/architecture/host-storage-layout.md+++ b/docs/architecture/host-storage-layout.md@@ -14,14 +14,14 @@ durability, as before #825: a stateless Host always writes withHCC renders the same storage for every Host Deployment(`host-context-controller/src/hostReconciler.ts`):-| Item | Value |-| --------------------- | ---------------------------------------------------------------------- |-| Volume mount | the PVC `<host>-workspace` root at `workspacePath`, no `subPath` |-| `workspacePath` | `/workspace`; `/config/workspace` for a `spec.desktop` Host |-| Conversation database | `<workspacePath>/state.db` (with `-wal` and `-shm`) |-| Store env | `CLERUM_SESSION_STORE=sqlite`, `CLERUM_SESSION_DB_DIR=<workspacePath>` |+| Item | Value |+| --------------------- | ------------------------------------------------------------------------------------------------ |+| Volume mount | the PVC `<host>-workspace` root at `workspacePath`, no `subPath` |+| `workspacePath` | `/workspace`; `/config/workspace` for a `spec.desktop` Host |+| Conversation database | `<workspacePath>/state.db` (with `-wal` and `-shm`) |+| Store env | `CLERUM_SESSION_STORE=sqlite`, `CLERUM_SESSION_DB_DIR=<workspacePath>` || Init container | `workspace-layout-merge`, while `CONTEXT_MAPPER_WORKSPACE_LAYOUT_MERGE` is enabled (the default) |-| Deployment strategy | `Recreate` |+| Deployment strategy | `Recreate` |`Recreate` stops the old Pod before the new one starts. A rolling update canrun both Pods on the same node at once, and a `ReadWriteOnce` PVC does not@@ -87,12 +87,12 @@ keep them; the database and its journals are already at the root.stderr and exits 1 before the first move, leaving the tree unchanged. The Podstays in `Init:Error`.-| Case | Line contains |-| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |+| Case | Line contains |+| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- || F1: `workspace` or the PVC root is a symlink, not a directory, or escapes the root; a real `state/` or a present `workspace/` cannot be listed and searched; a `state.db*` entry is a symlink or not a regular file; a directory that decides a collision cannot be listed | `directory is a symlink`, `is not a directory`, `escapes the workspace PVC root`, `state directory is not readable and searchable`, `workspace directory is not readable and searchable`, `SQLite file is a symlink`, `SQLite file is not a regular file`, `cannot list directory` |-| F2: more than one live database family across the root, `state/` and `workspace/` | `more than one live SQLite database` |-| F3: a name to move already exists at the root, or under both `state/` and `workspace/`; `workspace/lost+found` exists | `destination exists`, `exists under both state/ and workspace/`, `lost+found would remain` |-| F4: the PVC root, `state/` or `workspace/` is not writable by the container uid | `not writable by uid` |+| F2: more than one live database family across the root, `state/` and `workspace/` | `more than one live SQLite database` |+| F3: a name to move already exists at the root, or under both `state/` and `workspace/`; `workspace/lost+found` exists | `destination exists`, `exists under both state/ and workspace/`, `lost+found would remain` |+| F4: the PVC root, `state/`, `workspace/`, or a directory to be moved out of them is not writable by the container uid | `not writable by uid` |The PVC root checks of F1 run on every start, before the signature check.diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 657156c65..8aec35dbd 100644--- a/host-context-controller/package-lock.json+++ b/host-context-controller/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-host-context-controller",- "version": "0.1.391",+ "version": "0.1.392","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.391",+ "version": "0.1.392","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex 2a731c36a..dc81601d2 100644--- a/host-context-controller/package.json+++ b/host-context-controller/package.json@@ -1,6 +1,6 @@{"name": "clerum-host-context-controller",- "version": "0.1.391",+ "version": "0.1.392","description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API","main": "dist/main.js","engines": {diff --git a/host-context-controller/src/statelessDeployment.ts b/host-context-controller/src/statelessDeployment.tsindex 38b5a4bfd..0dc175ec0 100644--- a/host-context-controller/src/statelessDeployment.ts+++ b/host-context-controller/src/statelessDeployment.ts@@ -46,7 +46,8 @@ function shellSingleQuote(value: string): string {* F3 a name to move already exists at the root, or exists under both* `state/` and `workspace/` (an empty source directory is removed* instead), or `workspace/lost+found` would keep `workspace/` alive;- * F4 the root, `state/` or `workspace/` is not writable.+ * F4 the root, `state/`, `workspace/`, or a directory to be moved out of+ * them is not writable (renaming a directory rewrites its `..`).* Moves: `workspace/*`, then `state/*` except `state.db`, then* `state/state.db` last, so a stopped merge keeps the signature and the* next start finishes it. Symlinks are renamed, never followed. The script@@ -171,6 +172,14 @@ doneif [ "$workspace_present" -eq 1 ]; then[ -w "$root/workspace" ] || fail_merge "not writable by uid $(id -u): $root/workspace"fi+# Renaming a directory to a new parent rewrites its .. entry, which needs+# write permission on the directory itself.+for entry in "$root/workspace"/* "$root/workspace"/.[!.]* "$root/workspace"/..?* \\+ "$root/state"/* "$root/state"/.[!.]* "$root/state"/..?*; do+ [ -d "$entry" ] && [ ! -L "$entry" ] || continue+ ! present "$root/$(basename "$entry")" || continue+ [ -w "$entry" ] || fail_merge "not writable by uid $(id -u): $entry"+donemove_to_root() {entry="$1"diff --git a/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts b/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.tsindex bb1f4e809..97372642f 100644--- a/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts+++ b/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts@@ -398,6 +398,57 @@ describe('workspace layout merge', () => {expect(merge(root).stderr).toContain(`destination exists: ${root}/cache`)}, 15_000)+ // Renaming a directory to a new parent rewrites its `..` entry, so it needs+ // write permission on that directory. Without this check the merge would+ // stop part-way with `mv: Permission denied` on every start.+ it.each(['workspace', 'state'])(+ 'refuses before the first move when a directory under %s/ is not writable (F4)',+ source => {+ const root = splitRoot()+ const locked = join(root, source, 'readonly')+ mkdirSync(locked)+ writeFileSync(join(locked, 'entry'), 'kept')+ chmodSync(locked, 0o555)+ const before = snapshot(root)++ const refused = merge(root)++ expect(refused).toEqual({+ status: 1,+ stderr: `workspace layout merge refused: not writable by uid ${process.getuid!()}: ${locked}\n`,+ })+ expect(snapshot(root)).toEqual(before)+ // Witness: once writable, the same tree merges and the directory moves.+ chmodSync(locked, 0o755)+ expect(merge(root)).toEqual({ status: 0, stderr: '' })+ expect(readFileSync(join(root, 'readonly', 'entry'), 'utf8')).toBe('kept')+ expect(messageCount(join(root, 'state.db'))).toEqual({ rows: ROWS, check: 'ok' })+ },+ 15_000+ )++ // A directory moved whole is renamed, never listed: an unlistable one with a+ // free name moves intact. Refusing it would let an agent's chmod stop the Host.+ it.each(['workspace', 'state'])(+ 'moves an unlistable directory under %s/ whose name is free at the root',+ source => {+ const root = splitRoot()+ const hidden = join(root, source, 'hidden')+ mkdirSync(hidden)+ writeFileSync(join(hidden, 'entry'), 'kept')+ chmodSync(hidden, 0o333)++ const merged = merge(root)++ chmodSync(join(root, 'hidden'), 0o755)+ expect(merged).toEqual({ status: 0, stderr: '' })+ expect(readFileSync(join(root, 'hidden', 'entry'), 'utf8')).toBe('kept')+ expect(readdirSync(root)).not.toContain(source)+ expect(messageCount(join(root, 'state.db'))).toEqual({ rows: ROWS, check: 'ok' })+ },+ 15_000+ )+it('refuses a journal present both at the root and under state/ in a resumed merge', () => {const root = splitRoot()// A merge stopped after the journals moved, with a second copy of one.