Settings > Host directories adds a folder on the machine Cobble runs on (super admin), linked to computers or workspaces with read-write or read only access. A computer link shows at hosts/<name> in every bot's own folder, a workspace link at <name> in the workspace's shared folder on every computer the workspace is on, both inside computerRunDirs' roots. A link is all it takes: applyHostDirectoryGrant gives every bot that sees the folder an ACL entry of its own (never chown, chgrp or chmod), from a throwaway container of the computer's image. It runs on link, unlink, a source change, a bot joining, every sync-computers tick, and from Give access when it failed. Checks record what each account can do per computer; the permission command only appears when a check still says a bot can't write. Mounts exist only at container creation, so reconcileComputerHostDirectories reprovisions a computer whose metadata.host_mounts differ, skipping a busy one. Docker's Mounts array with CreateMountpoint: false means a missing source fails the setup instead of becoming a root-owned folder, and mount points under the run accounts are made by a throwaway root container when the app runs on the host as a plain user. The agent prunes every mount point from /proc/self/mountinfo in its shareFolder walk and measures the workspace with du -x, so a mounted host folder is never chowned or counted against the quota. Computer image is 1.4.4 and the workspace layout is cobble-computer-host-mounts.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
|
|
/**
|
|
* Mount point paths inside a folder, deepest irrelevant: a host folder is
|
|
* bind-mounted in a bot's folder (or a workspace's), and walking that
|
|
* folder must stop at it. `find -xdev` alone isn't enough, since the mount
|
|
* point directory itself still counts as visited and would be chowned or
|
|
* chmoded through the bind, changing the folder on the host machine.
|
|
*/
|
|
export default async function mountPointsUnder({ dir }: { dir: string }) {
|
|
const text = await readFile("/proc/self/mountinfo", "utf8").catch(() => "");
|
|
const prefix = dir.endsWith("/") ? dir : `${dir}/`;
|
|
|
|
return text.split("\n").flatMap((line) => {
|
|
const field = line.split(" ")[4];
|
|
const mount_point = unescape({ text: field || "" });
|
|
|
|
if (!mount_point.startsWith(prefix)) return [];
|
|
|
|
return [mount_point];
|
|
});
|
|
}
|
|
|
|
const Escapes: Record<string, string> = {
|
|
"040": " ",
|
|
"011": "\t",
|
|
"012": "\n",
|
|
"134": "\\",
|
|
};
|
|
|
|
/** mountinfo writes a path's spaces and friends octal-escaped. */
|
|
function unescape({ text }: { text: string }) {
|
|
return text.replace(/\\([0-7]{3})/g, (match, code: string) => Escapes[code] ?? match);
|
|
} |