# Signed records

> How Osevel decides who may do what with signed records instead of trusting its cloud: the log, device enrolment, approvals and proofs.

Source: https://osevel.com/docs/security/signed-records/

Who may do what in an organization is decided by **signed records**,
not by our cloud. This page is the reference for their format and rules; the code is
`packages/protocol/src/records.ts` (format, rules, verification) and
`packages/bridge/src/records.ts` (the bridge's pinned copy).

## The log

An organization has one append-only log. Each record:

```json
{
  "record": {
    "v": 1,
    "organization": "<uuid>",
    "seq": 7,
    "prev": "<hex SHA-256 of record 6>",
    "at": "2026-11-19T10:07:00.000Z",
    "signer": "<device id>",
    "body": { "type": "role.assign", "...": "..." }
  },
  "signature": { "<WebAuthn assertion JSON>": "..." }
}
```

- `digest(record) = SHA-256("ar-record-v1" ‖ 0x00 ‖ UTF-8(JCS(record)))`. It is the record's id,
  the next record's `prev`, and the WebAuthn challenge the signer's passkey signs (with user
  verification, for the device's pinned origin and RP ID). The label keeps a record signature
  from ever being mistaken for an action or unlock signature.
- Record 1 is the **genesis**: it names the root device (the first owner's passkey) and is
  signed by it. `prev` is 64 zeros.

## Record types

| Type              | Body                                                                                | Who may sign it                                                                                                   |
| ----------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `genesis`         | root device key, label                                                              | the root device itself (record 1 only)                                                                            |
| `member.add`      | member (account id), label                                                          | `members.manage`                                                                                                  |
| `member.remove`   | member                                                                              | `members.manage`; never the last owner with a device                                                              |
| `device.enrol`    | device key (id, member, COSE key, origin, …)                                        | `members.manage`; device and credential ids are never reused                                                      |
| `device.remove`   | device id                                                                           | `members.manage`, or the device's own member; never the last owner device                                         |
| `device.reset`    | device id                                                                           | `members.manage`, another member's device; with more than one owner it waits for `device.reset.approve`; voids that member's signatures on strong actions not cancelled |
| `device.reset.approve` | device id                                                                      | an owner other than the one who asked                                                                              |
| `team.put`        | team, parent, name                                                                  | `teams.manage`; no cycles, at most 8 levels                                                                       |
| `team.remove`     | team (sub-teams go with it)                                                         | `teams.manage`                                                                                                    |
| `team.member`     | team, member, lead (or null: removed)                                               | `teams.manage` or a lead of the team or above; making a lead needs one above                                      |
| `project.team`    | project, owning team                                                                | `project.manage`                                                                                                  |
| `role.assign`     | subject (member or team), resource, role                                            | see below                                                                                                         |
| `role.revoke`     | the same triple                                                                     | as `role.assign`; the last owner stays                                                                            |
| `policy.set`      | project, database, approval policy                                                  | `database.manage` on that database                                                                                |
| `client.enrol`    | IDE client key (device id, member, X25519), code                                    | `members.manage`; a client never signs records                                                                    |
| `client.remove`   | device id                                                                           | `members.manage`, or the client's own member                                                                      |
| `phone.enrol`     | phone (device id, member, P-256 signing key, X25519 channel key, attestation), code | `members.manage`; one phone per member, a new one retires the old; a phone never signs records alone (Security 3) |
| `phone.remove`    | device id                                                                           | `members.manage`, or the phone's own member                                                                       |
| `agent.bind`      | project, database, agent, member                                                    | `agent.manage` on that database                                                                                   |
| `agent.unbind`    | project, database, agent                                                            | `agent.manage` on that database                                                                                   |
| `bridge.key`      | connector id, the team bridge's static key                                          | `members.manage`                                                                                                  |
| `security.set`    | lock and session settings (Security 1, below)                                       | `org.manage` (owners); the activity log scope can only grow                                                       |
| `release.propose` | id, target (`panel` or `connector`), version, digest                                | `org.manage` (owners); the proposer's signature counts as the first; a refused digest cannot be proposed          |
| `release.sign`    | proposal id                                                                         | `org.manage`; another owner than those who signed it                                                              |
| `release.refuse`  | target, digest                                                                      | `org.manage`; the digest never takes effect, not even as a critical fix                                           |

**Lock and session settings** (`security.set`, Security 1): idle lock 30 s to 15 min (default
90 s, it cannot be turned off), session length 15 min to 12 h (default 4 h), whether unfinished
work is discarded on lock, the roles that unlock only with a hardware security key, the root
certificates the organization trusts for hardware key attestations (DER, base64url, at most 8;
required when a role needs a hardware key) and what the activity log records beyond its floor
(`panel.write`, `panel.read`; once on, never off). Every bridge follows the latest one; before
any, the defaults apply. A device enrolled with `device.enrol` may carry its registration's
attestation (`attestation{object, clientData}`); a bridge counts it as a hardware key only when
that `packed` attestation is for this very credential and chains to a trusted root.

**Releases** (`release.*`, Security 2 §6): a build or release is accepted when two different
owners signed its proposal, or, in an organization of one member, when that member's phone
confirmed the proposal. See [pinned panel and connector releases](https://osevel.com/docs/security/pinned-releases/).

Resources are the organization, a project, or `project/database`. Roles are owner, admin,
developer and viewer with the permissions of the Phase 5 design (§6).

**Giving a role.** An owner may give any role anywhere (on a restricted database this is
reported to everyone who reads the log). Anyone else needs `roles.assign` on that resource and a
role at least as high as the one given; only an owner gives `owner`. A lead of the team that
owns a project may give up to `developer` on it.

**Effective access.** Assignments add up, there are no deny rules. A role on the organization or
a project flows to its databases; an assignment to a team reaches the members of its sub-teams.
A **restricted** database takes nothing by inheritance, the owner included: only assignments
made directly on it count. `effectiveRole` returns the role and the record it comes from.

## Enrolling a device

1. The new device (signed in as the member) creates its passkey and posts a **commitment**:
   `hex(SHA-256("ar-enrol-commit-v1" ‖ 0 ‖ JCS(device key) ‖ nonceDevice))`.
2. An admin's panel adds a random **nonceAdmin**.
3. The device reveals its key and nonceDevice; the cloud checks them against the commitment.
4. Both screens show `enrolCode`: 8 digits from
   `SHA-256("ar-enrol-code-v1" ‖ 0 ‖ JCS(device key) ‖ nonceDevice ‖ nonceAdmin)`. The two
   people compare them over a call or in person. Only if they match does the admin sign
   `device.enrol` with that digest as `code` (a record without it is refused).

The device committed before it saw the admin's nonce, so whoever relays the ceremony cannot
choose a key whose code matches (one chance in 10^8, and a failed comparison is seen).

**Lost devices** are removed with `device.remove` (an admin, or the device's own member). **When
every admin device is lost**, a cloud admin clears the log, the owner posts a new genesis from a
new device, and every bridge must be re-pinned at its terminal (`org pin --replace`): until then
it keeps working from the log it pinned.

## Verification on the bridge

1. `osevel org pin` (terminal): the human compares the genesis fingerprint with the one
   the owner's panel shows, and confirms with the code. Only then is the genesis pinned.
2. `osevel org sync`: the bridge fetches the log from the cloud and verifies every record
   in order: shape, sequence, chaining, date (not more than 10 minutes ahead of the bridge's
   clock, nor before the previous record by more than that), signer enrolled and not removed at
   that point, signature, and permission.
3. **A record its signer may not make takes no effect** (work package 14). A record that is
   well formed, chained and correctly signed by an enrolled device, but that its signer was not
   allowed to make at that point (or that does not apply, such as removing the last owner), is
   **skipped**: it changes nothing, the bridge reports it (`[records] ignored: …` and a notice in
   the panel), and the log goes on. Before, it stopped the log, so one enrolled member could
   freeze the whole organization with a single bad record. Shape, order, chaining, time, signer
   and signature failures still stop the log: those mean the log itself is not trustworthy.
4. **No rollback.** The bridge keeps the sequence and digest it accepted last. A log that is
   shorter (`rollback`) or does not contain it (`fork`) is refused, so the cloud cannot hide a
   removal by serving an older log.

The pin and the accepted log are kept in `bridge/records.json`, authenticated with the bridge's
integrity key. The cloud stores the log (`organization_records`). Since work package 14 it also
verifies each new record against the whole log before storing it (signature, chaining, signer
and permission, with every database counted as not restricted, which only ever allows more) and
answers `400 RECORD_REFUSED` otherwise, so the log stays clean. Its verdict decides nothing for a
bridge, which verifies everything itself.

## Signing in the panel (work package 14)

The panel signs records with the passkey of one of its pairings: the pairing keeps the passkey's
COSE public key (read from the registration's attestation object), so the same passkey can be the
organization's root device or an enrolled one. For every record the panel:

1. fetches the log and **verifies it in the browser** (WebCrypto: ES256, EdDSA, RS256, the same
   checks as the bridge) against the genesis this browser pinned (when it started the records, or
   after a human compared the fingerprint);
2. **dry-runs** the record on the verified state: a record that would be skipped never reaches the
   passkey prompt;
3. asks for **one passkey gesture** over the record's digest, checks the signature itself, and
   posts it. If another record took the place first, it starts again (a new gesture).

What the panel offers: starting the records (genesis), registering a team bridge (`bridge.key`,
with the key the pairing checked at the terminal), adding and removing members, copying cloud
teams with their members and leads, giving and taking back roles, the approval policy, a
project's owning team, and asking for, signing and cancelling strong actions. Device enrolment of
a second member's browser is the ceremony above.

## What a lying cloud can and cannot do

- Alter, reorder, invent or drop a record in the middle: refused (signature, chain, signer).
- Drop the newest records: refused once the bridge has seen them (rollback); before that, the
  bridge works from what it has, and a change the cloud withholds does not take effect.
- Serve another organization's log: refused (pinned genesis).
- Withhold the log entirely: no new records are accepted (work package 9 decides how long a
  team bridge keeps working on its last verified log).

## Decisions on requests (approvals)

A team bridge applies the database's approval policy before it records a signed decision
(`packages/protocol/src/approvals.ts`):

- **Approvers**: the `policy.set` record's members and teams (a team reaches its sub-teams).
  Without one: developers and above on `dev`, `staging` or unlabelled databases; nobody on `prod`
  (a terminal can always decide).
- **Self-approval**: the member the agent is bound to (`agent.bind`) may not approve where
  self-approval is off, and never on `prod`.
- **Approvals needed**: the larger of the database setting (journal v11) and the policy. The
  database itself counts the proofs (journal v12) before it lets the bridge approve.
- **Escalation**: unanswered past the escalation time, a request goes to the leads of the
  project's team, then each team above, then the owners; past the owners it is rejected.

Every dashboard decision is stored with its proof (member, device, statement digest, WebAuthn
assertion) in `agent_reverse.approval_proofs`, for audits.

## Checking the proofs later (work package 15)

Every decision made through the panel can be checked again, independently of the bridge that
made it (design §9 "Proof"):

- The team bridge mirrors the records it verified into each enabled database (`record_log`,
  journal v14): appended only by its remote role, in order and chained, never changed.
- Every dashboard decision keeps, with its proof, the **statement** its signer signed (not only
  its digest), so a check can tell that a signature was made for this request and no other.
- `osevel audit proofs [--days n]` (terminal) and the `audit_proofs` tool of auditor agents
  read these through the auditor role and check: the records verify; each proof's statement has
  the stored digest, names this request, this decision and (approve) its SQL digest; the passkey
  signature verifies for a device the records had enrolled, for that member, at that time; an
  approved request had valid approvals from as many different members as the database needs;
  each strong decision was asked for and signed in its records by enough members (two on prod),
  was not cancelled, and applied what was signed. The command exits 1 on any violation.
- Proofs from before journal v14 (no statement) and decisions on an individual's bridge (devices
  paired at its terminal, not in signed records) are reported as warnings: their signatures
  cannot be tied to a request or a device here.

The auditor role sees the signed statements only through the check: auditor agents get its
verdicts and findings, never the statements themselves.
