forked from vhaudiquet/rhema-claw
feat(tools): the ingest credential — the event door, write-only
The agent token is deliberately barred from /v1/ingest: the events are the inbound channel, and the model must not feed it itself. But the same bar closes the door on every honest integration too — a sidecar poller with events to hand in had to hold the human token, which is wider than its job. This adds the missing class: a third bearer, the ingest token, answering the event door and nothing else. `ingest_allowed` is the whole credential in one function — one route row, `POST /v1/ingest` — symmetric with `agent_allowed` and suite-covered the same way: the mock and the daemon's real router both answer the new checks (a push succeeds with the contract header; a watch read and a consent answer are 403). The middleware classifier gains the third arm, boot refuses an ingest token equal to either other credential — one value playing two roles silently widens the scoped one — and the daemon provisions it to tool shells as `RHEMA_INGEST_TOKEN`, so a tool that only pushes events never sees the wider agent token at all. The door is the first half of the extensions story (rhema-tools spec §8): a self-timed sidecar is now a tier-1 tool with a credential narrow enough to hold.
This commit is contained in:
1 parent
98bc0fd623
commit
f96f8c4c1d
10 files changed
+210
-18
No files matched your search
@@ -8,6 +8,7 @@ use serde_json::{Value, json};
|
||||
|
||||
use std::sync::PoisonError;
|
||||
|
||||
use crate::ingest_allowed;
|
||||
use crate::{
|
||||
Auth, CONTRACT_VERSION, CallRequest, CallResponse, NotificationOut, NotificationPush, TaskAdd,
|
||||
TaskOut, agent_allowed, now_millis,
|
||||
@@ -19,6 +20,7 @@ use crate::{
|
||||
pub struct MockClaw {
|
||||
human_token: Option<String>,
|
||||
agent_token: Option<String>,
|
||||
ingest_token: Option<String>,
|
||||
notifications: Mutex<Vec<NotificationOut>>,
|
||||
tasks: Mutex<Vec<TaskOut>>,
|
||||
watches: Mutex<Vec<Value>>,
|
||||
@@ -29,10 +31,15 @@ pub struct MockClaw {
|
||||
impl MockClaw {
|
||||
/// A mock with the daemon's two tokens; `None` means that class is
|
||||
/// unconfigured and its bearers are strangers.
|
||||
pub fn new(human_token: Option<&str>, agent_token: Option<&str>) -> Self {
|
||||
pub fn new(
|
||||
human_token: Option<&str>,
|
||||
agent_token: Option<&str>,
|
||||
ingest_token: Option<&str>,
|
||||
) -> Self {
|
||||
Self {
|
||||
human_token: human_token.map(str::to_owned),
|
||||
agent_token: agent_token.map(str::to_owned),
|
||||
ingest_token: ingest_token.map(str::to_owned),
|
||||
notifications: Mutex::new(Vec::new()),
|
||||
tasks: Mutex::new(Vec::new()),
|
||||
watches: Mutex::new(Vec::new()),
|
||||
@@ -46,7 +53,8 @@ impl MockClaw {
|
||||
pub async fn call(&self, request: CallRequest) -> Result<CallResponse, String> {
|
||||
// The bearer gate. With no tokens configured the surface is
|
||||
// open; with either, a stranger is a 401.
|
||||
let open = self.human_token.is_none() && self.agent_token.is_none();
|
||||
let open =
|
||||
self.human_token.is_none() && self.agent_token.is_none() && self.ingest_token.is_none();
|
||||
if !open && matches!(request.auth, Auth::None | Auth::Invalid) {
|
||||
return Ok(self.error(401, "unauthorized"));
|
||||
}
|
||||
@@ -59,6 +67,16 @@ impl MockClaw {
|
||||
return Ok(self.error(403, "this route is not the agent token's"));
|
||||
}
|
||||
}
|
||||
// The ingest class: the event door, contract version required —
|
||||
// an integration speaks the same handshake the tools do.
|
||||
if request.auth == Auth::Ingest {
|
||||
if request.contract != Some(CONTRACT_VERSION) {
|
||||
return Ok(self.error(409, "contract version mismatch"));
|
||||
}
|
||||
if !ingest_allowed(request.method, &request.path) {
|
||||
return Ok(self.error(403, "this route is not the ingest token's"));
|
||||
}
|
||||
}
|
||||
|
||||
let segments: Vec<&str> = request.path.trim_matches('/').split('/').collect();
|
||||
match (request.method, segments.as_slice()) {
|
||||
|
||||
Reference in new issue
Block a user