Skip to content

Security & Multi-Tenant Isolation ​

OpenHusky defaults to fail-closed security across both tool execution and multi-tenant session access.

Fail-Closed PermissionPolicy ​

Every AgentRuntime evaluates tool calls through PermissionPolicy before execution. With PermissionPolicy.failClosed(), any tool not explicitly allowed or approved is denied by default:

java
PermissionPolicy policy = PermissionPolicy.failClosed()
        .allowReadOnlyTools()                 // Permits tools annotated with readOnly = true
        .allow("remember_customer_fact")      // Explicit write-capable allowlist
        .requireApproval("issue_refund", "grant_account_credit", "escalate_to_human")
        .deny("shell_exec")
        .build();

Built-in presets are also available for common environments:

  • PermissionPolicy.readOnly() — allows only readOnly = true tools, denies writes
  • PermissionPolicy.requireApprovalForWrites() — allows read-only tools, prompts HITL approval for writes
  • PermissionPolicy.allowAll() — permits all tools (recommended only inside isolated L2/L3 sandboxes or tests)

Human-in-the-Loop (ApprovalDecision.Handler) ​

When a tool evaluates to REQUIRE_APPROVAL, AgentLoop emits AgentEvent.ApprovalRequested, suspends cleanly on its virtual thread, and waits for an ApprovalDecision from your ApprovalDecision.Handler (with cooperative AbortSignal and approvalTimeout support):

  • Embedded CLI / Service: implement (req, signal) -> ApprovalDecision.approveOnce() (or deny("reason")).
  • Web / SSE Apps: wire AgUiApprovalBroker from openhusky-agui, which maps approvalId to a CompletableFuture<ApprovalDecision> resolved when the frontend POSTs to /approve.

Multi-Tenant Principal & SessionAccessPolicy v0.2.0 ​

Availability

SessionAccessPolicy and AgUiHttpPrincipalResolver are available on main and in the upcoming 0.2.0 release.

Every AgentSession carries a Principal (Principal.of(userId, tenantId)). When multiple tenants share one SessionStore (for example a shared PostgreSQL/SQLite database or InMemorySessionStore), AgentRuntime enforces SessionAccessPolicy (default: TENANT_ISOLATED) on every openSession, prompt, compactNow, fork, and rewindTo call:

PolicyRule
TENANT_ISOLATED (default)Caller's principal.tenantId() must match SessionHeader.tenantId().
PRINCIPAL_ISOLATEDBoth tenantId and principalId must match the session owner.
UNRESTRICTEDDisables tenant/principal checks (for single-tenant embedded migrations).

Cross-tenant access throws SessionAccessDeniedException (with error messages intentionally omitting owning tenant/principal details to prevent metadata leakage), mapped by AgUiJdkHttpHandler to HTTP 403 Forbidden.

HTTP Authentication (AgUiHttpPrincipalResolver) v0.2.0 ​

In openhusky-agui, attach AgUiHttpPrincipalResolver to AgUiJdkHttpHandler.builder(runner) to authenticate every /run, /steer, /abort, and /approve request before it touches AgUiRunner:

java
AgUiHttpPrincipalResolver resolver = exchange -> {
    String auth = exchange.getRequestHeaders().getFirst("Authorization");
    if (auth == null || !auth.startsWith("Bearer ")) {
        throw AgUiAuthException.unauthorized("Missing Bearer token");
    }
    JwtClaims claims = jwtVerifier.verify(auth.substring(7).trim());
    if (!tenantRegistry.isActive(claims.tenantId())) {
        throw AgUiAuthException.forbidden("Unknown or suspended tenant");
    }
    return Principal.of(claims.subject(), claims.tenantId());
};

AgUiJdkHttpHandler handler = AgUiJdkHttpHandler.builder(runner)
        .principalResolver(resolver)
        .heartbeatInterval(Duration.ofSeconds(15))
        .build();
  • Throwing AgUiAuthException.unauthorized(...) returns HTTP 401 Unauthorized.
  • Throwing AgUiAuthException.forbidden(...) returns HTTP 403 Forbidden.
  • AgUiRunner also scopes thread keys and HITL approvalIds to the authenticated Principal, preventing cross-tenant session hijacking or approval spoofing.

Released under the MIT License. Built with Java 21 Virtual Threads.