Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

fix(vps): undo a half-done user switch and hand over only root files at start

Alan Buscaglia4d1035e50945
diff --git a/compose.yaml b/compose.yaml
index 48aa964..45d7fc5 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -21,9 +21,9 @@ services:
cap_add:
- SETUID # start the engine and connector servers as their users
- SETGID # with their own group and no supplementary groups
- - CHOWN # hand the files the daemon writes for the engine to the engine's user
- - FOWNER # keep the engine's folders private (chmod on folders the engine owns)
- - DAC_OVERRIDE # read and write the engine's folders (sessions, uploads, settings)
+ - CHOWN # at start, hand files an older image left owned by root to the engine's user
+ - FOWNER # at start, set the modes of folders the daemon does not own
+ - DAC_OVERRIDE # reach and watch the engine's private folders; their files are opened as the engine's user
- KILL # stop the engine and connector servers, which run as other users
volumes:
- dot-home:/home/dot
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index a54352f..04564d3 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -11,6 +11,6 @@ if [ "${GENTLE_DOT_VPS:-}" = "1" ]; then
chown root:root "$volume"
chmod 0755 "$volume"
mkdir -p "$GENTLE_DOT_ENGRAM_DATA_DIR"
- chown -R -P dot:dot "$GENTLE_DOT_ENGRAM_DATA_DIR"
+ chown -R -P --from=0:0 dot:dot "$GENTLE_DOT_ENGRAM_DATA_DIR"
fi
exec node /app/packages/daemon/src/cli.ts
diff --git a/docs/deploy-vps.md b/docs/deploy-vps.md
index 0c939e2..8227c6a 100644
--- a/docs/deploy-vps.md
+++ b/docs/deploy-vps.md
@@ -45,9 +45,9 @@ The image runs in server mode (`GENTLE_DOT_VPS=1`). The assistant has a shell, s
| Capability | Why the daemon needs it |
|---|---|
| `SETUID`, `SETGID` | Start the agent as `dot` and connector servers as `dotmcp`, without supplementary groups |
-| `CHOWN` | Give the agent the files the daemon writes for it (`mcp.json`, sign-ins, settings, uploads) |
-| `FOWNER` | Keep the agent's folders private (`chmod` on folders the agent owns) |
-| `DAC_OVERRIDE` | Read and write in the agent's folders: history, uploads, settings |
+| `CHOWN` | At start, hand the agent the files an older image left owned by root (`chown -R -P --from=0:0`) |
+| `FOWNER` | At start, set the modes of folders it does not own (`connector-home`, the agent's folders) |
+| `DAC_OVERRIDE` | Reach and watch the agent's private folders as root; their contents are opened only as `dot` |
| `KILL` | Stop the agent and connector servers, which run as other users |
## Steps
diff --git a/packages/daemon/src/daemon.ts b/packages/daemon/src/daemon.ts
index becf6d4..b740379 100644
--- a/packages/daemon/src/daemon.ts
+++ b/packages/daemon/src/daemon.ts
@@ -127,7 +127,7 @@ const CONTENT_TYPES: Record<string, string> = {
/**
* Reads the access token from `<dataDir>/token`, creating a random one when
- * absent. The data folder is kept at 0700 and the token at 0600.
+ * absent. The data folder is kept at 0700 (0711 in server mode, so the engine reaches its own folders by name) and the token at 0600.
*/
export function ensureToken(dataDir: string): string {
ensurePrivateDir(dataDir);
diff --git a/packages/daemon/src/engine-access.ts b/packages/daemon/src/engine-access.ts
index 60ee7a1..76f58be 100644
--- a/packages/daemon/src/engine-access.ts
+++ b/packages/daemon/src/engine-access.ts
@@ -57,11 +57,12 @@ export function engineAccess(user: OsUser, onFatal: (error: Error) => never = fa
}
const groups = process.getgroups?.() ?? [];
const egid = process.getegid?.() ?? 0;
- process.setgroups?.([user.gid]);
- process.setegid?.(user.gid);
- process.seteuid?.(user.uid);
depth++;
try {
+ // Inside the try, so a switch that fails halfway is undone like a finished one.
+ process.setgroups?.([user.gid]);
+ process.setegid?.(user.gid);
+ process.seteuid?.(user.uid);
return refuseAsync(fn());
} finally {
depth--;