1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Gateway-route entity catalog reconciliation.
//!
//! Gateway route ids are content-addressed (`synthesize_route_id` in
//! `systemprompt_models`), so they are stable across installs but change the
//! moment a route's pattern or provider changes. The resolver is exact-match
//! and fail-closed: a route id with no `access_control_entities` row resolves
//! to [`DenyReason::UnknownEntity`](crate::authz::DenyReason::UnknownEntity)
//! before any rule runs.
//!
//! [`reconcile_gateway_entities_exact`] makes the catalog equal to the live
//! profile's routes: it registers the current ids and deletes the
//! `gateway_route` rows outside that set. Boot and the `admin config` CLI both
//! call it, keeping the catalog in step with the profile whether the operator
//! edited a route or simply started the app. Entities are registered
//! `default_included = false`: presence in the catalog never grants access on
//! its own — an explicit, role-scoped grant in `access_control_rules` still
//! has to allow the route, and the catalog is what a `gateway_route`
//! `entity_match` glob expands over.
//!
//! Deletion is by set difference, not by `source`. Provenance cannot carry it:
//! `access_control_entities.source` is rewritten on every conflicting upsert
//! (`ingestion/upsert.rs`), so a row this module wrote as `profile:<name>` is
//! relabelled `ingestion:access_control_config` the moment a roles.yaml rule
//! touches it. Filtering on `source` would therefore prune nothing.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.
use AccessControlRepository;
use EntityKind;
use crate;
// Why: an empty `route_ids` is refused rather than treated as "prune
// everything". No gateway routes is a plausible misread — a missing `gateway:`
// block, a profile that failed to load — and wiping every route grant on that
// guess is not recoverable. Callers with genuinely no routes have nothing to
// reconcile and must not call this.
pub async