Skip to content

Confidential Docs

Confidential Docs is a document store: one database of collections, queried with MongoDB’s filter, update and aggregation language. Every answer passes the policy the data’s owner set, field by field. It is for applications built on MongoDB’s data model that need to keep documents out of everyone’s reach but their own services and the people they choose. It is the package com.calimero.confidential-docs.

  • Neither the developer nor Calimero can read the data or change the code. The store declares upgrades = "owner": only an owner or admin of its organization upgrades it.
  • servicesOnly collections keep the owner out too. Only the API keys and apps a person grants read their documents. The owner keeps the collection’s policies, admins and audit log, and sees names, index paths and counts, never a value. A collection is made servicesOnly once, when it is created, and never changes, so nobody turns it off to read what was written under it.
  • Policies mask where a document is decoded. A denied path is removed and a hashed one replaced by its keyed hash before your filter, sort or pipeline runs, and a request that names a hidden path is refused (ProtectedField) rather than answered empty.
  • Only people change access. Setting policies, granting collection admins and dropping a collection need a passkey, and every change is in the audit log.

This holds within the cluster’s rules: whoever approves the cluster’s node images decides which code may run. See the security model.

Term What it is
Store One instance: one database of collections, with its own policies and audit log.
Collection Documents, their indexes and their policies. Either ordinary or servicesOnly.
Policy What one principal may do on one collection: account:, key:, app:, team: or role:. On a servicesOnly collection, only key: and app:.
Collection admin A person (an account, team or role) the owner names on one collection. It manages the collection’s policies, and reads it only through a policy of its own.
Index On one field or several, ascending or descending, optionally unique, TTL, sparse or partial. Your app’s code creates them.

A policy:

{
"level": "documents", // documents | aggregates | noisy | none
"fields": { // unlisted paths: deny, including later ones
"_id": "hash",
"patient": "allow",
"patient.name": "deny", // the longest listed path wins
"visits.$.date": "allow" // $ = every array element
},
"filter": "{\"patient.region\": \"eu\"}", // Extended JSON over raw values
"minGroup": 10, "write": false, "keys": false, "via": ["app:<id>"],
"unlisted": "allow", // the rule of paths `fields` does not cover (absent: deny)
"schema": true // createIndex / dropIndex with no passkey
}
  • Levels. documents reads documents; aggregates allows only a pipeline of $match, then $group ($sum, $avg, $count), then $sort, $limit, $skip or $project, with groups of at least minGroup; none reads nothing.
  • One policy applies, never a union. On a servicesOnly collection only a key’s or app’s own policy. Elsewhere the owner reads everything; a person gets their account’s policy, else their team’s, else their highest role’s; an API key its own, else its account’s when that says keys: true; a person through an app only their own, where via lists the app.
  • A store an app creates is the app’s. When your app’s release uses the store with mode = "create", every collection it makes is servicesOnly by default and gives your app a full policy. No person gets one.
  • find, count, explain and aggregate with MongoDB’s filter semantics, including $regex (without backreferences or lookaround), Decimal128 and ISO-8601 $date strings.
  • insert, update, delete, findAndModify and bulkWrite, with positional paths ($, $[], $[<id>]) and arrayFilters.
  • Cursors for paging, and retryable writes: send the same retryId with the same request within 30 minutes and you get the first answer again, with nothing written twice.
  1. In the console, open Document stores under Services and press New document store. Pick the cluster and who it is for, and confirm with your passkey.
  2. Make a collection, choosing whether it is services-only, and set its policies with your passkey.
  3. On Connect, make an API key with its policy on a collection, and copy the code that uses it. Ask for schema too if your app creates its indexes at startup.
  4. Browse and edit documents of collections that are not services-only on the store’s page, in your own session.

From code, with mero-js or any Calimero client:

import { CalimeroClient } from '@calimero-network/mero-js';
// reads the cluster's nodes, then attests each against this policy before using it
const client = await CalimeroClient.connect({
cluster: '<cluster>',
policy: { release: { minReleaseVersion: '<release>' } },
});
client.useApiKey(process.env.CALIMERO_API_KEY);
const store = process.env.CALIMERO_DOCS_STORE;
// documents and filters are Extended JSON text; every answer passes this key's policy
await client.apps.call({ app: store, method: 'insert', args: { collection: 'orders', documents: [JSON.stringify({ region: 'eu', total: 120 })] } });
const { result } = await client.apps.view({ app: store, method: 'find', args: { collection: 'orders', filter: '{}', limit: 10 } });
console.log(result.documents.map((d) => JSON.parse(d)));
// at startup, the indexes this app reads through; the same index again changes nothing
await client.apps.call({ app: store, method: 'createIndex', args: { collection: 'orders', name: 'by_region', keys: '{"region": 1}' } });
Limit Value
find page Up to 10,000 documents (batchSize) and 384 KiB stored; answers stop at 512 KiB
aggregate page 1,000 rows by default, 10,000 at most
bulkWrite 1,000 operations in one call
Documents one request holds 10,000 by default (interactiveDocLimit at create)
Retryable writes 30 minutes; per caller 10,000 records and 16 MiB of answers

Each request has a work budget covering documents read, bytes decoded, values hashed and the answer’s size. A request past it is refused with TooLargeForInteractive, never cut short: filter or sort on an indexed field, or page with the cursor. A store needs nodes on merod 1.0.0-rc.38 or later.

A store is billed as any app instance: its calls, views, compute and state on a shared cluster, or within the flat fee of a dedicated cluster. See Products → Pricing.