Skip to content

Confidential SQL

Confidential SQL is one dataset of SQL tables in which every caller reads through its own policy: a column shown, hashed or hidden, rows filtered, or aggregates only. It is for teams that let analysts, partners or services query sensitive data without handing them the raw rows. It is the package com.calimero.confidential-sql, and runs SQLite 3.54 compiled into the app.

  • Neither the developer nor Calimero can read the data or change the code. The app declares upgrades = "owner": only an owner or admin of its organization upgrades it.
  • The policy is applied where a row is read from storage, before SQLite sees a value: a denied column decodes as NULL, a hashed one as its keyed hash, and rows outside the row filter are dropped. A statement that names what the policy hides is refused rather than answered empty.
  • Hashes are keyed. A hash column shows HMAC-SHA256 of the value under the dataset’s own key, which is created inside the app and never returned, so nobody can test guesses against it.
  • Only people change access. Setting policies, granting table admins and running DDL need a passkey, and every access 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
Dataset One instance: its tables, policies, admins and audit log.
Store admins The owner, plus accounts the owner adds. They see every table in full and manage tables, policies and table admins.
Table admin An account, team or role a store admin names on one table. It manages that table’s policies, and reads it only through a policy of its own.
Policy What one principal (account:<id>, key:<api key id> or app:<app id>) may do on one table.
Table-creation grant A name prefix a store admin gives a principal, so it can create its own tables (createTable) without a passkey, for example from df.to_sql() with an API key.

A policy:

{
"level": "rows", // rows | aggregates | noisy | none
"columns": { "patient_id": "hash", "region": "allow", "age": "allow" }, // unlisted: deny
"rowFilter": "region = 'eu'", // raw values, evaluated in storage
"minGroup": 10, // aggregates
"write": false, // execute, inside rowFilter
"keys": false, // on account:<id>: also that account's API keys
"via": ["app:<dashboard id>"] // on a person: also through these apps
}
  • Levels. rows reads rows; aggregates allows only COUNT, SUM, AVG, TOTAL and GROUP BY keys, and adds HAVING COUNT(*) >= minGroup to every query; none reads nothing. noisy is refused for now.
  • Columns. allow, hash or deny; an unlisted column is denied. A hashed column can be compared only with another hash, never ordered or compared with a raw value.
  • One policy applies, never a union. A person in person gets their account’s policy; an API key its own, else its account’s when that says keys: true; an app its own; a person through an app only their own, and only if via lists that app. A table the caller has no policy on answers NoSuchTable, as if it did not exist.
  1. In the console, open SQL under Services and press New SQL instance. Pick the cluster and who it is for, and confirm with your passkey.
  2. On the Tables tab, create tables (CREATE TABLE, with your passkey).
  3. On the Access tab, set each table’s policies and table admins.
  4. On the Connect tab, make an API key with a policy on one table in one passkey prompt, and copy the code that queries with it. The Query tab runs a statement as you.

From code, a query is a view of the instance and a write is a call, 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 { result } = await client.apps.view({
app: '<instance-id>',
method: 'query',
args: { sql: 'SELECT region, COUNT(*) FROM claims GROUP BY region' },
});
// result: { columns, rows, truncated, next }
Method What it does
query(sql, params?, limit?, cursor?) One read-only statement; a page of rows and next when more follow
execute(sql, params?) One INSERT, UPDATE or DELETE under a policy with write
insertRows(table, columns?, rows) Typed rows without SQL text
deleteRows(table, condition?, limit?, cursor?) Deletes larger than one call, a slice at a time
analyze(sql, params?) A statement past the interactive limit, answered in a compute run
tables(), describe(table) What the caller may see, each column with the caller’s rule

Parameters and cells are tagged values, such as { "int": "42" } or { "text": "eu" }. SQLite supports CTEs, window functions, UPSERT and joins.

A statement that reads more rows than one interactive query may is refused with TooLargeForInteractive. Send it to analyze instead: each table it reads is snapshotted with your policy already applied, so neither hidden values nor their order reach the job node, and the statement runs there. analysis(id) shows its state and, when they fit, its rows; fetchAnalysis(id) gives the requester alone a 15-minute download of the answer file.

Limit Value
Interactive query 4,000 rows read by default (interactiveRowLimit at create)
Page of query 1,000 rows
insertRows 2,000 rows a call, fewer when the call’s 1 MiB log entry fills first
Analysis 64 snapshot segments: about 960,000 rows with nothing hashed, 150,000 under a policy that hashes three values a row
Analysis rows shown by analysis(id) Up to 48 KiB; larger answers download with fetchAnalysis

ALTER TABLE makes one change a statement and rewrites every row in the call, so a table past one call’s writes cannot be altered. Indexes are on one column each. An instance needs nodes on merod 1.0.0-rc.39 or later.

An instance 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.