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.
Why it’s confidential
Section titled “Why it’s confidential”- 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. servicesOnlycollections 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 madeservicesOnlyonce, 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.
Core concepts
Section titled “Core concepts”| 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.
documentsreads documents;aggregatesallows only a pipeline of$match, then$group($sum,$avg,$count), then$sort,$limit,$skipor$project, with groups of at leastminGroup;nonereads nothing. - One policy applies, never a union. On a
servicesOnlycollection 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 sayskeys: true; a person through an app only their own, wherevialists the app. - A store an app creates is the app’s. When your app’s release
usesthe store withmode = "create", every collection it makes isservicesOnlyby default and gives your app a full policy. No person gets one.
What it supports
Section titled “What it supports”find,count,explainandaggregatewith MongoDB’s filter semantics, including$regex(without backreferences or lookaround), Decimal128 and ISO-8601$datestrings.insert,update,delete,findAndModifyandbulkWrite, with positional paths ($,$[],$[<id>]) andarrayFilters.- Cursors for paging, and retryable writes: send the same
retryIdwith the same request within 30 minutes and you get the first answer again, with nothing written twice.
Use it
Section titled “Use it”- 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.
- Make a collection, choosing whether it is services-only, and set its policies with your passkey.
- On Connect, make an API key with its policy on a collection, and copy the code that uses it. Ask for
schematoo if your app creates its indexes at startup. - 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 itconst 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 policyawait 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 nothingawait client.apps.call({ app: store, method: 'createIndex', args: { collection: 'orders', name: 'by_region', keys: '{"region": 1}' } });Limits
Section titled “Limits”| 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.
Pricing
Section titled “Pricing”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.
Further reading
Section titled “Further reading”- Confidential SQL: the same policy model for SQL tables
- Confidential KV: keys and values, with
servicesOnlyand private buckets - Call it from code
- Security model