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:
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 onlyreadOnly = truetools, denies writesPermissionPolicy.requireApprovalForWrites()— allows read-only tools, prompts HITL approval for writesPermissionPolicy.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()(ordeny("reason")). - Web / SSE Apps: wire
AgUiApprovalBrokerfromopenhusky-agui, which mapsapprovalIdto aCompletableFuture<ApprovalDecision>resolved when the frontendPOSTs 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:
| Policy | Rule |
|---|---|
TENANT_ISOLATED (default) | Caller's principal.tenantId() must match SessionHeader.tenantId(). |
PRINCIPAL_ISOLATED | Both tenantId and principalId must match the session owner. |
UNRESTRICTED | Disables 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:
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 HTTP401 Unauthorized. - Throwing
AgUiAuthException.forbidden(...)returns HTTP403 Forbidden. AgUiRunneralso scopes thread keys and HITLapprovalIds to the authenticatedPrincipal, preventing cross-tenant session hijacking or approval spoofing.