|
1 | 1 | # CapiscIO SDK (Python) |
2 | 2 |
|
3 | | -**Runtime security middleware for A2A (Agent-to-Agent) protocol agents** |
| 3 | +**Enforcement-First Security for A2A Agents.** |
4 | 4 |
|
5 | 5 | [](https://badge.fury.io/py/capiscio-sdk) |
6 | 6 | [](https://opensource.org/licenses/Apache-2.0) |
7 | 7 | [](https://www.python.org/downloads/) |
8 | 8 |
|
9 | | -## What is CapiscIO SDK? |
| 9 | +**CapiscIO** is the "Customs Officer" for your AI Agent. It provides military-grade Identity and Integrity enforcement for the [Agent-to-Agent (A2A) Protocol](https://github.com/google/A2A) with **zero configuration**. |
10 | 10 |
|
11 | | -CapiscIO SDK provides **always-on runtime protection** for agents using the [A2A (Agent-to-Agent) protocol](https://github.com/google/A2A). It wraps your agent executor to validate incoming requests, verify signatures, and protect against malicious actors—all without requiring peer cooperation. |
| 11 | +## 🚀 The 60-Second Upgrade |
12 | 12 |
|
13 | | -### Key Features |
14 | | - |
15 | | -- ✅ **Message validation** - Schema and protocol compliance checking |
16 | | -- ✅ **Signature verification** - JWS/JWKS cryptographic validation (RFC 7515) |
17 | | -- ✅ **Upstream protection** - Validate agents you call |
18 | | -- ✅ **Downstream protection** - Validate agents calling you |
19 | | -- ✅ **Rate limiting** - Token bucket algorithm |
20 | | -- ✅ **Caching** - Performance-optimized validation results |
21 | | -- ✅ **Three integration patterns** - Minimal, explicit, or decorator |
22 | | - |
23 | | -## Installation |
24 | | - |
25 | | -```bash |
26 | | -pip install capiscio-sdk |
27 | | -``` |
28 | | - |
29 | | -## Quick Start |
30 | | - |
31 | | - |
32 | | -### Pattern 1: Minimal (One-liner with Preset) |
| 13 | +Turn any FastAPI application into a Verified A2A Agent in 3 lines of code. |
33 | 14 |
|
34 | 15 | ```python |
35 | | -from capiscio_sdk import secure, SecurityConfig |
36 | | -from a2a.server.request_handlers import DefaultRequestHandler |
37 | | -from a2a.server.tasks import InMemoryTaskStore |
38 | | - |
39 | | -# Wrap your agent with security (production defaults) |
40 | | -agent = secure(MyAgentExecutor(), SecurityConfig.production()) |
41 | | - |
42 | | -# Use in A2A request handler |
43 | | -handler = DefaultRequestHandler( |
44 | | - agent_executor=agent, |
45 | | - task_store=InMemoryTaskStore() |
46 | | -) |
47 | | - |
48 | | -# Access validation results (three-dimensional scoring) |
49 | | -result = await agent.validate_agent_card(card_url) |
50 | | -print(result.compliance.total, result.trust.total, result.availability.total) |
51 | | -``` |
| 16 | +from fastapi import FastAPI |
| 17 | +from capiscio_sdk.simple_guard import SimpleGuard |
| 18 | +from capiscio_sdk.integrations.fastapi import CapiscioMiddleware |
52 | 19 |
|
53 | | -### Pattern 2: Granular Control |
| 20 | +# 1. Initialize Guard (Auto-generates keys in dev_mode) |
| 21 | +guard = SimpleGuard(dev_mode=True) |
54 | 22 |
|
55 | | -```python |
56 | | -from capiscio_sdk import CapiscIOSecurityExecutor, SecurityConfig |
57 | | - |
58 | | -# Start with a preset, customize what matters to you |
59 | | -config = SecurityConfig.production() |
60 | | -config.downstream.rate_limit_requests_per_minute = 100 # Higher rate limit |
61 | | -config.downstream.require_signatures = True # Enforce signatures |
62 | | -config.upstream.test_endpoints = True # Test before calling |
63 | | -config.fail_mode = "monitor" # Log but don't block yet |
64 | | - |
65 | | -secure_agent = CapiscIOSecurityExecutor( |
66 | | - delegate=MyAgentExecutor(), |
67 | | - config=config |
68 | | -) |
69 | | -``` |
| 23 | +app = FastAPI() |
70 | 24 |
|
71 | | -### Pattern 3: Environment-Driven (12-Factor App) |
| 25 | +# 2. Add Enforcement Middleware |
| 26 | +app.add_middleware(CapiscioMiddleware, guard=guard) |
72 | 27 |
|
73 | | -```python |
74 | | -from capiscio_sdk import secure_agent, SecurityConfig |
75 | | -from a2a import AgentExecutor, RequestContext, EventQueue |
76 | | - |
77 | | -@secure_agent(config=SecurityConfig.from_env()) |
78 | | -class MyAgentExecutor(AgentExecutor): |
79 | | - async def execute(self, context: RequestContext, event_queue: EventQueue): |
80 | | - # Your agent logic - config loaded from env vars |
81 | | - pass |
82 | | - |
83 | | -# Already secured - use directly! |
84 | | -handler = DefaultRequestHandler(agent_executor=MyAgentExecutor()) |
| 28 | +@app.post("/agent/task") |
| 29 | +async def handle_task(request: Request): |
| 30 | + # 🔒 Only reachable if Identity + Integrity are verified |
| 31 | + caller = request.state.agent_id |
| 32 | + return {"status": "accepted", "verified_caller": caller} |
85 | 33 | ``` |
86 | 34 |
|
87 | | -**All 16 configuration options documented in the [Configuration Guide](https://docs.capisc.io/sdk-python/guides/configuration/).** |
88 | | - |
89 | | -## Why CapiscIO? |
90 | | - |
91 | | -### The Problem |
| 35 | +## 🛡️ What You Get (Out of the Box) |
92 | 36 |
|
93 | | -When building A2A agents, you face security risks from: |
94 | | -- **Malicious downstream agents** sending invalid/malicious requests |
95 | | -- **Broken upstream dependencies** with invalid agent cards |
96 | | -- **Protocol violations** causing runtime failures |
97 | | -- **Missing signatures** with no authenticity verification |
| 37 | +1. **Zero-Config Identity**: |
| 38 | + * Auto-generates **Ed25519** keys and `agent-card.json` on first run. |
| 39 | + * No manual key management required for development. |
98 | 40 |
|
99 | | -### The Solution |
| 41 | +2. **Payload Integrity**: |
| 42 | + * Enforces **SHA-256 Body Hash (`bh`)** verification. |
| 43 | + * Blocks tampered payloads instantly (returns `403 Forbidden`). |
100 | 44 |
|
101 | | -CapiscIO wraps your agent executor and provides: |
| 45 | +3. **Replay Protection**: |
| 46 | + * Enforces strict **60-second** token expiration (`exp`). |
| 47 | + * Prevents replay attacks and ensures freshness. |
102 | 48 |
|
103 | | -1. **Downstream Protection** - Validates all incoming requests |
104 | | -2. **Upstream Protection** - Validates agents you call |
105 | | -3. **Always-On** - Works without peer cooperation |
106 | | -4. **Performance** - Caching and parallel validation |
107 | | -5. **Three-Dimensional Scoring** - Compliance, trust, and availability insights |
| 49 | +4. **Performance Telemetry**: |
| 50 | + * Adds `<1ms` overhead. |
| 51 | + * Includes `Server-Timing` headers for transparent monitoring. |
108 | 52 |
|
109 | | -## Configuration |
110 | | - |
111 | | -### Presets |
112 | | - |
113 | | -```python |
114 | | -# Development - Permissive, verbose logging |
115 | | -SecurityConfig.development() |
| 53 | +## Installation |
116 | 54 |
|
117 | | -# Production - Balanced (default) |
118 | | -SecurityConfig.production() |
| 55 | +```bash |
| 56 | +pip install capiscio-sdk |
| 57 | +``` |
119 | 58 |
|
120 | | -# Strict - Maximum security |
121 | | -SecurityConfig.strict() |
| 59 | +## How It Works |
122 | 60 |
|
123 | | -# From environment variables |
124 | | -SecurityConfig.from_env() |
125 | | -``` |
| 61 | +### 1. The Handshake |
| 62 | +CapiscIO enforces the **A2A Trust Protocol**: |
| 63 | +* **Sender**: Signs the request body (JWS + Body Hash). |
| 64 | +* **Receiver**: Verifies the signature and re-hashes the body to ensure integrity. |
126 | 65 |
|
127 | | -### Custom Configuration |
| 66 | +### 2. The "Customs Officer" |
| 67 | +The `SimpleGuard` acts as a local authority. It manages your agent's "Passport" (Agent Card) and verifies the "Visas" (Tokens) of incoming requests. |
128 | 68 |
|
129 | | -```python |
130 | | -from capiscio_sdk import SecurityConfig, DownstreamConfig, UpstreamConfig |
131 | | - |
132 | | -config = SecurityConfig( |
133 | | - downstream=DownstreamConfig( |
134 | | - validate_schema=True, |
135 | | - verify_signatures=True, |
136 | | - require_signatures=False, |
137 | | - enable_rate_limiting=True, |
138 | | - rate_limit_requests_per_minute=100 |
139 | | - ), |
140 | | - upstream=UpstreamConfig( |
141 | | - validate_agent_cards=True, |
142 | | - verify_signatures=True, |
143 | | - cache_validation=True, |
144 | | - cache_timeout=3600 # seconds |
145 | | - ), |
146 | | - fail_mode="block", # "block" | "monitor" | "log" |
147 | | - timeout_ms=5000 |
148 | | -) |
| 69 | +### 3. Telemetry |
| 70 | +Every response includes a `Server-Timing` header showing exactly how fast the verification was: |
| 71 | +```http |
| 72 | +Server-Timing: capiscio-auth;dur=0.618;desc="CapiscIO Verification" |
149 | 73 | ``` |
150 | 74 |
|
151 | 75 | ## Documentation |
152 | 76 |
|
153 | | -- [Quickstart Guide](docs/quickstart.md) |
154 | | -- [Configuration Reference](docs/configuration.md) |
155 | | -- [API Documentation](docs/api-reference.md) |
156 | | -- [Examples](examples/) |
157 | | - |
158 | | -## Roadmap |
159 | | - |
160 | | -- **V1.0** (Q4 2025) - Core middleware (this package) |
161 | | -- **V2.0** (Q2 2026) - Extension protocol (validation feedback) |
162 | | -- **V3.0** (Q3 2026) - Platform integration (trust network) |
163 | | -- **V4.0** (Q4 2026) - Enterprise features (policies, audit logs) |
164 | | - |
165 | | -## Contributing |
166 | | - |
167 | | -We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 77 | +- [Official Documentation](https://docs.capisc.io) |
| 78 | +- [A2A Protocol Spec](https://github.com/google/A2A) |
168 | 79 |
|
169 | 80 | ## License |
170 | 81 |
|
171 | 82 | Apache License 2.0 - see [LICENSE](LICENSE) for details. |
172 | | - |
173 | | -## About A2A |
174 | | - |
175 | | -The [Agent-to-Agent (A2A) protocol](https://github.com/google/A2A) is an open standard for agent interoperability, supported by Google and 50+ partners including Salesforce, ServiceNow, SAP, Intuit, and more. CapiscIO provides the security layer for production A2A deployments. |
176 | | - |
177 | | -## Support |
178 | | - |
179 | | -- **Issues:** [GitHub Issues](https://github.com/capiscio/capiscio-sdk-python/issues) |
180 | | -- **Discussions:** [GitHub Discussions](https://github.com/capiscio/capiscio-sdk-python/discussions) |
181 | | -- **Documentation:** [docs.capisc.io](https://docs.capisc.io) |
182 | | -- **Website:** [capisc.io](https://capisc.io) |
0 commit comments