From 8e6ddb45affb55dbe38d31ccadc5abe4642bbe07 Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 16:03:52 +0100 Subject: [PATCH] feat(permissions): show callers only what they may read Every caller read everything a server held. Callers now see only what their rights let them read, as `permissions::Reader` decides. A caller who reads no path doesn't see the repository at all: it isn't listed, and every call answers as if it didn't exist. Otherwise they see its targets and acceptances, every revision that changes a path they read, or changes nothing, and the statements about what they see. Fetching records leaves out the others, and so do inventories, the revisions of a change and its heads, statements, pending landings and events, while a push's expected heads are compared with those the caller sees. A snapshot walk withholds the content of the paths they don't read: their entries keep their place in the trees, but neither the blobs nor the trees under them come. Everyone who sees the repository reads `policy`'s snapshots, which say what each may do and which keys sign acceptances, so they can verify every target. Walks only check paths where the rules differ: under a path whose level is settled, nothing more is checked. --- apps/origin-src/src/events.rs | 49 +++-- apps/origin-src/src/http.rs | 13 +- apps/origin-src/src/permissions.rs | 237 +++++++++++++++++++++++- apps/origin-src/src/server.rs | 35 ++-- apps/origin-src/src/service.rs | 284 +++++++++++++++++++---------- apps/origin-src/src/sync.rs | 4 +- apps/origin-src/src/tree.rs | 92 ++++++---- apps/origin-src/tests/http.rs | 136 +++++++++++++- crates/origin-client/src/lib.rs | 14 +- crates/origin-shared/src/api.rs | 10 +- docs/openapi.json | 6 +- 11 files changed, 703 insertions(+), 177 deletions(-) diff --git a/apps/origin-src/src/events.rs b/apps/origin-src/src/events.rs index beabb9f4..7959b931 100644 --- a/apps/origin-src/src/events.rs +++ b/apps/origin-src/src/events.rs @@ -79,6 +79,29 @@ impl Wakeup { } } +/// Which events a reader takes: those a [`Filter`] passes, or a closure +/// accepts, such as one that also checks what a caller sees. +pub trait Accept { + /// Whether the reader takes `event`. + /// + /// # Errors + /// + /// Fails if what decides cannot be read. + fn accept(&mut self, event: &EventKind) -> Result; +} + +impl Accept for &Filter { + fn accept(&mut self, event: &EventKind) -> Result { + Ok(self.matches(event)) + } +} + +impl Result> Accept for F { + fn accept(&mut self, event: &EventKind) -> Result { + self(event) + } +} + impl<'a, P: Platform> Events<'a, P> { /// How often [`Events::wait`] reads the op log. pub const POLL: Duration = Duration::from_millis(50); @@ -110,14 +133,19 @@ impl<'a, P: Platform> Events<'a, P> { self.store.oplog().settled() } - /// The events after `cursor` that pass `filter`, oldest first: those + /// The events after `cursor` that `accept` takes, oldest first: those /// of whole entries, until there are `limit` or more. /// /// # Errors /// /// Fails with [`StoreError::Expired`] if the op log no longer keeps the /// entries after `cursor`, or if it or a record cannot be read. - pub fn after(&self, cursor: u64, filter: &Filter, limit: usize) -> Result { + pub fn after( + &self, + cursor: u64, + mut accept: impl Accept, + limit: usize, + ) -> Result { let mut page = Page { events: Vec::new(), next: cursor, @@ -131,15 +159,14 @@ impl<'a, P: Platform> Events<'a, P> { let settled = oplog.settled()?; let mut waiting = None; for entry in read.entries.iter().take_while(|entry| entry.seq <= settled) { - page.events.extend( - self.derive(entry, &mut waiting)? - .into_iter() - .filter(|kind| filter.matches(kind)) - .map(|kind| Event { + for kind in self.derive(entry, &mut waiting)? { + if accept.accept(&kind)? { + page.events.push(Event { cursor: entry.seq, kind, - }), - ); + }); + } + } page.next = entry.seq; if page.events.len() >= limit { break; @@ -158,7 +185,7 @@ impl<'a, P: Platform> Events<'a, P> { pub fn wait( &self, cursor: u64, - filter: &Filter, + mut accept: impl Accept, limit: usize, timeout: Duration, ) -> Result { @@ -167,7 +194,7 @@ impl<'a, P: Platform> Events<'a, P> { loop { // Read before the op log, so no write after it is missed. let seen = self.wakeup.map(Wakeup::writes); - let page = self.after(cursor, filter, limit)?; + let page = self.after(cursor, |event: &EventKind| accept.accept(event), limit)?; let left = timeout.saturating_sub(start.elapsed()); if !page.events.is_empty() || left.is_zero() { return Ok(page); diff --git a/apps/origin-src/src/http.rs b/apps/origin-src/src/http.rs index 8f2a6f5e..afe28959 100644 --- a/apps/origin-src/src/http.rs +++ b/apps/origin-src/src/http.rs @@ -176,7 +176,7 @@ impl utoipa::PartialSchema for Binary { impl utoipa::ToSchema for Binary {} -/// Lists the repositories on the server. +/// Lists the repositories on the server that the caller sees. #[utoipa::path( get, path = "/api/v1/repos", @@ -186,8 +186,15 @@ impl utoipa::ToSchema for Binary {} (status = 401, description = "The token is invalid or expired", body = ApiError) ) )] -async fn list_repos(State(repositories): Repos, caller: Caller) -> Json> { - Json(repositories.list(&caller)) +async fn list_repos( + State(repositories): Repos, + caller: Caller, +) -> Result>, HttpError> { + tokio::task::spawn_blocking(move || repositories.list(&caller)) + .await + .map_err(|error| HttpError::Panicked(error.to_string()))? + .map(Json) + .map_err(HttpError::Service) } /// A part of a fetch, as a response: its pack, with the [`MORE`] header if diff --git a/apps/origin-src/src/permissions.rs b/apps/origin-src/src/permissions.rs index 8bd7cca4..c25db54a 100644 --- a/apps/origin-src/src/permissions.rs +++ b/apps/origin-src/src/permissions.rs @@ -1,9 +1,21 @@ -//! Who calls the service: the node's own user, an anonymous client, or a -//! principal the server [authenticated](crate::auth), whose token may -//! narrow their rights to its scope. +//! Enforcing what callers may do, as their +//! [`Rights`](origin_shared::access::Rights) say: what they read +//! of a repository's records. +//! +//! **Reading.** A caller who reads no path doesn't see the repository at +//! all. Otherwise they see its targets and acceptances, every revision that +//! changes a path they read, or changes nothing, and the statements about +//! what they see. Snapshots withhold the content of the paths they don't +//! read (see [`Store::added`]). -use origin_shared::Principal; -use origin_shared::access::Capability; +use std::collections::HashMap; + +use origin_platform::Platform; +use origin_shared::access::{Capability, PathAccess}; +use origin_shared::event::EventKind; +use origin_shared::{Principal, RecordId, RepoPath, Revision, RevisionId}; + +use crate::store::{Store, StoreError}; /// Who calls the service. #[derive(Clone, Debug, PartialEq, Eq)] @@ -43,6 +55,89 @@ impl Caller { } } +/// What a caller sees of a repository's records, remembering what it +/// decided. +pub struct Reader<'a, P> { + store: &'a Store

, + /// What the caller may do with each path. + paths: &'a PathAccess, + seen: HashMap, +} + +impl<'a, P: Platform> Reader<'a, P> { + /// What a caller who may do `paths` sees of `store`. + pub fn new(store: &'a Store

, paths: &'a PathAccess) -> Self { + Self { + store, + paths, + seen: HashMap::new(), + } + } + + /// Whether the caller sees the repository: they read some path. + #[must_use] + pub fn sees_repository(&self) -> bool { + self.paths.reads_under(&RepoPath::root()) + } + + /// Whether the caller sees every record. + fn sees_all(&self) -> bool { + self.paths.reads_all() + } + + /// Whether the caller sees `record`, as the module explains. A record + /// this node lacks, or whose base it lacks, is not seen. + /// + /// # Errors + /// + /// Fails if a record or tree cannot be read. + pub fn sees(&mut self, record: RecordId) -> Result { + if self.sees_all() { + return Ok(true); + } + if !self.sees_repository() { + return Ok(false); + } + if let Some(&seen) = self.seen.get(&record) { + return Ok(seen); + } + let seen = match record { + RecordId::Revision(id) => self.sees_revision(id), + RecordId::Statement(id) => match self.store.get(id) { + Ok(statement) => self.sees(statement.subject), + Err(error) => Err(error), + }, + RecordId::Acceptance(_) | RecordId::Snapshot(_) => Ok(true), + }; + let seen = match seen { + Err(StoreError::NotFound(_)) => false, + seen => seen?, + }; + self.seen.insert(record, seen); + Ok(seen) + } + + fn sees_revision(&self, id: RevisionId) -> Result { + let revision: Revision = self.store.get(id)?; + let changes = self + .store + .diff(self.store.base_snapshot(revision.base)?, revision.snapshot)?; + Ok(changes.is_empty() || changes.iter().any(|change| self.paths.reads(&change.path))) + } + + /// Whether the caller sees what `event` is about. + /// + /// # Errors + /// + /// Fails like [`Reader::sees`]. + pub fn sees_event(&mut self, event: &EventKind) -> Result { + match event { + EventKind::CheckRequested { subject, .. } => self.sees(*subject), + event => self.sees(event.record()), + } + } +} + /// Something a caller may not do. #[derive(Debug, PartialEq, Eq, thiserror::Error)] pub enum Forbidden { @@ -53,3 +148,135 @@ pub enum Forbidden { #[error("a token may only narrow your rights, which don't include `{0}`")] Scope(Capability), } + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use origin_shared::{NodeKey, TargetName}; + + use super::*; + use crate::queue::tests::Repo; + use crate::service::{Node, OriginService, ServiceError}; + + /// Ada writes everything and changes the rules. Eve reads all but + /// `secrets`, writes only `src`, and issues reviews and checks. Both + /// land on `main`. + const RULES: &str = r#" +[targets.main] +authority = "node:queue" + +[grants] +"user:ada" = ["admin", "land *"] +"user:eve" = ["land *", "annotate review", "annotate ci.*"] + +[[paths]] +path = "/" +grants = { all = "read", "user:ada" = "write" } + +[[paths]] +path = "src" +grants = { "user:eve" = "write" } + +[[paths]] +path = "secrets" +grants = { all = "none", "user:ada" = "write" } +"#; + + /// The repository, with `main` holding a README, a library, a secret + /// and a protected file, and its service. + struct Fixture { + repo: Repo, + service: OriginService, + } + + impl Fixture { + fn new() -> Self { + let repo = Repo::new(RULES); + repo.change_on_main( + 1, + &[ + ("README.md", "hello"), + ("src/lib.rs", "fn a() {}"), + ("secrets/key", "hunter2"), + ("protected/file", "keep"), + ], + ); + repo.land(1); + let node = Node { + name: "queue".parse().unwrap(), + key: Arc::new(NodeKey::from_bytes(&[7; 32])), + }; + let service = OriginService::new(repo.store.clone(), node); + Self { repo, service } + } + } + + fn caller(principal: &str) -> Caller { + Caller::Principal { + principal: principal.parse().unwrap(), + scope: None, + } + } + + /// `caller`, with a token narrowing them to `scope`, expiring at + /// `expires`. + fn scoped(principal: &str, scope: &[&str], expires: u64) -> Caller { + Caller::Principal { + principal: principal.parse().unwrap(), + scope: Some(Scope { + capabilities: scope.iter().map(|c| c.parse().unwrap()).collect(), + expires, + }), + } + } + + /// A week from now, in seconds since the Unix epoch. + fn in_a_week() -> u64 { + let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH); + (now.unwrap() + OriginService::MAX_TOKEN_TTL).as_secs() + } + + #[test] + fn callers_who_read_nothing_see_nothing() { + let fixture = Fixture::new(); + let revision = fixture.repo.change_on_main(2, &[]); + let blind = scoped("user:eve", &["annotate review"], in_a_week()); + let service = &fixture.service; + assert!(!service.sees_repository(&blind).unwrap()); + let records = service.records(&blind, &[revision.into()]).unwrap(); + assert!( + records.pack.objects.is_empty(), + "not even a revision changing nothing" + ); + assert_eq!(service.targets(&blind).unwrap(), []); + let log = origin_shared::api::LogQuery { + target: TargetName::MAIN, + since: 0, + limit: None, + }; + assert!(matches!( + service.log(&blind, &log), + Err(ServiceError::UnknownTarget(_)) + )); + assert_eq!(service.log(&caller("user:eve"), &log).unwrap().len(), 2); + } + + #[test] + fn tokens_issued_from_a_token_expire_with_it() { + let fixture = Fixture::new(); + let expires = in_a_week() - 6 * 24 * 3600; + let parent = scoped("user:eve", &["annotate review", "land *"], expires); + let request = origin_shared::api::TokenRequest { + scope: vec!["annotate review".parse().unwrap()], + ttl: origin_shared::Period(OriginService::MAX_TOKEN_TTL), + }; + let issued = fixture.service.issue_token(&parent, &request).unwrap(); + assert_eq!(issued.expires, expires); + let issued = fixture + .service + .issue_token(&caller("user:eve"), &request) + .unwrap(); + assert!(issued.expires > expires, "a static token's last a week"); + } +} diff --git a/apps/origin-src/src/server.rs b/apps/origin-src/src/server.rs index b0819071..4459eaae 100644 --- a/apps/origin-src/src/server.rs +++ b/apps/origin-src/src/server.rs @@ -269,24 +269,33 @@ impl Repositories { self.repos.insert(name, service); } - /// Lists the repositories, by name. - #[must_use] - pub fn list(&self, _caller: &Caller) -> Vec { - self.repos - .keys() - .map(|name| RepoSummary { name: name.clone() }) - .collect() + /// Lists the repositories the caller sees, by name. + /// + /// # Errors + /// + /// Fails if a repository's policy cannot be read. + pub fn list(&self, caller: &Caller) -> Result, ServiceError> { + let mut seen = Vec::new(); + for (name, service) in &self.repos { + if service.sees_repository(caller)? { + seen.push(RepoSummary { name: name.clone() }); + } + } + Ok(seen) } - /// The repository `name`. + /// The repository `name`, if the caller sees it: invisible repositories + /// don't exist. /// /// # Errors /// - /// Fails if the server hosts none by that name. - pub fn get(&self, _caller: &Caller, name: &RepoName) -> Result<&OriginService, ServiceError> { - self.repos - .get(name) - .ok_or_else(|| ServiceError::UnknownRepository(name.clone())) + /// Fails if the server hosts none by that name the caller sees, or its + /// policy cannot be read. + pub fn get(&self, caller: &Caller, name: &RepoName) -> Result<&OriginService, ServiceError> { + match self.repos.get(name) { + Some(service) if service.sees_repository(caller)? => Ok(service), + _ => Err(ServiceError::UnknownRepository(name.clone())), + } } } diff --git a/apps/origin-src/src/service.rs b/apps/origin-src/src/service.rs index 3fdeed33..090ee59d 100644 --- a/apps/origin-src/src/service.rs +++ b/apps/origin-src/src/service.rs @@ -15,8 +15,9 @@ //! queue lock. //! //! Every method takes the [`Caller`], whose [`Rights`] the policy in force -//! resolves. Nothing is checked yet: every caller may read and write -//! everything. +//! resolves: what each caller reads is filtered, as +//! [`permissions`](crate::permissions) explains. Nothing they write is +//! checked yet. use std::collections::hash_map::Entry; use std::collections::{HashMap, HashSet}; @@ -26,26 +27,26 @@ use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; use std::time::Duration; use origin_platform::Native; -use origin_shared::access::{Rights, Token}; +use origin_shared::access::{PathAccess, Rights, Token}; use origin_shared::api::{ Annotation, ErrorCode, EventsQuery, Expected, FetchSnapshot, Inventory, InventoryRequest, IssuedToken, LandRequest, Landings, LogEntry, LogQuery, NewTarget, RevisionEntry, Revisions, Stored, TargetInfo, TokenRequest, }; -use origin_shared::event::{Filter, Page}; +use origin_shared::event::{EventKind, Filter, Page}; use origin_shared::landing::{Pending, Proposal}; use origin_shared::object::DecodeError; use origin_shared::pack::{Pack, Packer, Part}; use origin_shared::{ AcceptanceId, Base, ChangeId, Head, Kind, NodeKey, Object, ObjectId, ObjectKind, Principal, - PrincipalName, RecordId, Statement, StatementId, TargetName, TreeId, + PrincipalName, RecordId, RepoPath, Statement, StatementId, TargetName, TreeId, }; use crate::annotations::{AnnotateError, Annotations}; use crate::events::{Events, Wakeup}; use crate::index::Index; pub use crate::permissions::Caller; -use crate::permissions::Forbidden; +use crate::permissions::{Forbidden, Reader}; use crate::policy::{Policy, PolicyError}; use crate::queue::{LandError, Queue}; use crate::store::{Store, StoreError}; @@ -232,6 +233,16 @@ impl OriginService { }) } + /// Whether the caller sees the repository at all: they read some path. + /// Those who don't see none of its records, targets or events. + /// + /// # Errors + /// + /// Fails if the policy cannot be read. + pub fn sees_repository(&self, caller: &Caller) -> Result { + Ok(self.rights(caller)?.paths.reads_under(&RepoPath::root())) + } + /// `whoami`: what the caller may do, and who they are. /// /// # Errors @@ -285,32 +296,40 @@ impl OriginService { } /// The records `ids` name, in their order, as a pack: revisions, - /// statements and acceptances, each followed by the attachment it - /// carries, if the repository has it: a revision's description, a - /// statement's payload. Snapshots only leave through - /// [`OriginService::snapshot`]. The pack stops short at [`Pack::LIMIT`], - /// before a record that doesn't fit with its attachment: the rest comes - /// from asking for the ids after the last record it has. + /// statements and acceptances the caller sees, the others left out, + /// each followed by the attachment it carries, if the repository has + /// it: a revision's description, a statement's payload. Snapshots only + /// leave through [`OriginService::snapshot`]. The pack stops short at + /// [`Pack::LIMIT`], before a record that doesn't fit with its + /// attachment: the rest comes from asking for the ids after the last + /// record it has. /// /// # Errors /// /// Fails if the repository doesn't have one, one is a blob, a tree or /// an attachment, or it cannot read one. - pub fn records(&self, _caller: &Caller, ids: &[ObjectId]) -> Result { + pub fn records(&self, caller: &Caller, ids: &[ObjectId]) -> Result { + let rights = self.rights(caller)?; + let mut reader = Reader::new(&self.store, &rights.paths); let mut packer = Packer::new(self.pack_limit); for &id in ids { let object = self.store.read(id)?; - let carried = match object + let (record, carried) = match object .decode() .map_err(|source| StoreError::Decode { id, source })? { Object::Blob(_) | Object::Tree(_) | Object::Attachment(_) => { return Err(ServiceError::NotARecord(id)); } - Object::Revision(revision) => Some(revision.description), - Object::Statement(statement) => statement.payload, - Object::Acceptance(_) => None, + Object::Revision(revision) => { + (RecordId::Revision(id.into()), Some(revision.description)) + } + Object::Statement(statement) => (RecordId::Statement(id.into()), statement.payload), + Object::Acceptance(_) => (RecordId::Acceptance(id.into()), None), }; + if !reader.sees(record)? { + continue; + } // Only an attachment goes with a record: never a blob, a file's // content, whose id a record names instead. let carried = carried @@ -333,8 +352,13 @@ impl OriginService { }) } - /// The snapshot of a record, a revision or an acceptance, if it is one. - fn snapshot_of(&self, record: RecordId) -> Result { + /// The snapshot of a record the caller sees, a revision or an + /// acceptance, if it is one. + fn snapshot_of( + &self, + reader: &mut Reader<'_, Native>, + record: RecordId, + ) -> Result { let unknown = || ServiceError::UnknownRecord(record); let snapshot = match record { RecordId::Revision(id) => self.store.get(id).map(|revision| revision.snapshot), @@ -345,30 +369,33 @@ impl OriginService { return Err(ServiceError::NotASnapshot(record)); } }; - match snapshot { + let snapshot = match snapshot { // Not a record of the kind it's named as. - Err(StoreError::NotFound(_) | StoreError::Decode { .. }) => Err(unknown()), - snapshot => Ok(snapshot?), + Err(StoreError::NotFound(_) | StoreError::Decode { .. }) => return Err(unknown()), + snapshot => snapshot?, + }; + if !reader.sees(record)? { + return Err(unknown()); } + Ok(snapshot) } /// The objects of the snapshot of the record the request names that the /// caller lacks, as a pack, parents before children: those none of the /// snapshots it has holds at the same path, under the paths it asks - /// for, but the first `skip`. See [`Store::added`]. The pack stops - /// short at [`Pack::LIMIT`]: the rest comes from asking again, skipping - /// what came. + /// for, but the first `skip`. The content of paths the caller may not + /// read is withheld. See [`Store::added`]. The pack stops short at + /// [`Pack::LIMIT`]: the rest comes from asking again, skipping what + /// came. /// /// # Errors /// - /// Fails if the record isn't a revision or an acceptance, or the - /// repository cannot read its snapshot. - pub fn snapshot( - &self, - _caller: &Caller, - request: &FetchSnapshot, - ) -> Result { - let snapshot = self.snapshot_of(request.of)?; + /// Fails if the record isn't a revision or an acceptance the caller + /// sees, or the repository cannot read its snapshot. + pub fn snapshot(&self, caller: &Caller, request: &FetchSnapshot) -> Result { + let rights = self.rights(caller)?; + let snapshot = + self.snapshot_of(&mut Reader::new(&self.store, &rights.paths), request.of)?; let mut have = Vec::new(); for &id in &request.have { let object = self.store.try_read(id.into())?; @@ -376,7 +403,12 @@ impl OriginService { have.push(id); } } - let added = self.store.added(snapshot, &have, &request.paths)?; + let added = self.store.added( + snapshot, + &have, + &request.paths, + self.filter(&rights, request.of)?, + )?; let skip = usize::try_from(request.skip).unwrap_or(usize::MAX); let ids: Vec = added .iter() @@ -398,42 +430,69 @@ impl OriginService { }) } - /// What the repository holds of each change: its revisions and heads, - /// and the statements about them, by id. A change it never heard of - /// has none. + /// What a walk of the snapshot of `record` withholds from a caller with + /// `rights`, if anything. Everyone who sees the repository reads the + /// snapshots of `policy`: what each may do, and the keys that sign + /// acceptances, so they can verify every target. + fn filter<'r>( + &self, + rights: &'r Rights, + record: RecordId, + ) -> Result, ServiceError> { + if rights.paths.reads_all() { + return Ok(None); + } + if let RecordId::Acceptance(id) = record + && self.store.get(id)?.body().target == TargetName::POLICY.id() + { + return Ok(None); + } + Ok(Some(&rights.paths)) + } + + /// What the repository holds of each change that the caller sees: its + /// revisions and heads, and the statements about them, by id. A change + /// it never heard of has none. /// /// # Errors /// - /// Fails if the index cannot be read. + /// Fails if the index or a record cannot be read. pub fn inventory( &self, - _caller: &Caller, + caller: &Caller, request: &InventoryRequest, ) -> Result, ServiceError> { + let rights = self.rights(caller)?; + let mut reader = Reader::new(&self.store, &rights.paths); self.annotations(|annotations| { let index = annotations.index(); - Ok(request - .changes - .iter() - .map(|&change| { - let revisions = index.revisions(change).to_vec(); - let mut subjects: Vec<_> = - revisions.iter().copied().map(RecordId::Revision).collect(); - let mut statements = Vec::new(); - while let Some(subject) = subjects.pop() { - for &statement in index.statements(subject) { - statements.push(statement); - subjects.push(RecordId::Statement(statement)); - } + let mut inventories = Vec::new(); + for &change in &request.changes { + let mut revisions = Vec::new(); + for &id in index.revisions(change) { + if reader.sees(RecordId::Revision(id))? { + revisions.push(id); } - Inventory { - change, - heads: index.heads(change), - revisions, - statements, + } + let mut heads = index.heads(change); + heads.retain(|head| revisions.contains(head)); + let mut subjects: Vec<_> = + revisions.iter().copied().map(RecordId::Revision).collect(); + let mut statements = Vec::new(); + while let Some(subject) = subjects.pop() { + for &statement in index.statements(subject) { + statements.push(statement); + subjects.push(RecordId::Statement(statement)); } - }) - .collect()) + } + inventories.push(Inventory { + change, + heads, + revisions, + statements, + }); + } + Ok(inventories) }) } @@ -464,11 +523,12 @@ impl OriginService { } /// Puts `pack` like [`OriginService::put_records`], if each change of - /// `expect` has the heads it names when its records are published: a - /// compare-and-swap, which every other publication of revisions waits - /// for, puts and the landing queue's rebases alike. So of two pushes - /// made from the same view of a change, or a push and a rebase, the - /// second is refused instead of making it diverge. + /// `expect` has the heads it names, of those the caller sees, when its + /// records are published: a compare-and-swap, which every other + /// publication of revisions waits for, puts and the landing queue's + /// rebases alike. So of two pushes made from the same view of a change, + /// or a push and a rebase, the second is refused instead of making it + /// diverge. /// /// # Errors /// @@ -476,7 +536,7 @@ impl OriginService { /// `expect` moved, which publishes no record, only snapshots. pub fn push( &self, - _caller: &Caller, + caller: &Caller, pack: Pack, expect: &[Expected], ) -> Result { @@ -555,7 +615,7 @@ impl OriginService { // changes in between: see `Store::lock_pushes`. let _pushing = if !revisions.is_empty() || !expect.is_empty() { let lock = self.store.lock_pushes()?; - self.check_heads(expect)?; + self.check_heads(caller, expect)?; Some(lock) } else { None @@ -595,11 +655,19 @@ impl OriginService { Ok(Stored { new: new as u64 }) } - /// Checks that each change of `expect` has the heads it names. - fn check_heads(&self, expect: &[Expected]) -> Result<(), ServiceError> { + /// Checks that each change of `expect` has the heads it names, of those + /// the caller sees. + fn check_heads(&self, caller: &Caller, expect: &[Expected]) -> Result<(), ServiceError> { + let rights = self.rights(caller)?; + let mut reader = Reader::new(&self.store, &rights.paths); self.annotations(|annotations| { for expected in expect { - let heads = annotations.index().heads(expected.change); + let mut heads = Vec::new(); + for head in annotations.index().heads(expected.change) { + if reader.sees(RecordId::Revision(head))? { + heads.push(head); + } + } let now: HashSet<_> = heads.iter().collect(); if now != expected.heads.iter().collect() { return Err(ServiceError::Moved { @@ -661,34 +729,47 @@ impl OriginService { } /// The statements about `subject`, in the order the repository received - /// them. + /// them: none if the caller doesn't see it. /// /// # Errors /// /// Fails if the index or a statement cannot be read. pub fn statements( &self, - _caller: &Caller, + caller: &Caller, subject: RecordId, ) -> Result, ServiceError> { + let rights = self.rights(caller)?; + if !Reader::new(&self.store, &rights.paths).sees(subject)? { + return Ok(Vec::new()); + } self.annotations(|annotations| Ok(annotations.about(subject)?)) } - /// The revisions of `change`, and its heads. + /// The revisions of `change` the caller sees, and its heads among them. /// /// # Errors /// - /// Fails if the repository has no revision of the change, or cannot - /// read one. - pub fn revisions(&self, _caller: &Caller, change: ChangeId) -> Result { - let (ids, heads) = self.annotations(|annotations| { + /// Fails if the repository has no revision of the change the caller + /// sees, or cannot read one. + pub fn revisions(&self, caller: &Caller, change: ChangeId) -> Result { + let rights = self.rights(caller)?; + let mut reader = Reader::new(&self.store, &rights.paths); + let (mut ids, mut heads) = self.annotations(|annotations| { let index = annotations.index(); Ok((index.revisions(change).to_vec(), index.heads(change))) })?; - if ids.is_empty() { + let mut seen = Vec::with_capacity(ids.len()); + for id in ids.drain(..) { + if reader.sees(RecordId::Revision(id))? { + seen.push(id); + } + } + heads.retain(|head| seen.contains(head)); + if seen.is_empty() { return Err(ServiceError::UnknownChange(change)); } - let revisions = ids + let revisions = seen .into_iter() .map(|id| { Ok(RevisionEntry { @@ -701,12 +782,16 @@ impl OriginService { } /// Every target, by name, with its tip, and its authority and - /// requirements under the policy in force. + /// requirements under the policy in force: none, if the caller doesn't + /// see the repository. /// /// # Errors /// /// Fails if the targets or the policy cannot be read. - pub fn targets(&self, _caller: &Caller) -> Result, ServiceError> { + pub fn targets(&self, caller: &Caller) -> Result, ServiceError> { + if !self.sees_repository(caller)? { + return Ok(Vec::new()); + } let policy = Policy::load(&self.store)?; let mut names = self.store.targets()?; names.sort(); @@ -730,11 +815,11 @@ impl OriginService { /// /// # Errors /// - /// Fails if the target doesn't exist, or its log or an acceptance - /// cannot be read. - pub fn log(&self, _caller: &Caller, query: &LogQuery) -> Result, ServiceError> { + /// Fails if the target doesn't exist, or the caller doesn't see the + /// repository, or its log or an acceptance cannot be read. + pub fn log(&self, caller: &Caller, query: &LogQuery) -> Result, ServiceError> { let target = &query.target; - if self.store.head(target)?.is_none() { + if !self.sees_repository(caller)? || self.store.head(target)?.is_none() { return Err(ServiceError::UnknownTarget(target.clone())); } let mut ids = self.store.log_since(target, query.since)?; @@ -807,13 +892,22 @@ impl OriginService { Ok(self.store.stack_target(head)?) } - /// Every landing that waits, on every target, and why. + /// Every landing that waits, on every target, and why: those about what + /// the caller sees. /// /// # Errors /// - /// Fails if the queues cannot be read. - pub fn landings(&self, _caller: &Caller) -> Result, ServiceError> { - Ok(Queue::pending(&self.store)?) + /// Fails if the queues or a record cannot be read. + pub fn landings(&self, caller: &Caller) -> Result, ServiceError> { + let rights = self.rights(caller)?; + let mut reader = Reader::new(&self.store, &rights.paths); + let mut seen = Vec::new(); + for pending in Queue::pending(&self.store)? { + if reader.sees(pending.subject)? { + seen.push(pending); + } + } + Ok(seen) } /// Creates a target at the tip of another, with this node as its @@ -835,22 +929,25 @@ impl OriginService { Ok(head) } - /// The events after the query's cursor that pass its filter, waiting - /// up to its `wait`, at most [`OriginService::MAX_WAIT`], for some to - /// come. Without a cursor, only events from now on come. + /// The events after the query's cursor that pass its filter, about what + /// the caller sees, waiting up to its `wait`, at most + /// [`OriginService::MAX_WAIT`], for some to come. Without a cursor, only + /// events from now on come. /// /// # Errors /// /// Fails if the op log no longer keeps the events after the cursor, or /// isn't of the generation the query names, or it or a record cannot /// be read. - pub fn events(&self, _caller: &Caller, query: &EventsQuery) -> Result { + pub fn events(&self, caller: &Caller, query: &EventsQuery) -> Result { let generation = self.store.oplog().generation()?; if let Some(theirs) = &query.generation && *theirs != generation { return Err(ServiceError::OtherLog(theirs.clone())); } + let rights = self.rights(caller)?; + let mut reader = Reader::new(&self.store, &rights.paths); let events = Events::new(&self.store).waking_on(&self.wakeup); let cursor = match query.cursor { Some(cursor) => cursor, @@ -865,7 +962,8 @@ impl OriginService { .unwrap_or(Self::MAX_EVENTS) .min(Self::MAX_EVENTS) as usize; let wait = query.wait.map_or(Duration::ZERO, |wait| wait.0); - let page = events.wait(cursor, &filter, limit, wait.min(Self::MAX_WAIT))?; + let accept = |event: &EventKind| Ok(filter.matches(event) && reader.sees_event(event)?); + let page = events.wait(cursor, accept, limit, wait.min(Self::MAX_WAIT))?; Ok(Page { generation, ..page }) } } diff --git a/apps/origin-src/src/sync.rs b/apps/origin-src/src/sync.rs index a8bac424..657a4af7 100644 --- a/apps/origin-src/src/sync.rs +++ b/apps/origin-src/src/sync.rs @@ -1027,7 +1027,7 @@ impl<'a> Sync<'a> { // Children first: a tree goes after what it holds. for placed in self .store - .added(revision.snapshot, &have, &[])? + .added(revision.snapshot, &have, &[], None)? .into_iter() .rev() { @@ -2193,7 +2193,7 @@ mod tests { let wire = |objects: Vec| Pack { objects }.encode().len(); let content = client .store - .added(revision.snapshot, &[], &[]) + .added(revision.snapshot, &[], &[], None) .unwrap() .iter() .map(|placed| client.store.read(placed.entry.id).unwrap()) diff --git a/apps/origin-src/src/tree.rs b/apps/origin-src/src/tree.rs index f854cce5..f64b6909 100644 --- a/apps/origin-src/src/tree.rs +++ b/apps/origin-src/src/tree.rs @@ -7,6 +7,7 @@ use std::io; use std::path::PathBuf; use origin_platform::Platform; +use origin_shared::access::{Level, PathAccess}; use origin_shared::{ Base, Digest, EncodedObject, EntryKind, EntryName, Inputs, ObjectId, Record, RecordId, RepoPath, Tree, TreeEntry, TreeId, @@ -27,6 +28,13 @@ pub struct FileChange { } impl Store

{ + /// Whether a tree operation may read the entry at `path` of a + /// directory whose withheld paths are `withheld`: a file it reads, or a + /// directory it reads something under. + fn readable(withheld: Option<&PathAccess>, path: &RepoPath, entry: &TreeEntry) -> bool { + withheld.is_none_or(|access| access.reads_entry(path, entry)) + } + /// Lists the files that differ between two trees, sorted by path. /// Subtrees with equal ids are skipped without being read, so the cost /// follows the size of the change. @@ -543,7 +551,9 @@ impl Store

{ /// The objects of `snapshot` that none of the snapshots `have` holds at /// the same path, parents before children: what someone holding `have` /// lacks of it. With `paths`, only those under them, and the trees on - /// the way. Subtrees a `have` holds whole are skipped without being + /// the way. With `access`, only what it reads, and the trees on the way + /// to it: the rest keeps its place in the trees, but its content is + /// withheld. Subtrees a `have` holds whole are skipped without being /// read, so the cost follows the size of the change. Objects appear /// once, at their first path. /// @@ -555,34 +565,48 @@ impl Store

{ snapshot: TreeId, have: &[TreeId], paths: &[RepoPath], + access: Option<&PathAccess>, ) -> Result, StoreError> { let mut added = Vec::new(); let mut seen = HashSet::new(); - self.add_dir( - &RepoPath::root(), - snapshot, - have, - &Scope(paths), - &mut seen, - &mut added, - )?; + let walk = Walk { + scope: Scope(paths), + seen: &mut seen, + added: &mut added, + }; + let root = RepoPath::root(); + walk.dir(self, &root, snapshot, have, Self::unsettled(access, &root))?; Ok(added) } - fn add_dir( - &self, + /// `access`, if what it allows at and under `path` isn't settled to + /// reading: walks only check paths while it isn't. + fn unsettled<'a>(access: Option<&'a PathAccess>, path: &RepoPath) -> Option<&'a PathAccess> { + access.filter(|access| access.settled(path).is_none_or(|level| level < Level::Read)) + } +} + +/// A walk of [`Store::added`]. +struct Walk<'w> { + scope: Scope<'w>, + seen: &'w mut HashSet, + added: &'w mut Vec, +} + +impl Walk<'_> { + fn dir( + mut self, + store: &Store

, dir: &RepoPath, tree: TreeId, have: &[TreeId], - scope: &Scope<'_>, - seen: &mut HashSet, - added: &mut Vec, - ) -> Result<(), StoreError> { + access: Option<&PathAccess>, + ) -> Result { if have.contains(&tree) { - return Ok(()); + return Ok(self); } - if seen.insert(tree.into()) { - added.push(Placed { + if self.seen.insert(tree.into()) { + self.added.push(Placed { path: dir.clone(), entry: TreeEntry { kind: EntryKind::Tree, @@ -592,12 +616,15 @@ impl Store

{ } let have: Vec = have .iter() - .map(|&id| self.get(id)) + .map(|&id| store.get(id)) .collect::>()?; - for (name, &entry) in &self.get(tree)? { + for (name, &entry) in &store.get(tree)? { let path = dir.join(name); - let covered = scope.covers(&path); - if !(covered || entry.kind.is_tree() && scope.leads_in(&path)) { + let covered = self.scope.covers(&path); + if !(covered || entry.kind.is_tree() && self.scope.leads_in(&path)) { + continue; + } + if !Store::

::readable(access, &path, &entry) { continue; } let held = have.iter().filter_map(|tree| tree.get(name.as_str())); @@ -607,13 +634,14 @@ impl Store

{ match entry.subtree() { Some(subtree) => { let held: Vec<_> = held.filter_map(|held| held.subtree()).collect(); - self.add_dir(&path, subtree, &held, scope, seen, added)?; + let access = Store::

::unsettled(access, &path); + self = self.dir(store, &path, subtree, &held, access)?; } - None if seen.insert(entry.id) => added.push(Placed { path, entry }), + None if self.seen.insert(entry.id) => self.added.push(Placed { path, entry }), None => {} } } - Ok(()) + Ok(self) } } @@ -776,31 +804,31 @@ pub(crate) mod tests { }; assert_eq!( - paths(store.added(new, &[old], &[]).unwrap()), + paths(store.added(new, &[old], &[], None).unwrap()), ["/", "docs", "docs/copy", "edit", "edit/b", "file"], "`file/now-dir` has the content of `docs/copy`, listed first" ); assert_eq!( - store.added(new, &[], &[]).unwrap().len(), + store.added(new, &[], &[], None).unwrap().len(), 8, "5 trees, and 5 files of 3 contents" ); - assert_eq!(store.added(new, &[new], &[]).unwrap(), []); + assert_eq!(store.added(new, &[new], &[], None).unwrap(), []); let empty = build(&store, &[]); assert_eq!( - paths(store.added(new, &[empty, old], &[]).unwrap()), - paths(store.added(new, &[old], &[]).unwrap()), + paths(store.added(new, &[empty, old], &[], None).unwrap()), + paths(store.added(new, &[old], &[], None).unwrap()), "any have holding an object is enough" ); let only = |path: &str| [RepoPath::new(path).unwrap()]; assert_eq!( - paths(store.added(new, &[], &only("edit/b")).unwrap()), + paths(store.added(new, &[], &only("edit/b"), None).unwrap()), ["/", "edit", "edit/b"], "the trees on the way, then the path" ); assert_eq!( - paths(store.added(new, &[old], &only("same")).unwrap()), + paths(store.added(new, &[old], &only("same"), None).unwrap()), ["/"] ); } diff --git a/apps/origin-src/tests/http.rs b/apps/origin-src/tests/http.rs index 9346bbaf..517925db 100644 --- a/apps/origin-src/tests/http.rs +++ b/apps/origin-src/tests/http.rs @@ -38,6 +38,8 @@ struct Server { /// `demo` and `strict`, as `user:ada`. demo: Repo, strict: Repo, + /// `strict`, as `user:ci`. + ci: Repo, /// `strict`, anonymously. anonymous: Repo, } @@ -75,11 +77,13 @@ impl Server { tokio::spawn(async move { axum::serve(listener, Api::router(repositories)).await }); let anonymous = Client::new(&format!("http://{address}")); let client = anonymous.clone().with_token("ada-token"); + let ci = anonymous.clone().with_token("ci-token"); Self { _dir: dir, base: format!("http://{address}"), demo: client.repo("demo".parse().unwrap()), strict: client.repo("strict".parse().unwrap()), + ci: ci.repo("strict".parse().unwrap()), anonymous: anonymous.repo("strict".parse().unwrap()), client, } @@ -200,12 +204,12 @@ async fn main_tip(repo: &Repo) -> Base { Base::Acceptance(main.head.acceptance) } -fn ci_test(subject: RevisionId) -> EncodedObject { +fn ci_test(subject: RevisionId, issuer: &str) -> EncodedObject { Statement { subject: RecordId::Revision(subject), kind: Kind::new("ci.test").unwrap(), verdict: Some(Verdict::Pass), - issuer: "user:ci".parse().unwrap(), + issuer: issuer.parse().unwrap(), inputs: None, payload: None, supersedes: None, @@ -562,7 +566,7 @@ async fn reads_statements_and_revisions() { let repo = &server.demo; let base = main_tip(repo).await; let first = Made::revision(change(1), base, vec![], &[("a.txt", "1")]); - let statement = ci_test(first.id); + let statement = ci_test(first.id, "user:ada"); let mut pack = first.pack(); pack.objects.push(statement.clone()); repo.put_records(&pack).await.unwrap(); @@ -733,7 +737,7 @@ async fn landings_wait_for_evidence() { ); repo.put_records(&Pack { - objects: vec![ci_test(made.id)], + objects: vec![ci_test(made.id, "user:ci")], }) .await .unwrap(); @@ -789,6 +793,30 @@ async fn events_long_poll() { ); } +/// Lands a change of `user:ada` with `files` on `strict`'s `main`, with the +/// `ci.test` it requires. +async fn land_on_strict(server: &Server, seed: u8, files: &[(&str, &str)]) -> Made { + let made = Made::nested(change(seed), main_tip(&server.strict).await, files); + server.strict.put_records(&made.pack()).await.unwrap(); + server + .ci + .put_records(&Pack { + objects: vec![ci_test(made.id, "user:ci")], + }) + .await + .unwrap(); + let land = LandRequest { + proposal: Proposal::Change(change(seed)), + onto: None, + }; + let landed = server.strict.land(&land).await.unwrap(); + assert!( + matches!(landed.landings[..], [Landing::Landed { .. }]), + "{landed:?}" + ); + made +} + #[tokio::test] async fn tells_callers_what_they_may_do_and_issues_narrower_tokens() { let server = Server::start().await; @@ -841,6 +869,106 @@ async fn tells_callers_what_they_may_do_and_issues_narrower_tokens() { assert_eq!(code(error), ErrorCode::Forbidden); } +#[tokio::test] +async fn reads_only_what_the_caller_may() { + let server = Server::start().await; + let public = land_on_strict( + &server, + 1, + &[("README.md", "hello"), ("secrets/key", "hunter2")], + ) + .await; + let secret = Made::nested( + change(2), + main_tip(&server.strict).await, + &[("README.md", "hello"), ("secrets/key", "rotated")], + ); + server.strict.put_records(&secret.pack()).await.unwrap(); + let anonymous = &server.anonymous; + + // The walk withholds the secret, but keeps its place in the tree. + let walked = anonymous + .fetch_snapshot(&FetchSnapshot { + of: RecordId::Revision(public.id), + have: Vec::new(), + paths: Vec::new(), + skip: 0, + }) + .await + .unwrap(); + let ids: Vec<_> = walked.pack.objects.iter().map(EncodedObject::id).collect(); + let hunter2 = EncodedObject::blob(b"hunter2").id(); + assert!(!ids.contains(&hunter2), "the secret's content is withheld"); + assert_eq!(ids.len(), 2, "the root and README.md, not `secrets`'s tree"); + let root: Tree = walked.pack.objects[0].decode_as().unwrap(); + assert!(root.get("secrets").is_some()); + + // A revision that only changes what they can't read is hidden, with + // everything about it. + let records = anonymous + .fetch_records(&FetchRecords { + ids: vec![public.id.into(), secret.id.into()], + }) + .await + .unwrap(); + assert_eq!(records.pack.objects[0].id(), public.id.into()); + assert!( + records + .pack + .objects + .iter() + .all(|object| object.id() != secret.id.into()) + ); + let error = anonymous.revisions(change(2)).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::NotFound); + let query = StatementsQuery { + subject: RecordId::Revision(secret.id), + }; + server + .strict + .put_records(&Pack { + objects: vec![review(secret.id)], + }) + .await + .unwrap(); + assert_eq!(server.strict.statements(&query).await.unwrap().len(), 1); + assert_eq!(anonymous.statements(&query).await.unwrap(), []); + let error = anonymous + .fetch_snapshot(&FetchSnapshot { + of: RecordId::Revision(secret.id), + have: Vec::new(), + paths: Vec::new(), + skip: 0, + }) + .await + .unwrap_err(); + assert_eq!(code(error), ErrorCode::NotFound); + let everything = EventsQuery { + cursor: Some(0), + ..EventsQuery::default() + }; + let hidden = |page: &origin_shared::event::Page| { + page.events.iter().any(|event| { + matches!(event.kind, + EventKind::RevisionCreated { revision, .. } if revision == secret.id) + || matches!(event.kind, + EventKind::StatementIssued { subject, .. } if subject == RecordId::Revision(secret.id)) + }) + }; + assert!(hidden(&server.strict.events(&everything).await.unwrap())); + assert!(!hidden(&anonymous.events(&everything).await.unwrap())); +} + +/// A passing review from `user:ada` about `subject`. +fn review(subject: RevisionId) -> EncodedObject { + Statement { + kind: Kind::new("review").unwrap(), + issuer: "user:ada".parse().unwrap(), + ..ci_test(subject, "user:ada").decode_as().unwrap() + } + .encode() +} + #[tokio::test] async fn serves_its_openapi_document() { let server = Server::start().await; diff --git a/crates/origin-client/src/lib.rs b/crates/origin-client/src/lib.rs index bb1dafaf..bc3bb024 100644 --- a/crates/origin-client/src/lib.rs +++ b/crates/origin-client/src/lib.rs @@ -67,16 +67,16 @@ endpoints! { } impl Repo { - /// Fetches records by id, in the order asked, each followed by the - /// attachment it carries if the server has it: a revision's - /// description, a statement's payload. A part that stops short - /// holds those up to the last record it has. + /// Fetches the records the caller sees by id, in the order asked, + /// each followed by the attachment it carries if the server has + /// it: a revision's description, a statement's payload. A part + /// that stops short holds those up to the last record it has. fn fetch_records(request: &FetchRecords) -> Part = POST "records/fetch", json(request) => part; /// Fetches the trees and blobs of a record's snapshot that none of - /// the request's snapshots holds at the same path, parents first. A - /// part that stops short is followed by asking again, skipping the - /// objects it holds. + /// the request's snapshots holds at the same path, parents first, + /// but the content the caller may not read. A part that stops short + /// is followed by asking again, skipping the objects it holds. fn fetch_snapshot(request: &FetchSnapshot) -> Part = POST "snapshots/fetch", json(request) => part; /// Puts a batch of objects: snapshots, revisions and statements, diff --git a/crates/origin-shared/src/api.rs b/crates/origin-shared/src/api.rs index 42120b7a..33b04b8b 100644 --- a/crates/origin-shared/src/api.rs +++ b/crates/origin-shared/src/api.rs @@ -108,15 +108,17 @@ pub const MORE: &str = "origin-more"; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)] pub struct FetchRecords { /// The records, returned in this order, each followed by its - /// attachment. A response that stops short, with the [`MORE`] header, - /// holds those up to the last record it has: ask again for those after - /// it. + /// attachment. Those the caller may not read are left out. A response + /// that stops short, with the [`MORE`] header, holds those up to the + /// last record it has: ask again for those after it. pub ids: Vec, } /// Asks for the objects of a snapshot that the caller lacks: its trees and /// blobs, walked from its root. This is the only way blobs and trees leave -/// a repository, so what each caller may read can be checked by path. +/// a repository, so what each caller may read is checked by path: the +/// content of paths they may not read is withheld, though it keeps its +/// place in the trees. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)] pub struct FetchSnapshot { /// The record whose snapshot it is: a revision or an acceptance. Only a diff --git a/docs/openapi.json b/docs/openapi.json index a3924aa9..a018e732 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -29,7 +29,7 @@ }, "/api/v1/repos": { "get": { - "summary": "Lists the repositories on the server.", + "summary": "Lists the repositories on the server that the caller sees.", "operationId": "list_repos", "responses": { "200": { @@ -1354,13 +1354,13 @@ "items": { "$ref": "#/components/schemas/ObjectId" }, - "description": "The records, returned in this order, each followed by its\nattachment. A response that stops short, with the [`MORE`] header,\nholds those up to the last record it has: ask again for those after\nit." + "description": "The records, returned in this order, each followed by its\nattachment. Those the caller may not read are left out. A response\nthat stops short, with the [`MORE`] header, holds those up to the\nlast record it has: ask again for those after it." } } }, "FetchSnapshot": { "type": "object", - "description": "Asks for the objects of a snapshot that the caller lacks: its trees and\nblobs, walked from its root. This is the only way blobs and trees leave\na repository, so what each caller may read can be checked by path.", + "description": "Asks for the objects of a snapshot that the caller lacks: its trees and\nblobs, walked from its root. This is the only way blobs and trees leave\na repository, so what each caller may read is checked by path: the\ncontent of paths they may not read is withheld, though it keeps its\nplace in the trees.", "required": [ "of" ],