# RBAC - the reads the engine makes for a caller

> This page is section 5.3 of [rbac.md](/v/2.2.5/dfe-engine/control-plane/rbac.md), kept under that number so section references resolve.

## 5.3 Row reads for a caller

The query API does not lean on a ClickHouse user for tenancy: the executor injects the caller's `org_id` as a reserved bind parameter that a client cannot override (`src/dfe_engine/query/executor.py`, `RESERVED_PARAMS`).

The row reads the engine makes for a caller with no platform grant -- the sampler, the transform dry run, and the schema routes `sample-rows`, `json-paths` and `promote-field` -- bind `_org_id` to the tenant ids of the registered orgs a grant holding the read's action reaches (`api/deps.py::held_orgs`). Those are the ids each org's pinned user holds (`src/dfe_engine/orgs/tenant_scope.py`). A grant bound at an org's scope reaches that org. A tenant role bound system-wide (`org_viewer`, or a `scoped` role) reaches the orgs its group lists and none another of the caller's groups lists, as its group's ClickHouse user does.

The sampler, `/operations`, `sample-rows` and `json-paths` accept that action at system scope or at one of the caller's orgs. `promote-field` changes a source every org shares, so it still needs `schema:write` at system scope. Each org marker the caller holds resolves the way a group's does (`resolve_orgs`): by name, or failing that by the one org declaring it as a tenant id. A marker no org declares, or a tenant id two orgs share, binds nothing. A caller left with no tenant id, or a table with no `_org_id`, is turned away before any row is read, and `/operations` shows such a caller the operations held to its orgs and no others.

## Source reads

`GET /api/v1/sources` and every other source read (`/sources/{name}`, `/columns`, `/flow`, `/signals`, `/export`, `/versions/{version}`, `/catalogue`, `/catalogue-tags`, `/engines`) accept `source:read` at system scope or at one of the caller's orgs. A source definition is shared by every org, so every such caller lists those. A fetcher source belongs to the org it names (none when it names none, so only a caller reading every org lists it), so a caller without a platform grant lists the fetcher sources of its held orgs and no others. A read by name of a fetcher source bound to an org the caller does not hold gets a 403 `org_not_granted`, and a caller with no `source:read` at system scope or in any org gets the 403.

The same rule covers `GET /schemas/{source}/columns`, `GET /kafka/topics` (a held caller sees the topics of the sources it may read) and `GET /ingest/rules` (a held caller sees the blocks of those sources). `GET /ingest/compat` and `/ingest/compat-profiles` are the deployment's bindings and profiles, shared by every source, so any `source:read` holder reads them. `GET /hyperdx/sources` lists every org's dfe-hyperdx team, so it needs `source:read` at system scope and turns away a caller held to its orgs.

## Hunt reads

The hunt runner's ClickHouse user reads every org, so every statement it compiles holds `_org_id IN (<the hunt's tenant ids>)` as a separate conjunct, and a rule condition may read no other table except one in `hunts.lookup_databases`. The alert-volume preview a rule write runs adds the same conjunct over the customers of each hunt that runs or lists the rule, cut to the orgs the author may read with `rule:write`. A rule no hunt runs is counted over the author's orgs alone, every org for a platform author, and a fence left with no org leaves the rule unmeasured.

A listed database holds shared reference data and no org's rows. The runner will not start, or stops at its next reload, when one of its tables has an `_org_id` column or is not a plain store of rows, as a view is not. The engine will not start on one either when ClickHouse answers at its start, and starts with the check unrun when it does not ([source-detections.md](/v/2.2.5/dfe-engine/data-plane/source-detections.md#lookup-databases)).

## Usage reads

`GET /api/v1/usage` and `GET /api/v1/usage/overview` read the usage rollup (`usage_daily` and `usage_minute`) and need `usage:read` at system scope or at the scope of one of the caller's orgs ([rbac.md](/v/2.2.5/dfe-engine/control-plane/rbac.md#23-permission-taxonomy)). The deciding step is the one the other reads use: whether the caller's grant reads every org for `usage:read` (`api/deps.py::reads_every_org`).

A caller with a grant that reads every org sees the deployment-wide rows, and may name any registered org with `org`. It can read all four metrics. An unregistered org answers `422 unknown_org`, and an org given for `cores_deployed` or `node_cores` answers `422 not_per_org`, because those two are counted for the deployment.

Any other caller is held to the tenant ids of the registered orgs its groups name (`resolve_orgs`) and grant `usage:read` at. An org where its groups grant some other role and not `usage:read` is never read. It reads:

- `ingested_bytes` and `events_per_second` for those orgs added together, or for the one it names with `org`.
- The two core counts as `not_permitted` with no series. Naming one of its orgs changes nothing for them, and the response is still `200`.

It cannot read the deployment-wide row, the one with an empty `_org_id`, and it cannot read an org it does not hold. Naming one answers `403 org_not_granted`, registered or not. A caller with groups that name no registered org answers `403 no_org`.

Events per second over more than one tenant id is the busiest minute of their sum, taken from `usage_minute`, which keeps 7 days. A held caller with several orgs therefore gets no events-per-second days older than 7. A range with no row reads as `not_measured`, and a day with no row is left out of the series, never 0.
