Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(storage): allow the migration ledger through grant validation

Steven Enamakele8400597f8b0
diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas.rs b/crates/openhuman-core/src/modules/storage_grant_schemas.rs
index b5b806d61f..91dc831b63 100644
--- a/crates/openhuman-core/src/modules/storage_grant_schemas.rs
+++ b/crates/openhuman-core/src/modules/storage_grant_schemas.rs
@@ -168,7 +168,7 @@ pub(super) fn grant_for(module_id: &str) -> Option<StorageGrant> {
fn migration_collections(owner: &str) -> Vec<CollectionSpec> {
match owner {
"mcp" => [
- "tsd.migrations",
+ super::storage_grants::MIGRATION_LEDGER,
"mcp_servers",
"mcp_server_names",
"mcp_registry_cache",
diff --git a/crates/openhuman-core/src/modules/storage_grants.rs b/crates/openhuman-core/src/modules/storage_grants.rs
index f68fd4bbb9..e982554948 100644
--- a/crates/openhuman-core/src/modules/storage_grants.rs
+++ b/crates/openhuman-core/src/modules/storage_grants.rs
@@ -139,6 +139,12 @@ const RESERVED_COLLECTIONS: [&str; 1] = [tinystoragedrivers::secrets::DEFAULT_CO
/// A module reaches the queue collections only through the `Queues` object.
const RESERVED_COLLECTION_PREFIX: &str = "tsd.";
+/// The one `tsd.` collection a module may hold: the progress ledger its own
+/// first-open migration keeps, one row per owner, item and step. It sits in the
+/// module's own scope, so it exposes no other module's data, and a forged row
+/// can only skip a step of that module's own migration.
+pub(super) const MIGRATION_LEDGER: &str = "tsd.migrations";
+
impl StorageGrant {
/// The schema the host ensures when it binds the module.
pub fn specs(&self) -> &[CollectionSpec] {
@@ -156,7 +162,8 @@ impl StorageGrant {
for spec in &self.collections {
if spec.name.is_empty()
|| spec.name.starts_with('_')
- || spec.name.starts_with(RESERVED_COLLECTION_PREFIX)
+ || (spec.name.starts_with(RESERVED_COLLECTION_PREFIX)
+ && spec.name != MIGRATION_LEDGER)
|| RESERVED_COLLECTIONS.contains(&spec.name.as_str())
{
return Err("a granted collection name is empty or reserved".into());
diff --git a/crates/openhuman-core/src/modules/storage_grants_tests.rs b/crates/openhuman-core/src/modules/storage_grants_tests.rs
index 0eeecf1cf0..adca863dbe 100644
--- a/crates/openhuman-core/src/modules/storage_grants_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_grants_tests.rs
@@ -624,3 +624,15 @@ fn the_selectors_added_to_the_wire_keep_the_grants_prefixes_and_read_only_rule()
)
.is_ok());
}
+
+#[test]
+fn only_the_migration_ledger_may_be_granted_from_the_storage_layers_namespace() {
+ let with = |name: &str| StorageGrant {
+ collections: vec![CollectionSpec::new(name)],
+ ..grant()
+ };
+ assert!(with("tsd.migrations").validate().is_ok());
+ for reserved in ["tsd.queue", "tsd.leases", "tsd.kv", "tsd.migrations2"] {
+ assert!(with(reserved).validate().is_err(), "{reserved}");
+ }
+}