Commit 51110cd
sentinel: multi-tenant agent — single deployed agent serves all orgs
Previous slice 3 design had one Fly app per org (single MCP key, single
org_id env var, processor filtered foreign-org runs). That doesn't
scale — one Fly deploy per customer is operational suicide. Switching
to one shared agent that handles every org via per-call scoping at the
MCP layer.
Design
agent → MCP request:
Authorization: Bearer <SENTINEL_AGENT_MCP_KEY>
X-Agent-Org-Override: <run.org_id>
MCP server _resolve_org():
if bearer == SENTINEL_AGENT_MCP_KEY (constant-time compare):
→ require X-Agent-Org-Override header
→ use that as org_id
→ require org has Pro Plus + Sentinel enabled (defence in depth
against the dispatcher's gate having lapsed between dispatch
and pickup)
→ rate-limit on per-org bucket "sentinel-agent:{org_id}" so
agent traffic for org X can't burn org Y's tool budget
→ audit-log with key_name="<sentinel-agent>" + the override org
else:
→ existing per-org osc_* key flow (unchanged)
The two auth paths are completely independent — leaking the agent key
gives an attacker the ability to make MCP calls as any org, but doesn't
forge a per-org osc_* key (which is bound to a specific org_id by hash).
Changes
1. backend/app/core/config.py:
- New env var SENTINEL_AGENT_MCP_KEY (distinct from SENTINEL_AGENT_KEY
to keep blast radii separate; one is for run-lifecycle callbacks,
the other is for MCP tool calls).
2. backend/app/mcp/server.py:
- hmac added to imports + settings imported.
- _auth() now also pulls the x-agent-org-override header so it's
available to _resolve_org.
- _resolve_org() branches: if bearer matches SENTINEL_AGENT_MCP_KEY,
hand off to _resolve_via_agent_key (new function).
- _resolve_via_agent_key() validates the override header, enforces
plan + sentinel-enabled checks, applies a per-override-org rate
limit bucket, sets the activity tracker context with key_name=
"<sentinel-agent>" so audit attribution is preserved.
The McpApiKey table is unchanged — the agent key isn't an osc_* row,
it's a bearer that lives in env vars on both sides. No new schema, no
encrypted-at-rest column. Honest trust model: the agent has the
secret, therefore it can act as any org.
Verified locally:
- 549/549 backend tests green
- Ruff clean
- _resolve_org dispatches both paths correctly
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8f4e4c6 commit 51110cd
2 files changed
Lines changed: 133 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
169 | 190 | | |
170 | 191 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
277 | 279 | | |
278 | 280 | | |
279 | 281 | | |
280 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
281 | 293 | | |
282 | 294 | | |
283 | 295 | | |
| |||
289 | 301 | | |
290 | 302 | | |
291 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
292 | 314 | | |
293 | 315 | | |
294 | 316 | | |
| |||
351 | 373 | | |
352 | 374 | | |
353 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
354 | 464 | | |
355 | 465 | | |
356 | | - | |
| 466 | + | |
357 | 467 | | |
358 | 468 | | |
359 | 469 | | |
| |||
0 commit comments