Commit 45168fc
feat: SPIFFE/SPIRE Integration Architecture for Agent Identity (#695)
* feat: add SPIFFE/SPIRE configuration for agent identity
Add environment variables to support SPIFFE workload identity integration
for AI agents and services. This enables cryptographic machine identity
with configurable migration phases:
- SPIFFE_ENABLED: Toggle SPIFFE integration
- SPIFFE_AUTH_MODE: Migration phases (disabled→optional→preferred→required)
- SPIFFE_ENDPOINT_SOCKET: SPIRE Agent Workload API socket
- SPIFFE_TRUST_DOMAIN: Trust domain for identity hierarchy
- SPIFFE_LEGACY_JWT_WARNING: Track legacy auth usage during migration
- SPIFFE_SVID_TTL_SECONDS: Certificate lifetime configuration
- SPIFFE_JWT_AUDIENCES: Allowed JWT-SVID audiences
Related to: MCP Context Forge integration (PR #684)
* docs: add SPIFFE/SPIRE integration architecture for agent identity
This architecture document outlines how to integrate SPIRE (SPIFFE Runtime
Environment) into RAG Modulo to provide cryptographic workload identities
for AI agents. This enables zero-trust agent authentication and secure
agent-to-agent (A2A) communication.
Key architectural decisions:
- JWT-SVIDs for stateless verification (vs X.509 for mTLS)
- Trust domain: spiffe://rag-modulo.example.com
- Integration with IBM MCP Context Forge (PR #684)
- Capability-based access control for agents
- 5-phase implementation plan
Agent types defined:
- search-enricher: MCP tool invocation
- cot-reasoning: Chain of Thought orchestration
- question-decomposer: Query decomposition
- source-attribution: Document source tracking
- entity-extraction: Named entity recognition
- answer-synthesis: Answer generation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(spiffe): implement SPIFFE/SPIRE agent authentication
This commit implements the SPIFFE/SPIRE integration for AI agent
authentication as designed in docs/architecture/spire-integration-architecture.md.
Key changes:
- Add py-spiffe dependency for SPIFFE JWT-SVID support
- Create core SPIFFE authentication module (spiffe_auth.py) with:
- SPIFFEConfig for environment-based configuration
- AgentPrincipal dataclass for authenticated agent identity
- SPIFFEAuthenticator for JWT-SVID validation
- AgentType and AgentCapability enums
- Helper functions for SPIFFE ID parsing and building
- Create Agent data model with SQLAlchemy:
- Agent model with SPIFFE ID, type, capabilities, status
- Relationships to User (owner) and Team
- Status management (active, suspended, revoked)
- Add Agent repository, service, and router layers:
- Full CRUD operations for agents
- Agent registration with SPIFFE ID generation
- Status and capability management
- JWT-SVID validation endpoint
- Extend AuthenticationMiddleware to detect and validate SPIFFE JWT-SVIDs
- Add SPIRE deployment configuration templates:
- server.conf, agent.conf for SPIRE configuration
- docker-compose.spire.yml for local development
- README.md with deployment instructions
- Add comprehensive unit tests for all SPIFFE components
Reference: PR #695
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(spiffe): address PR review feedback for SPIFFE/SPIRE integration
Critical fixes:
- Add database migration for agents table (migrations/add_agents_table.sql)
- Fix signature verification security: failed validation now always rejects
(prevents fallback bypass attack)
- Fix timezone handling: use UTC consistently for JWT timestamps
Improvements:
- Align env vars with .env.example (SPIFFE_JWT_AUDIENCES, SPIFFE_SVID_TTL_SECONDS)
- Add capability enforcement decorator (require_capabilities)
- Add OpenAPI tags metadata for agents endpoint
- Update and expand unit tests (47 tests passing)
Addresses review comments from PR #695.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(spiffe): rename metadata to agent_metadata to avoid SQLAlchemy reserved word
SQLAlchemy's Declarative API reserves the 'metadata' attribute name.
Renamed the field to 'agent_metadata' in the model while keeping the
database column name as 'metadata' via explicit column name mapping.
This also updates the schema to use validation_alias for proper
model_validate() from ORM objects.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(test): add missing trust_domain to AgentPrincipal in test
The test_validate_jwt_svid_valid test was failing because AgentPrincipal
requires a trust_domain field which was not being provided.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(spiffe): Address comprehensive PR review feedback
Critical fixes:
- Fix timezone-naive datetime to use UTC throughout (agent.py, agent_repository.py)
- Change default agent status from ACTIVE to PENDING for approval workflow
- Add RuntimeError when SPIFFE enabled but py-spiffe library missing
- Restrict trust domain to configured value only (security fix)
High priority security fixes:
- Add capability validation per agent type (ALLOWED_CAPABILITIES_BY_TYPE)
- Add authentication requirement to SPIFFE validation endpoint
- Reject user-specified trust domains that don't match server config
Code quality improvements:
- Add OpenAPI tags metadata for agent router documentation
- Fix require_capabilities decorator type hints (ParamSpec, TypeVar)
- Add composite database indexes (owner+status, type+status, team+status)
- Update migration script with new composite indexes
Test updates:
- Update test_register_agent_with_custom_trust_domain to verify rejection
- Fix test_authenticator_creates_principal_with_fallback to mock spiffe module
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6701795 commit 45168fc
File tree
23 files changed
+5956
-3
lines changed- backend
- core
- rag_solution
- models
- repository
- router
- schemas
- services
- deployment/spire
- docs/architecture
- migrations
- tests/unit
- core
- services
23 files changed
+5956
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
5 | 13 | | |
6 | 14 | | |
7 | 15 | | |
| |||
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
22 | 34 | | |
23 | 35 | | |
24 | 36 | | |
| |||
206 | 218 | | |
207 | 219 | | |
208 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
209 | 273 | | |
210 | 274 | | |
211 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
212 | 279 | | |
213 | 280 | | |
214 | 281 | | |
| |||
221 | 288 | | |
222 | 289 | | |
223 | 290 | | |
224 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
225 | 296 | | |
226 | 297 | | |
| 298 | + | |
227 | 299 | | |
228 | 300 | | |
229 | 301 | | |
230 | 302 | | |
231 | 303 | | |
232 | 304 | | |
233 | 305 | | |
| 306 | + | |
234 | 307 | | |
235 | 308 | | |
236 | 309 | | |
| |||
0 commit comments