Skip to content

Security Boundaries

This page collects the boundaries Entrabot enforces between the agent, the human, external content, and the tools it exposes.

Identity boundary: Agent User vs. delegated human

Every action the agent takes against Graph is attributed to one of two principals, and the attribution is structural, not cosmetic:

  • agent_user mode — the three-hop Blueprint → Agent Identity → Agent User flow (tools/teams.py::acquire_agent_user_token) mints a token with idtyp=user carrying the Agent User's own object ID. Graph sees the agent as a first-class user principal, distinct from both the human and an app-only service principal.
  • delegated mode — MsalDelegatedAuth uses the signed-in human's own token. There is no Agent User attribution in this mode; outbound messages are prefixed [EntraBot] so the human can tell which messages the agent sent, and the identity state machine records attribution_type = "delegated-human".

tools/audit.py::log_event() is what makes this durable: every audit event carries an attribution_type of "agent", "delegated-human", or "none", resolved from the active identity session, then config, then the credential store, in that order. See Identity and Token Flow for the full three-hop mechanics.

Certificate boundary (per OS)

Certificate handling differs by platform, and the two paths are not equivalent in strength:

  • macOS and Linux — _build_blueprint_assertion() retrieves the PEM private key from the OS keystore (Keychain via MacCredentialStore, Secret Service/KWallet via LinuxCredentialStore) into the process, then signs the JWT in-process with cryptography's load_pem_private_key and PyJWT. The key material is present in process memory for the duration of the signing call. Each certificate is one keystore item holding the certificate and its key (platform/keycert.py), named by the SHA-1 thumbprint .env records, so one agent's key is never read in place of another's; a keystore that cannot be read, or that is not an OS-native backend, stops setup and the sign-in rather than falling back to a file.
  • Windows — the private key is a non-exportable CNG key in Cert:\CurrentUser\My, created on the Microsoft Platform Crypto Provider (TPM) when the TPM accepts a key, or on the Microsoft Software Key Storage Provider otherwise (platform/wincert.py, auth/cncrypt_signer.py). Setup's Provisioner key is stored the same way; on macOS and Linux it is a PEM in the OS keystore, one item per tenant. Signing happens through ncrypt.dll; only the signature crosses back into the process, never the key.

Both paths produce the same JWT shape (x5t#S256 header, 10-minute assertion lifetime — auth/certificate.py), so the two are interchangeable at the protocol level. They are not interchangeable at the threat-model level: only the Windows CNG path is non-exportable, and only a TPM-backed CNG key is hardware-backed. The Mac/Linux path is neither hardware-backed nor non-exportable because anything that can read the OS keystore under the agent's account can retrieve the PEM.

Audit-first, fail-closed attribution

log_event() is called before a sensitive action proceeds, and again after it resolves, for security-sensitive call sites (Files Graph calls via _audit_graph_call(), Teams member adds, file shares): a pending event first, then success or failure. Other tools audit once, immediately before the side effect.

Every tool that sends, creates, shares or deletes writes its pending event first and does nothing when that write fails: send_teams_message, send_card, post_thinking_placeholder, create_chat, send_email, delete_teams_message, add_teams_reaction, remove_teams_reaction, resolve_placeholder, add_teams_member, share_file, the Files and Work IQ writes, and the daily summary. Files and Work IQ reads are audited the same way. update_placeholder (editing the agent's own progress message) and the Teams and mail read tools (read_teams_messages, read_email, list_chat_members) are not audited; they go to the interaction log, which is best effort. In a delegated session add_teams_reaction and remove_teams_reaction refuse before any Graph call and write a denied event: the reaction would be made as the signed-in human, and unlike a message it has nowhere to carry the [EntraBot] prefix that attributes it to the agent. Each event is flushed to disk (fsync) before the action runs. The audit log is a local append-only JSONL file per day under ENTRABOT_AUDIT_DIR (default ~/.entrabot/audit): it is not signed, and anything running as the same OS user can edit it.

Every event carries origin: "system" for the server's own events, "model" for events the model wrote through the audit_log tool. A model-authored event is the model's claim, never the server's record.

Outbound recipient policy

security/recipients.py decides, in the server and before Microsoft Graph is called, whether the agent may reach an address. It applies to send_email (every to, cc and bcc address; one refusal stops the message), create_chat, add_teams_member (the invitee), share_file (the recipient) and the daily summary. Allowed by default:

  • the agent's sponsors as the directory lists them on the Agent Identity, cross-tenant sponsors included;
  • members of the chat the last pushed message came from, for 30 minutes after it;
  • the home tenant: the Agent User's domain, any domain in ENTRABOT_HOME_DOMAINS, or a domain whose sign-in discovery resolves to the agent's tenant ID.

Everyone else needs an entry in ENTRABOT_OUTBOUND_ALLOW (exact addresses, or domains as fabrikam.com or @fabrikam.com; a domain entry does not cover its subdomains). A sponsor list or member list that cannot be read counts as empty, and a domain that cannot be resolved counts as external. A refusal returns an error to the model and writes a denied audit event. share_file and add_teams_member still also require a sponsor's live request (below); the policy narrows who the sponsor can direct them at. The daily summary, which contains other people's messages, goes to every directory sponsor whose user record gives an address, an external sponsor included; keep only sponsors in the tenant on the Agent Identity to avoid that. .env's ENTRABOT_HUMAN_USER_MAILS is used only when the directory gives no sponsor address. A sponsor whose user record the agent can't read is known by user ID only, so mail to that sponsor passes the policy only as a home-tenant address.

Token lifetime and revocation

An access token Entra has issued stays valid until it expires, even after the agent is disabled. Continuous access evaluation (CAE) would let Microsoft Graph reject it sooner, but Microsoft Learn documents CAE for users and for single-tenant workload identities (line-of-business service principals), not for Agent Identities or for the Agent User user_fic grant, and asking for it (xms_cc cp1) makes Entra issue tokens that live up to 24 to 28 hours. Entrabot therefore does not request CAE. Instead the server asks for a fresh three-hop token when its current one is older than ENTRABOT_TOKEN_MAX_AGE_SECONDS (default 600, from 60 to 3300). Once the agent is disabled that sign-in fails and every Graph tool fails with it, so a disabled agent keeps acting through Graph for at most about ten minutes by default. The Azure Blob storage token (cloud memory) is cached separately until five minutes before it expires, so cloud memory reads and writes can go on for up to about an hour. Revisit this if Microsoft documents CAE for Agent Users.

Attribution itself fails closed: if agent_id isn't supplied and none can be resolved from the active identity session, config, or the credential store, log_event() raises AuditAttributionError rather than logging "unknown" — unless the caller explicitly opts in with attribution_type="none" (reserved for bootstrap/preflight code that genuinely runs before any identity exists). This scope is specifically about attribution; it does not mean every possible agent action is audited today — it means an action that is meant to be agent-attributed cannot silently become an orphaned log line.

External-content / XPIA boundary

security/xpia.py::wrap_external() wraps external-source text — Teams messages, email bodies, file contents, Work IQ content — in a <external_content> envelope before it reaches the model:

<external_content source="..." sender="..." received_at="...">
  ...body...
</external_content>

The properties that make this a real boundary, not just formatting:

  • The outer envelope is always authoritative. wrap_external() unconditionally wraps every call, even when the body already looks like an envelope. External text cannot forge the trusted source/sender/received_at metadata by embedding what looks like the wrapper prefix — the caller-supplied attributes always win because they're the ones written into the outer tag.
  • Escape-on-collision. Any literal </external_content> in the body — including case variants and whitespace-padded forms like < / External_Content > — is entity-escaped before wrapping, so embedded text can't break out of the envelope by closing it early.
  • Attribute-safe. source, sender, and received_at values are escaped for &, <, >, and ", so a hostile value like source="teams:<script>" can't open a new tag inside the attribute region.
  • Round-trip support for tests and audit. unwrap_external() reverses collision escaping and round-trips the body byte-for-byte while recovering the source, optional sender, and optional received_at attributes. The envelope has no content_hash attribute or cryptographic binding.
  • Opt-out is an env flag, not a code path. ENTRABOT_XPIA_WRAP_ENABLE=false short-circuits wrap_external() to the identity function for rollback, without touching call sites.
  • Channel pushes use a bracket form. A push can't carry angle brackets, and the push sanitizer strips every tag, so wrap_for_channel() writes the same envelope as [external_content source="..." sender="..."]...[/external_content]. Square brackets and the marker's name can't survive in the body, so it can't forge a marker.
  • Which pushes carry it. A Teams push from a verified sponsor stays outside the envelope, because the body prompt treats anything inside one as data, and this is how a sponsor gives an instruction. The sender is checked with SponsorGate, never a display name, and a failed lookup counts as not a sponsor. A push trusts a cached list for 15 minutes, so someone removed as a sponsor stops speaking outside the envelope within that time. A Teams push from anyone else is wrapped, and so is all email, even when it shows a sponsor's address, because a From address can be forged. A reaction push is always wrapped too, a sponsor's included: a reaction is information about one of the agent's messages, never an instruction, and its emoji and name are text someone else chose. It records no sponsor-channel binding.

This is a text-escaping and provenance boundary, not a cryptographic signature. See Security (XPIA) API Reference for the full public surface, confirmed wrapped/unwrapped call sites, and limitations.

"Sponsor" is Entrabot's authorization concept for who may direct the agent to take mutating action on a human's behalf.

  • Source of sponsors. identity/sponsors.py::fetch_agent_identity_sponsors() reads the Agent Identity's /sponsors Graph relationship using an app-only, two-hop token (acquire_agent_identity_token() — stops after the FIC exchange, no user_fic grant). This has to be app-only: the Agent User's own delegated token cannot read its own /sponsors relationship.
  • SponsorGate (identity/sponsors.py) decides whether an inbound message can satisfy an explicit wait_for_sponsor_dm or server-side auto-wait. It matches on sponsor user ID, UPN, or email, extended with chat-member and cross-tenant B2B lookups across watched chats.
  • Active-channel binding (identity/active_channel.py::ActiveChannelBindings) is the separate, TTL-scoped gate that authorizes both share_file and add_teams_member mutations. A binding is minted only after a sponsor's inbound message has been successfully pushed to the model (via the channel-push notification path) — recording (sponsor_user_id, chat_id, graph_sent_at). The TTL (120s) is enforced against the message's Graph-authored sent_at, not against when the server observed it, specifically so a stale message can't be replayed at bootstrap to mint a fresh authorization window. Bindings expire on read as well as on write, so a clock rewind can't resurrect one.
  • share_file and add_teams_member both enforce all three checks. share_file() (tools/files.py) and add_member() (tools/teams.py, exposed as the add_teams_member MCP tool) gate on: (1) the requester matching a sponsor identity, (2) an active-channel binding for that sponsor whose chat_id matches the one supplied, and (3) — defense in depth — the sponsor actually being a Graph member of the target chat. NoActiveSponsorChannelError is raised when the matched sponsor has no live binding at all; SponsorChannelMismatchError is raised specifically to catch a confused-deputy pattern: an LLM in chat A being induced to act on chat B, where the sponsor is a genuine member of B but not actively engaged there right now. Dedicated tests for the add_teams_member binding checks live in tests/tools/test_add_member_channel_binding.py.
  • The recipient or invitee is checked too. Besides the requester checks above, share_file's recipient_email and add_teams_member's invitee email must pass the recipient policy: a sponsor, a member of the requesting chat, someone in the home tenant, or an entry in ENTRABOT_OUTBOUND_ALLOW. A refusal writes a denied audit event and makes no Graph call.
  • Wait validation and mutation authorization are separate. SponsorGate.accepts() decides whether an inbound message can satisfy a sponsor wait. The general background poll delivers human messages without using SponsorGate as its filter: the gate only decides whether a push carries the envelope. Sponsor lookup after successful delivery decides whether to mint an active-channel binding. That binding, not SponsorGate, authorizes both share_file and add_teams_member mutations.

Server-side auto-wait, not a model-facing switch

send_teams_message's decision to block for a sponsor reply is made by inspecting the connected MCP client's clientInfo.name server-side (mcp_server.py::_current_host()), against a fixed set of known channel-push hosts. There is no tool parameter the model can set to skip or force this behavior — if there were, an LLM would be free to set it however the current turn's text happens to suggest, which defeats the point of a behavioral guarantee. If a new host needs different auto-wait behavior, that's a server-side allowlist change, not something exposed at the tool boundary.

The _COMMITMENT_PATTERNS outbound-discipline check (also in mcp_server.py) is a warning, not a block: it looks for commitment-sounding language in outbound Teams text without a matching recent add_promise call, and appends a _discipline_warning to the result JSON when it fires. It does not stop the message from sending.

Storage and cursor fail-closed behavior

Two storage-layer boundaries are part of the same fail-closed posture as the rest of this page:

  • Half-configured Blob storage is a hard error. storage/backend.py::get_backend() raises BackendMisconfiguredError when exactly one of ENTRABOT_BLOB_ENDPOINT / ENTRABOT_BLOB_CONTAINER is set, rather than silently falling back to an empty local store.
  • Ambiguous cursor reads never authorize a push. tools/chat_cursors.py::resolve_cursor() classifies every cursor read as ABSENT, PRESENT, or UNRESOLVED; only ABSENT (a clean, successful "nothing here yet" read) allows a poll to treat a chat as new. A read failure, a timeout, or a corrupt payload is UNRESOLVED and is treated the same as "don't push," because an ambiguous read could be hiding a live cursor.

See Storage and Memory for the full mechanics of both.

Efferent-copy trust boundary

The efferent-copy middleware (src/entrabot/efferent_copy.py) is disabled by default — it only wraps tool functions when EFFERENT_COPY_ENABLE=1 is set, and EFFERENT_COPY_DISABLE=1 always wins over the enable flag. When enabled, any MCP peer in .mcp.json that exposes a schema-compatible observe(tool_name, args[, result]) tool is treated as part of the trusted observability boundary — discovery is schema-based, not name-based, so there's no allowlist of specific peer identities beyond EFFERENT_COPY_SINKS if an operator sets one.

Sensitive values are redacted before leaving the body by a case-insensitive, substring-based denylist (token, secret, password, client_secret, access_token, api_key, bearer, credential, private_key, and similar). This is name/key-substring redaction, not semantic content inspection — a sensitive value stored under a non-obvious key name (the module's own example: auth_blob) is not caught by the denylist and can reach a sink unredacted. Treat this as a real but bounded mitigation, not a guarantee that no sensitive data ever reaches an attached sink.

Current limitation: no shipped execution sandbox

Entrabot does not ship an execution sandbox: the MCP server runs with all of its user's rights, and Claude Code's own sandbox covers the shell commands it runs, not local MCP servers. Containing the server in an OS sandbox on macOS and Linux is planned for 0.4.0.

See also