agentmux_srv\identity/mod.rs
1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Identity injection at agent CLI spawn time.
5//!
6//! When an agent instance is launched, the launch modal records an
7//! `identity_id` on the `db_agent_instances` row (v7 schema). Right
8//! before the CLI subprocess starts, this module:
9//!
10//! 1. Looks up the active instance for the spawning block.
11//! 2. Reads its `identity_id`. Empty / "blank" / not-found → noop
12//! (the agent inherits ambient credentials).
13//! 3. Reads the bindings for that Identity bundle.
14//! 4. For each binding: looks up the Account row, resolves its
15//! `SecretRef` to a plaintext value, looks up the provider →
16//! env-var matrix, and merges those env vars into the spawn
17//! `env_vars` HashMap.
18//!
19//! Failure mode is **warn-don't-block**: missing accounts, env-var
20//! resolution errors, unknown providers — all logged and skipped.
21//! The agent CLI launches with whatever ambient credentials remain.
22//! This is intentional: identity injection is a convenience, not a
23//! security gate. The caller flags hard-required-creds workflows
24//! separately.
25//!
26//! Closes Phase 2 of issue #678 (the per-instance injection layer).
27//! Phase 1 (Account registry + UI) and the v7 schema reshape (Bundle
28//! entity) were prerequisites; Phase 3 (encrypted vault, OAuth flows)
29//! is deferred.
30
31pub mod auth_patterns;
32pub mod auth_session;
33pub mod migration;
34pub mod resolver;
35
36// Legacy convenience re-export — newer call sites use
37// `resolver::inject_identity_env_with_broker` directly so the OAuth
38// expiry probe (PR D, spec §4.4) can publish on status change. The
39// broker-less wrapper is kept for tests and is intentionally allowed
40// to be unused in production.
41#[allow(unused_imports)]
42pub use resolver::inject_identity_env;