# Team bridge

> One always-on Osevel bridge for a team, in its own cloud account or on a member's machine, with roles and approval rules.

Source: https://osevel.com/docs/guides/team-bridge/

A team runs **one bridge** where it is always on and can reach its
databases: a small container in the team's own cloud account, or a member's machine for a very
small team. We host no bridge. The team bridge holds the database credentials, enforces every
rule, keeps one outbound connection to our cloud, and serves the team's agents.

An individual needs none of this: a local install without an organization keeps working as
before, with or without our cloud.

## Set it up

From the repository root:

```bash
docker compose -f deploy/team-bridge/compose.yaml build
```

Then, at the container's terminal (each step is done by a person; nothing here can be done from
the panel):

```bash
docker compose -f deploy/team-bridge/compose.yaml run --rm bridge osevel init
```

```bash
docker compose -f deploy/team-bridge/compose.yaml run --rm bridge osevel projects move <database> <project> --create
```

```bash
docker compose -f deploy/team-bridge/compose.yaml run --rm bridge osevel connect pair <code> --server https://<cloud>
```

The pairing code comes from the panel of a cloud admin of the team organization (pair "for this
organization"), so the connector belongs to the organization.

```bash
docker compose -f deploy/team-bridge/compose.yaml run --rm bridge osevel org pin
```

`org pin` shows the fingerprint of the organization's first signed record; pin only if the
owner's panel shows the same one ([signed records](https://osevel.com/docs/security/signed-records/)).

```bash
docker compose -f deploy/team-bridge/compose.yaml run --rm bridge osevel connect enable <database>
```

```bash
docker compose -f deploy/team-bridge/compose.yaml up -d
```

The bridge does not start without disk encryption, and from inside the container it cannot see
the disk. Put the `bridge-data` volume on an encrypted disk, then state it by uncommenting
`OSEVEL_DISK_ENCRYPTION: host` in `compose.yaml`. The statement is written to the log at every
start. The compose file also turns core dumps off.

The bridge also needs its **master key**: 32 random bytes (base64) in a file the organization's
key service mounts into the container, named by `OSEVEL_MASTER_KEY_FILE` (see `compose.yaml`).
Every password file in `/data` is sealed with it; without it the bridge does not start. Losing
the key loses the passwords: keep it in the key service, not next to the volume.

The image sets `OSEVEL_ISOLATION=container`: agents never get a shell inside it, so its store
may hold a database labelled `prod`. On a member's own machine a `prod` database must be in
daemon mode.

The container runs `osevel daemon run`: the agents' socket and the bridge. Its state is
in the `/data` volume (role passwords in 0600 files, the bridge's keys, the pinned
organization): back it up like a password store. The image runs as an unprivileged user with a
read-only root filesystem and no capabilities.

## Members' browsers

Only the first owner pairs a browser at the bridge's terminal. Everyone else enrols a browser in
the panel (Organization → Signed records → **Enrol this browser**) and compares an 8-digit code
with an admin, who signs the enrolment. The enrolled browser then reaches every team bridge whose
key is in the records (the owner registers each bridge once, from the pairing they checked at its
terminal). See [signed records](https://osevel.com/docs/security/signed-records/).

## Records

The running bridge fetches the organization's signed records every minute and accepts them only
when they verify back to the pinned genesis (no rollback). Records that do not verify are
reported in its log and not used; the bridge keeps working from the last verified ones.
`osevel org show` lists members, devices and role assignments; `connect status` shows the
team bridge's state.

## When the cloud cannot be reached

Agents on the bridge's host keep database access. What needs the cloud stops by itself: new
records (removals, role changes), approvals through the panel, IDE channels through the relay,
and grants of our LLM service.

`osevel connect offline` sets what happens to agents' **writes** (a strong action, at the
terminal, with the code):

| Policy            | Writes                                                        |
| ----------------- | ------------------------------------------------------------- |
| `timed` (default) | go on under the last verified records for 24 hours, then stop |
| `timed --hours N` | the same with N hours (1-720)                                 |
| `stop`            | stop as soon as the cloud is unreachable                      |
| `continue`        | never stop (removals made meanwhile do not reach the bridge)  |

Reads always go on. A verified record sync is what counts as contact; the last one is kept in an
integrity-protected file, and a tampered file counts as no contact (writes stop). A write that
is stopped is not sent to the database; the agent is told why.

## Where the team's local agents run

`osevel connect agents-on bridge|member`, chosen at setup:

- `bridge` (default): on the bridge's host, in the sandbox, next to the credentials (the host
  needs Docker).
- `member`: on members' machines, reaching the databases through the bridge over the encrypted
  relay (work package 10); the credentials never leave the bridge.

## IDE on a member's machine (through the relay)

A member's IDE can run an agent against the team's databases without the credentials ever
leaving the bridge:

1. In the panel the member creates a **client token** for their machine.
2. At their own terminal: `osevel client setup --server https://<cloud>`. It asks for the
   token, shows the fingerprint of the organization's first signed record (compare it with the
   panel), then shows an 8-digit code: an admin compares it in their panel and signs the
   enrolment (`client.enrol`).
3. An admin (anyone with `agent.manage` on the database) binds the agent to the member
   (`agent.bind`), and the team bridge's static key is in the records (`bridge.key`).
4. The IDE runs `osevel mcp --remote --project <project>/<database>` with the agent's
   token in `OSEVEL_AGENT_TOKEN`.

The thin client takes the bridge's key and its own enrolment only from the verified records,
opens a Noise KK channel through the relay (the cloud sees ciphertext), and the bridge serves
the session only for an agent bound to the client's member. A token copied to another machine
or used from another member's client is refused; a client removed by a record loses its
channels at the next sync. IDE prompts cannot approve through this channel (approve at a
terminal or in the panel). Limit: an agent with a shell as the member's OS user can read the
client's key file (`<config>/client.json`, 0600); daemon mode on the member's machine closes it.

## Strong actions from the panel

Some actions used to be terminal-only: approving a request the executor marks terminal-only,
raising an agent's access, raising a database's protection. On a team bridge they can be asked
for in the panel, with these protections (design §8):

| Protection               | How                                                                                   |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Device signature         | every request and co-signature is a signed record (a passkey gesture)                 |
| Two signatures on `prod` | two different members, each with the right for that action when it runs               |
| Independent notification | the bridge posts to the team's webhook directly (`connect notify <https-url>`)        |
| Waiting period on `prod` | runs only after `connect strong-wait` minutes (default 30); anyone with a say cancels |

Lowering protection (a lower label, fewer approvals, not restricted) stays at the terminal.

### The database decides (journal v13)

From journal v13 the bridge no longer decides by itself. It records each strong decision in the
database with its proof, as the `strong` role, and asks the database to apply it. The database
refuses (`AR011`) until it may:

| Mode (`database strong-mode`) | A decision applies                                                              |
| ----------------------------- | ------------------------------------------------------------------------------- |
| `locked`                      | never: strong actions stay at the terminal                                      |
| `wait` (default)              | on prod after `--wait` minutes by the database's clock, while the watcher lives |
| `witness`                     | as `wait`, and only after the witness checked the proof itself                  |

The watcher is a second program on **another machine**, holding only the `watch` credential:

```bash
osevel watcher export --project <database> --out watcher.json
```

```bash
osevel watcher run --config watcher.json
```

`export` removes the watch password from the bridge host; move the file away (or run
`deploy/watcher/compose.yaml` there). Every interval the watcher gives the database a sign of
life (on prod, no recent sign means strong decisions wait), posts each pending decision to the
team's webhook directly, and in `witness` mode verifies the proof from the genesis it pinned: the
signed request, its exact payload, and enough signatures from members with the right. A decision
that does not hold is cancelled and reported. `watcher cancel --config watcher.json <id>` stops
one by hand. A stolen bridge alone therefore cannot shorten the wait, skip the witness, or apply
anything the members did not sign.

### A panel you host yourself

`osevel connect pin-origin https://panel.team.example` makes the bridge accept devices,
unlocks, approvals and strong-action signatures only from passkeys made on your own panel's origin,
so no page we serve can act for the team. See [self-hosted-panel.md](https://osevel.com/docs/guides/self-hosted-dashboard/).

### Panel version and connector releases

The owners decide which panel build members run and which connector release the bridge starts
(Organization → Signed records → **Panel version**). The bridge checks the served panel every 5
minutes and answers no panel while it is not the signed build; `osevel daemon run` does not start
a connector release the owners did not accept. See
[pinned panel and connector releases](https://osevel.com/docs/security/pinned-releases/).

## Foreign connections (Security 6)

The bridge container runs `osevel daemon run`, so it also runs the foreign connection watch for
every database it holds: a round every 5 seconds in which the database itself cuts each session
that osevel did not open and that is not a known client. Switch it on once per database at the
bridge's terminal, after the app and tools that use the database are connected:

```
docker compose run --rm bridge osevel connections on --project <database>
```

It lists what is connected now and declares each client for its role, address and program.
Declare a new client before it connects (`osevel connections trust <role> --from <network>
--app <program>`); `osevel connections events` shows what was cut. With a team channel set
(`osevel connect notify <url>`), every cut is also posted there. See
the design.
