ADR 0027 — File store links (S3, Google Drive, WebDAV, local directories) on the raw layer
Status: accepted · 2026-10-31 (owner request: links to popular file stores — S3, MinIO, Google Drive and other providers — that connect to a bucket, create folders, read the tree of folders and files, build it as nodes, and upload files; separate links where the stores need different code).
Context
The driver framework (ADR 0004) is Connection → Device → Point: people configure every node, the framework polls points. A file store is the other way round: people configure one connection (a bucket, a drive folder, a WebDAV collection), and the nodes below it are whatever the store holds, found by reading it. Points do not fit either: a file has a size, a time and bytes, read on demand, not a value polled every second.
The stores differ in protocol, auth and model: S3 has flat keys and Signature V4; Google Drive has ids, duplicate names, OAuth 2 (service-account JWTs, refresh tokens); WebDAV has real collections, PROPFIND multistatus XML and basic or bearer auth.
Decision
- Three links, one toolkit.
links/s3(AWS S3 and the S3-compatible stores: MinIO, Ceph RGW, Cloudflare R2, Wasabi, Backblaze B2, DigitalOcean Spaces, Google Cloud Storage with HMAC keys),links/gdrive(Drive API v3),links/webdav(Nextcloud, ownCloud, Synology, …). Each implementswyrm_filestore::Backend(probe, scan, mkdir, put, get, delete) and runs asFileStore<B>, a raw-layerLinkincrates/wyrm-filestore. Each is its own driver, package and process binary; none adds a dependency the workspace did not have (SigV4 and the JWT onring, XML by a small reader in the toolkit, Drive JSON onserde_jsonas store data, not the wire). - Raw layer, the framework’s conventions. Connections come from
add_connection(the backend’s params plusrefresh_s,max_entries,max_depth,max_upload_mib,max_download_kib; one form built from#[derive(Params)]),edit(secrets left empty keep the stored ones while thedestfields stay the same, as the framework’skeep_secrets),remove,stop/start. They are kept sealed indata_dir/filestore.connswith the link’s store key, bootstrap params win when they change — the framework’spersist, reimplemented on the publicseal. A connection node has the framework’sstatusenum leaf (wy:df-status) and theerrorleaf while there is one, andentries,total_bytes,last_refresh. - The tree is the store’s, re-declared on every read (principle 3).
<conn>/filesis the root folder; a folder node per folder, a leaf per file (value = size in bytes, at the file’s time;attrname,path,modified,etag,content_type). What a read does not report is removed. A node keeps its key while its entry exists; a name that is not a key segment gets a safe form with a stable hash, the real name isdisplay. - Bounded reads. A read stops at
max_entries(≤ 9 000) andmax_depth(≤ 12) and saystruncated; S3 reads at most 500 pages, a whole read at most 10 minutes. Uploads at most 64 MiB (the gateway’sPOST /api/invokebody), downloads at most 16 MiB. - Levels. Reads (
refresh,download) atread, changes of the store (create_folder,upload,delete) atwrite, connections atconfig. I/O of an action runs on a task of its own, so a slow upload never holds the link’s other calls. - Failures. The probe (an S3 list of one key, Drive
files.getof the root, WebDAVPROPFIND Depth: 0) failing, or a read failing, fails the connection; it reconnects with the framework’s backoff. A request of an action that shows the store is down (connect, 5xx, timeout) wakes the connection task, which probes again. A refused request of one object (403, 404, a taken name) fails that action only. - No silent overwrite. An upload without
overwritesendsIf-None-Match: *(S3, WebDAV) or creates a new Drive file only when the tree has none of that name. - Credentials never leave in clear:
http://with credentials only to loopback unlessinsecure_plaintext; Drive’s API and token URLs must behttps://off loopback.
Consequences
- Big buckets show in part (
truncated); people setprefix(S3) or a subfolder URL (WebDAV) or folder id (Drive) as the connection’s root to see the part they need. - File contents are not values: no history, no flows on them. A flow can invoke
upload(a report) ordownloadthroughinvokesinks like any action. - Google Docs files have no bytes to download (export is not built); S3 uploads are one PutObject (no multipart upload, so up to the 64 MiB cap).
- Each link has an in-crate simulator (
wyrm-s3-sim,wyrm-gdrive-sim,wyrm-webdav-sim) and runs one shared scenario (wyrm_filestore::testkit); SigV4 is checked against the AWS test vectors. Not yet verified against the real services.
Alternatives
- The driver framework with devices as folders: people would add every folder by hand, and files are not polled points.
- One link with a
providerenum: one package pulls in every store’s code and params; the owner asked for separate links. - The AWS and Google SDKs: large dependency trees, aws-lc (refused, see the rustls pin), and three async runtimes’ worth of HTTP stacks for what is a handful of requests.
Amendment 2026-10-31 — local directories (links/localfs)
Owner request: local storage too, working in as many places as possible.
std::fsonly, every call on the blocking pool undertimeout_ms: one link for Linux, macOS, Windows and the BSDs, embedded or as a process link on the host that has the disk. Mounted storage (NFS, SMB, sshfs, USB/SD, NAS) needs nothing of its own.- Confinement: names checked one by one (portable names: what Windows refuses is refused everywhere), the parent resolved and checked inside the resolved root before every change, symlinks out of the root never shown or followed,
remove_dir_all(which does not follow links) for folders. Backend::check_place(default: nothing): called with the link’sdata_diron add, edit and start;localfsrefuses a root that overlaps the broker’s data directory (<data_dir>/links/<id>/data→<data_dir>) in either direction.- Atomic overwrite (temporary file + rename),
create_newotherwise,fsyncof the file and its folder by default,read_only. - Not done: Windows ACLs and hidden attributes (only names starting with
.are hidden).
Amendment 2026-10-31 — review of gencto/wyrm#7 (owner)
Renumbered 0025 → 0027 (0025 is the DQL link on another branch, 0026 history sync).
- Delete asks the store.
Backend::delete(e, below, recursive): withoutrecursivethe backend checks the store itself (localfsremove_dir, S3 a list of two keys under the prefix, WebDAVPROPFIND Depth: 1, Drive the folder’s children) and answers “not empty”; the tree may miss hidden names, deep levels, entries overmax_entriesand new files. localfsneedsallowed_roots(Backend::link_options: bootstrap params besideconnections, set by the admin; checked bystore::validate::<B>inwyrmdand on start). Empty = no directory;/proc,/sys,/devnever;Backend::check_place(data_dir, options)also runs before every probe. Built-in roles withconfigondownstream/**(engineer) can no longer point it at any host path.- Bounded concurrency. One tree read per connection (
busyotherwise), two transfers per connection; upload bytes are taken out of the args, not copied. - One hung call per connection (
localfsGate): while a timed-out blocking call still runs, new calls answertimeoutat once. - Files by their real name (
View::child_named): Overwrite never patches another file whose path form is the same (Drivea/b.txtvsa_b.txt); an entry a request made whose path another id holds gets the id in its path; Drive lists byname,createdTimeand gives a duplicate of a suffixed path the whole id. - An older read never undoes an action (
View::gen/touched): entries an action created or deleted after a read started are left as the action made them. - Smaller: a failed
create_newwrite removes only the file it made; hidden names are not written while not shown; the temporary name is short and keeps the old permissions; more Windows reserved names;refresh_s0 or ≥ 5; a short Drive token life is renewed halfway; a header that cannot be set fails the request (never sent unauthenticated); WebDAV bearer tokens checked; names a store sends that are./../empty/control are left out; a stored connection the link cannot show is skipped, not the link. - Actions end with their connection (review item 7, done after the first round): Stop, Remove, Edit and the link’s stop cut every action in flight at its next await (
Session::close→stopped); the caller getsdisconnected, and nothing more of it reaches the store (a recursive S3 delete stops before the next key). A blockinglocalfscall already in the kernel still ends there. - Still open:
localfsresolve-then-act races on shared mounts (openat2(RESOLVE_BENEATH)/O_NOFOLLOWare Linux-only and not used).
Amendment 2026-10-31 — second review of gencto/wyrm#7 (owner)
- A root that does not exist yet is resolved through its existing part (
localfs::resolve: the longest existing ancestor canonicalized, the rest appended), also forallowed_rootsand the broker’s data directory. Before, a missing root kept its raw path, soallowed/link/.sshwithcreate_root(whereallowed/linkleads out) passed the check andcreate_dir_allfollowed the link out. The probe checks the place again on the root as it resolves aftercreate_dir_all, then pins it; every change refuses a root that no longer resolves to the pinned path (a root swapped for a link after the probe) and makes the probe run again. On macOS (/var→/private/var) the check now compares resolved paths on both sides. Backend::check_placeis async;localfsruns it on the blocking pool behind itsGate, so a hung mount never blocks a tokio worker. TheGate’s count is kept per directory for the life of the process (Gate::for_root): Stop and Start or an Edit no longer forget a call that still hangs.- Overwrite temporary file: named from per-process random hash keys (not guessable), removed only when this upload made it (
write_new), permission bits copied asmode & 0o777. - WebDAV delete without
recursivefails closed: anyPROPFIND Depth: 1response but the collection itself, mapped or not, counts as content. - An id from a store’s answer is shortened by characters, not bytes.
- Still open: the limits on concurrent actions are per connection only (no link-wide bound;
create_folderanddeleteunbounded); a narrowedallowed_rootstakes effect on the link’s restart (noreconfigure).