Commit 01de6ff
authored
feat(a2a): Add A2A authentication middleware with TIP token propagation support (#304)
* feat: add run_processor support for Agent Runner
1. **Runner run_processor support**
- Add `run_processor` parameter to Runner.__init__() and Runner.run()
- Support multiple sources with priority: run() arg > __init__ arg > agent.run_processor > NoOpRunProcessor
2. **Fix IdentityClient region initialization**
- Change default region from hardcoded "cn-beijing" to None in WorkloadTokenManager
- Auto-detect region using _get_default_region() when not specified
- Import _get_default_region from auth_config module
Changes:
- veadk/runner.py: Add run_processor support with priority chain
- veadk/integrations/ve_identity/token_manager.py: Fix region initialization
- veadk/integrations/ve_identity/auth_mixins.py: Minor formatting fix
* feat(a2a): add credential service and auto auth token injection
This commit introduces comprehensive authentication support for A2A (Agent-to-Agent)
communication, enabling secure credential management and automatic token injection.
Key Changes:
1. **VeCredentialStore** (veadk/a2a/credentials.py)
- Implement custom credential store with user ID and session ID support
- Support both synchronous and asynchronous credential operations
- Prioritize user ID over session ID for credential retrieval
2. **AuthenticatedA2ARequestConverter** (veadk/a2a/ve_request_converter.py)
- Extract JWT tokens from Authorization headers
- Parse user ID from JWT payload (sub field)
3. **RemoteVeAgent** (veadk/a2a/remote_ve_agent.py)
- Add credential_service parameter to constructor
- Implement _run_async_impl with automatic auth token injection
- Inject Bearer tokens into httpx client headers before requests
- Add comprehensive error handling and logging
4. **VeA2AServer** (veadk/a2a/ve_a2a_server.py)
- Add credential_service parameter to constructor
- Integrate with AuthenticatedA2ARequestConverter
5. **Unit Tests** (tests/)
- Add comprehensive test coverage for VeCredentialStore
- Add tests for AuthenticatedA2ARequestConverter
- All tests passing with proper fixtures and mocking
Benefits:
- Seamless authentication for remote agent calls
- Automatic credential propagation across agent boundaries
- Support for both session-based and user-based authentication
- Clean separation of concerns with dedicated credential service
Breaking Changes:
- None (backward compatible - credential_service is optional)
Related: A2A authentication and secure agent communication
* revert
* revert
* feat: Add A2A authentication middleware with TIP token propagation support
- Add A2AAuthMiddleware for extracting auth tokens from requests
- Support both Authorization header and query string authentication methods
- Implement TIP (Trust Identity Propagation) token exchange via IdentityClient
- Add VeCredentialService integration for credential storage and retrieval
- Support workload token generation and propagation in request scope
- Add RemoteVeAgent with automatic credential injection from context
- Enhance credential service with ADK BaseCredentialService interface
- Add comprehensive test coverage for middleware and credential service
Key features:
* Extract JWT tokens and delegation chains from incoming requests
* Exchange TIP tokens for workload access tokens using IdentityClient
* Store credentials in credential service with app_name and user_id scoping
* Inject authentication tokens into remote agent HTTP clients at runtime
* Support multiple authentication methods (header/querystring)
This enables secure A2A communication with automatic credential propagation
across the Volcengine Agent runtimes.
* feat(identity): add unit test for middleware and credential service
* fix tests
* Update test_ve_a2a_middlewares.py
* Make credential_service parameter optional
Updated the VeA2AServer constructor and init_app function to allow credential_service to be optional by defaulting it to None. This increases flexibility for cases where credentials are not required.
* Fix example class name in docstrings
Replaces incorrect 'VeA2ACredentialService' with 'VeCredentialService' in usage examples within docstrings to ensure accuracy and prevent confusion for users.
* Initialize token variable in A2AAuthMiddleware
Added explicit initialization of the 'token' variable to None in the _extract_token method to ensure it is always defined before use.
* Update docstring examples to use lowercase type values
Changed the example values for 'Type' in the docstring of the permission check method to use lowercase (e.g., 'user', 'action', 'agent') for consistency and clarity.
* Fix type annotation for _identity_client in auth config
Updated the type annotation for _identity_client to use Optional["IdentityClient"] for better type clarity. Also removed unnecessary whitespace in ve_middlewares.py.
* Add VeADK A2A auth switch and utility enhancements
Introduces a new `to_a2a` utility in `veadk.a2a.utils.agent_to_a2a` to wrap Google ADK's A2A conversion with optional VeADK authentication and credential service integration. Adds comprehensive tests for the auth switch, refactors `RemoteVeAgent` to ensure pre-run initialization/auth logic always executes, and renames `credential_service.py` to `ve_credential_service.py` for clarity.
* Remove unused test and fix import formatting
Deleted test_to_a2a_auth_switch.py as it is no longer needed. Fixed import formatting in several files for consistency by removing extra spaces. Also removed an unused import in identity_client.py.
* Update A2A agent docs with authentication instructions
Added detailed instructions for enabling and configuring authentication in VeADK A2A Server, including server and client usage, supported authentication methods, and new parameters for the to_a2a function.1 parent 34db2c6 commit 01de6ff
File tree
19 files changed
+2151
-112
lines changed- docs/content/3.agent
- tests
- auth
- veadk
- a2a
- utils
- auth
- configs
- integrations/ve_identity
- tools/builtin_tools
- utils
19 files changed
+2151
-112
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
54 | 99 | | |
55 | 100 | | |
| 101 | + | |
| 102 | + | |
56 | 103 | | |
57 | 104 | | |
58 | 105 | | |
| |||
62 | 109 | | |
63 | 110 | | |
64 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
0 commit comments