Skip to content

feat(agent): enforce authorization at tool execution boundary - #169

Merged
yuluo-yx merged 1 commit into
agentic-ai-java:mainfrom
Koiyd:feat/120-tool-authorization
Oct 17, 2026
Merged

yuluo-yx merged 1 commit into
agentic-ai-java:mainfrom
Koiyd:feat/120-tool-authorization

Conversation

@Koiyd

@Koiyd Koiyd commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Describe what this PR does / why we need it

Adds opt-in authorization enforcement at the tool execution boundary, enabling applications to control which principals can invoke which tools based on runtime context.

This PR introduces:

  • AuthorizationDecision: Immutable allow/deny result with optional reason
  • ToolAuthorizationPolicy: Application SPI for authorization decisions with three built-in factory methods (allowAll, denyAll, requireMatchingTenant)
  • ToolAuthorizationInterceptor: ToolInterceptor that invokes the policy before dispatching; strict mode (default) rejects calls without trusted execution context
  • Tenant-scoped BackgroundTask access: TaskRepository now supports tenant-isolated task lookup to prevent cross-tenant access

Does this pull request fix one issue?

Fixes #120
Refs #117

Describe how you did it

  1. Created AuthorizationDecision as an immutable value type representing allow/deny outcomes
  2. Defined ToolAuthorizationPolicy functional interface as the application SPI, with three built-in static factory methods covering common cases
  3. Implemented ToolAuthorizationInterceptor extending ToolInterceptor, which reads TrustedExecutionContext from RunnableConfig and invokes the policy before forwarding to the next handler
  4. Extended BackgroundTask to record the creating principal's tenant
  5. Added tenant-scoped getTask(id, callerTenantId) method to TaskRepository interface as a default method; null caller has unrestricted access
  6. Implemented tenant-isolated lookup in DefaultTaskRepository and updated TaskOutputTool to pass caller's tenantId from trusted execution context

Describe how to verify it

Run the test suite:

./mvnw -pl :argi-agent-framework test \
  -Dtest="ToolAuthorizationInterceptorTest,DefaultTaskRepositoryTenantIsolationTest,BuiltInAuthorizationPoliciesTest"

All 18 tests pass, covering:

  • Authorization decisions (allow/deny with reason)
  • Built-in policies (allowAll, denyAll, requireMatchingTenant)
  • Interceptor behavior in strict/lenient modes
  • Tenant-isolated task repository access

Special notes for reviews

Opt-in design: No ToolAuthorizationInterceptor is registered by default. Existing AgentToolNode configurations are unaffected and execute tools without authorization checks. Applications must explicitly add the interceptor to enable authorization.

Built-in policies reduce friction: The three factory methods (allowAll, denyAll, requireMatchingTenant) provide reasonable starting points without requiring a full custom policy implementation.

Execution order matters: ToolAuthorizationInterceptor should typically be placed early in the interceptor chain (before retry/fallback) so that revoked access takes effect immediately, including on retries.

…gentic-ai-java#120)

Adds an opt-in authorization gate that runs before every tool dispatch,
including retries, so that revoking access takes effect immediately.

@yuluo-yx yuluo-yx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,thanks for you

@yuluo-yx
yuluo-yx merged commit 97d05be into agentic-ai-java:main Oct 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P0][T03] 在工具执行边界强制校验授权与风险策略

2 participants