Karyo
Documentation/ Decision records

ADR 0047: Agents sign in to read mirrored tools

Karyo 2.1.1rendered at build time
On this page

Status: Accepted. Implements the read-only part of ADR 0041. Supersedes its blanket exclusion of identity mirrors and its choice of the outbox for recent activity. Agent writes and the Approvals page are ADR 0054, which also adds three proposal-state tools as a second exact identity exception and supersedes the "twelve read-only tools" count and the "no prepare tools" statement here. The role equality of the mirror guard is superseded by ADR 0048: a tool declares the same catalogue action as its mirrored endpoint.

Context

ADR 0041 retired Karyo's Copilot and all three model providers. Its replacement needs a usable read surface before proposals or live vendor proofs. The retired tools also demonstrated why calling a service without its REST role check is unsafe.

The existing identity pipeline already binds a verified issuer and subject to an enrolled principal. It applies the principal's role ceiling and its Company, Business Unit and Facility grants. An agent must reuse that authority, not introduce a delegation principal or another permission system. Installation approval is an additional cutoff, not a grant.

Two details in ADR 0041 needed an explicit decision. Its tool list includes whoami while its guard forbids identity methods. It also names the outbox for activity without an equivalent read endpoint. The approved resolutions are one exact self-identity exception and the existing Facility-scoped inventory journal, respectively.

Decision

  • One endpoint, no model. Quarkiverse MCP Server HTTP handles Streamable HTTP at /mcp in karyo-app. Karyo implements neither a second protocol server nor an OAuth authorization server. It exposes twelve read-only tools, structured result schemas, and read-only server instructions. There are no prepare tools, proposals, warehouse writes or Approvals page in this slice.
  • OAuth belongs to the primary provider. Managed installations use Keycloak 26.8 with resource-indicators and cimd. Anonymous dynamic client registration has a quota, trusted sources and callback hosts, explicit scope ceilings, no supplied mappers, disabled full scope, and consent. Requests using karyo.read require S256 PKCE and reject password and implicit grants. CIMD accepts bounded HTTPS client metadata from the configured vendor domain. Ordinary console sign-in does not request karyo.read and keeps its existing clients and flow.
  • The resource has its own audience. KARYO_MCP_RESOURCE_URI is one canonical HTTPS /mcp URI, with HTTP permitted only for literal loopback development. The reserved agent OIDC tenant verifies the configured issuer and signature. The HTTP policy requires exactly that audience, karyo.read, an enrolled active principal, and a nonblank azp client identifier. Client identifiers preserve their opaque value, exclude control characters and contain at most 2,048 UTF-8 bytes. Console-audience tokens cannot reach MCP. MCP-audience tokens cannot reach ordinary REST. Protocol sessions never replace authentication on the next request.
  • Discovery is deliberately public. RFC 9728 JSON is served at /.well-known/oauth-protected-resource and its resource-specific /mcp child. Both paths serve one document, built from the quarkus.oidc.agent.resource-metadata.* configuration. A 401 for a missing, invalid or wrong-audience token points at the root discovery document. Missing scope returns 403 with insufficient_scope. A valid token whose connection is not approved or is revoked, or whose installation is disabled, returns 403 agent-access-disabled with no discovery challenge, because signing in again cannot fix it. The nginx proxy forwards only these exact discovery paths and /mcp, without buffering MCP responses. Unknown MCP children, including the separate SSE transport, return 404.
  • Every tool mirrors one existing GET. The tool and its target have equal authentication, endpoint roles, and declared scope. Dispatch checks the role before schema conversion. CDI security checks it again during invocation. TenantFilter.forAgentRead resolves current grants through the same selection rules as REST and clears earlier selections. Product reads remain Business Unit facts; Facility facts require an authorized Facility.
  • There is exactly one identity exception. Only IdentityReadTools#whoami may mirror AuthSessionResource#me, with its existing self-only authentication and IDENTITY scope. An alias of that target is also forbidden. Every other IDENTITY, ADMINISTRATION, CONFIGURATION, PUBLIC or write mirror remains forbidden. recentActivity mirrors JournalResource#list with inventory-read, never the outbox.
  • Results are projections, not entities. Each tool selects operational fields and separates external strings under untrusted. A result contains at most 50 rows. Text is truncated to 1,000 characters. Decimal nextPage values identify the next integer page. Existing paginated reads supply their own totals. Pick orders, shipments and journals accept bounded query windows with a lookahead row and stable ordering. Report and work calculations retain their existing Facility-scoped services; output bounds do not claim to bound every aggregate calculation.
  • Access starts off twice. The installation flag defaults to false. Each enrolled principal/client pair also defaults to false. Its approval is independent of the selected Facility. The authenticated self route lists connections and permits disabling only. The principal administration route retains user-admin plus the existing users.read or users.manage record boundary. Its permission hints drive both administrative UI controls, independently of principal suspension or provider profile capabilities.
  • No cached authority. Each request rechecks the principal, current grants, installation flag and connection approval. Role or grant removal, suspension and disabling apply on the next request. They do not end the person's console session.
  • Attribution is not content retention. agent_tool_calls records principal, client, catalogued tool, outcome, latency and timestamp. It begins before schema conversion, so denied calls and malformed arguments remain attributed. Unknown names become UNKNOWN. It stores no arguments, results or tokens. A daily global job deletes rows older than 90 days. Tool failures return sanitized errors; protocol diagnostics that can contain supplied values are suppressed.
  • Rate limits belong to one application instance. Bounded token buckets permit 60 requests per minute per principal/client pair by default. The SYS setting accepts 1 through 6,000. Idle buckets expire after two minutes. Saturation at 10,000 buckets returns 429 instead of evicting an active bucket and restoring its allowance. Every 429 includes Retry-After.

Consequences

The mirrored role defect cannot return unnoticed: the guard checks all exposed tools, exact catalogue membership, GET targets, authentication, roles, scope, structured content and schemas. Planted identity aliases and administration targets fail the guard.

The installation owner must knowingly permit warehouse data to leave through an agent. Karyo cannot impose the vendor's retention or residency policy. Turning on the installation does not approve every connection and does not add authority to any principal.

The rate limiter assumes the supported single-process application deployment. Multiple application instances would need a shared limit before claiming one installation-wide budget. The buckets contain limiter state, not cached warehouse facts or grants.

Keycloak's resource-indicator and CIMD features remain experimental. An external primary provider must support the same resource binding and OAuth client bootstrap. Real Claude Code, Grok Bot and dot compatibility is not proved by these local tests. Live proofs and Atlas exposure remain a later change. The Jev proposals assumed the retired chat and were closed with it.

Alternatives considered

  • Generic REST export or OpenAPI alongside MCP. Rejected for this slice: the approved agent surface is one curated MCP endpoint, not every REST operation.
  • Direct service reads with duplicated authorization. Rejected: they repeat the retired role bypass and drift from REST scope checks. The adapters invoke the actual mirrored resources.
  • A general identity exception. Rejected: it would admit other identity reads. The guard names the exact declaring class, tool method and target for whoami.
  • Read the outbox directly. Rejected: it has no approved equivalent REST read boundary. The journal already supplies Facility-scoped activity under inventory-read.
  • Approve all agents when the installation is enabled. Rejected: the captain selected default-off access. Each observed principal/client pair requires an administrator's decision.
  • Build an OAuth server inside Karyo. Rejected as in ADR 0041: the provider already handles client registration, authorization codes, PKCE, consent, refresh and signing.
  • A new domain read service for MCP. Rejected: query windows and filters belong to the existing REST read. The agent adapter only selects context and projects its result.

Evidence

  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/ConfiguredOidcTenantResolver.kt, ConfiguredOidcTenantResolver.resolve - reserved agent tenant.
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt, TenantFilter.forAgentRead - reused read scope and grant resolution.
  • services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentHttpPolicy.kt, AgentHttpPolicy.checkPermission - HTTP audience, scope, cutoff and limiter checks.
  • services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentDispatchFilter.kt, AgentDispatchFilter - role checks and attribution before conversion.
  • services/karyo-app/src/main/kotlin/com/karyo/app/agent/IdentityReadTools.kt, IdentityReadTools - exact self-identity exception.
  • services/karyo-app/src/main/kotlin/com/karyo/app/agent/ActivityReadTools.kt, ActivityReadTools - journal mirror.
  • services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentReadResult.kt, AgentReadResult - output envelope and projections.
  • services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentToolCallLog.kt, AgentToolCallLog - attribution and retention.
  • services/karyo-app/src/main/resources/db/migration/agent/V1600__agent_access_and_tool_calls.sql, karyo.agent_access, karyo.agent_tool_calls - default-off approval and call tables.
  • infrastructure/keycloak/karyo-realm.json, clients, clientProfiles, clientPolicies and infrastructure/keycloak/karyo-realm-prod.json, clients, clientProfiles, clientPolicies - managed registration and OAuth policies.
  • infrastructure/docker/nginx/nginx.conf, location = /mcp, location = /.well-known/oauth-protected-resource, location = /.well-known/oauth-protected-resource/mcp - exact proxy routes rather than console HTML fallback.
  • services/karyo-app/src/test/kotlin/com/karyo/security/guards/AgentToolMirrorTest.kt, AgentToolMirrorTest - mirror guard and planted violations.
  • services/karyo-app/src/test/kotlin/com/karyo/app/agent/AgentMcpRuntimeTest.kt, AgentMcpRuntimeTest - signed tokens, scope isolation, cutoffs, bounds and unchanged operational rows.
  • services/karyo-app/src/test/kotlin/com/karyo/app/agent/AgentRealmBootstrapTest.kt, AgentRealmBootstrapTest - real managed registration, code, consent, PKCE and resource indicators.
  • frontend/web/src/components/agent/connected-agents.tsx, ConnectedAgents - self and administrative controls.