remote.h (2660B)
1 #ifndef KIT_BUILD_REMOTE_H 2 #define KIT_BUILD_REMOTE_H 3 4 #include <kit/build_coord.h> /* KitBuildExec, KitBuildObjectRemote */ 5 #include <kit/cas.h> 6 #include <kit/core.h> 7 #include <stddef.h> 8 #include <stdint.h> 9 10 #include "build.h" 11 12 /* 13 * Untrusted remote object fetch — the extra rung in the materialization ladder 14 * (tree cache -> local CAS -> REMOTE FETCH -> run recipe). The coordinator 15 * performs no network I/O itself: when a needed object is absent locally and a 16 * remote is configured, it renders the user's fetch-recipe argv template and 17 * runs it via the exec host to pull one object into a temp file. The fetched 18 * bytes are VERIFIED against the requested content id before being installed 19 * into the local CAS, so a corrupt or malicious mirror fails the hash check and 20 * is discarded — the remotes and the fetch recipe are untrusted, and the 21 * self-verifying CAS makes that safe. Several mirrors may be configured; they 22 * are tried in order until one yields verified bytes. 23 * 24 * Trees vs blobs. A BLOB fetch verifies the bytes hash to `id` and installs 25 * them. A TREE fetch installs the id-checked tree MANIFEST only; the blobs that 26 * tree references are fetched on demand (as further BUILD_REMOTE_BLOB fetches) 27 * when build_store_cache_materialize verifies and restores the tree. So 28 * obtaining a tree is a two-step affair — manifest first, then its blobs — and 29 * the whole tree is verified before any cache hit is served from it. 30 * 31 * There is no separate deepset kind: a deepset closure node is a self-verifying 32 * CAS blob (deep-set-id == blob-id), so it — like need-overlay and argv blobs — 33 * is fetched as an ordinary BLOB ({kind}=blob) on demand when 34 * build_coord_deepset_load needs one the local CAS lacks. 35 * 36 * (Trust, where it exists, is for signed trace bundles — bundle.h. Content 37 * fetched here is trustless.) 38 */ 39 40 typedef enum BuildRemoteKind { 41 BUILD_REMOTE_BLOB = 0, 42 BUILD_REMOTE_TREE = 1, 43 } BuildRemoteKind; 44 45 /* Fetch one object (`kind`, `id`) by trying each remote in `remotes` in order: 46 * render its template (tokens {kind} {pp} {id} {out}), spawn it via the exec 47 * host, verify the fetched bytes hash to `id`, and install them into `cas`. 48 * Returns BUILD_OK on the first verified install, BUILD_ERR if no remote is 49 * configured or all fail/verify-fail (bad bytes are discarded). Stages into 50 * `tmp_dir`. */ 51 int build_remote_fetch(const KitContext*, const KitBuildExec*, 52 const KitBuildObjectRemote* remotes, size_t nremotes, 53 KitCas* cas, KitSlice tmp_dir, BuildRemoteKind kind, 54 const uint8_t id[BUILD_HASH_LEN]); 55 56 #endif