Skip to main content

Module private

Module private 

Source
Expand description

Directories and files that nobody else on this machine can read.

data/ holds the database (chat history, the proxy’s API key, the environment variables given to MCP servers) beside the endpoint identity and the device keys. A build made in a checkout resolves it inside the repository, which other accounts on the machine can often reach, so data/ is 0700 and the database in it 0600, each from the moment it exists.

Creating is strict; tightening is best effort. A mode asked of mkdir or open costs nothing a plain create did not, so these fail exactly when one would. Tightening what is already there, which an older build left or this crate’s build.rs made in a checkout, is a chmod afterwards, and a filesystem with no Unix modes refuses that for every file. So a tightening that fails is logged rather than returned: a gglib that would not start there would protect nothing.

Functions§

create_dir 🔒
mkdir asked for 0700. The mode applies to every directory this creates, parents included, and to none that already exist.
create_file 🔒
open asked for 0600, and only if nothing is there: create_new is what makes truncating an existing file impossible here.
create_private_dir
Create dir and any parents it lacks 0700, and take group and other’s access away from a dir that was already there.
create_private_file
Create file empty and 0600, or take group and other’s access away from one that is already there.
make_private
Take group and other’s access away from whatever is at path; the owner keeps what it had.
tighten 🔒
Clear group’s and other’s bits, keeping the owner’s and the setuid, setgid and sticky bits, and only when group or other has one, so a file that is already private costs a stat and nothing more.