MACAW Identity Flow Architecture V2 ποΈ
A Research Report on MACAW's Layered Identity Architecture
Executive Summary
This document presents MACAW's evolved identity architecture that achieves transparent security through clean separation of concerns. By leveraging the original MACAW security_context design with modern JWT integration, we've created an architecture that is both enterprise-grade secure and developer-friendly simple.
Key Achievement: Applications can implement enterprise identity integration by simply passing a JWT token, while maintaining complete multi-user safety and policy enforcement.
Architecture Overview
The Layer Cake Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β APPLICATION LAYER β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β Financial β β Document β β Data β β
β β Analyzer β β Processor β β Orchestrator β β
β β β β β β β β
β β β’ Business β β β’ Business β β β’ Business β β
β β Logic Only β β Logic Only β β Logic β β
β β β’ No Auth Code β β β’ No Auth Code β β β’ Multi-User β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββββ¬ββββββββββββββββββββ¬ββββββββββββββββββββ¬ββββββββββ
β JWT Token β JWT Token β JWT Token
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ADAPTER LAYER β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β SecureOpenAI β β SecureClaude β β SecureAPI β β
β β β β β β β β
β β β’ Identity β β β’ Identity β β β’ Identity β β
β β Agnostic β β Agnostic β β Agnostic β β
β β β’ Just Stores β β β’ Just Stores β β β’ Just β β
β β JWT β β JWT β β Stores β β
β β β’ Normal API β β β’ Normal API β β JWT β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββββ¬ββββββββββββββββββββ¬ββββββββββββββββββββ¬ββββββββββ
β JWT Token β JWT Token β JWT Token
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MACAW CLIENT LAYER β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MACAWClient β β
β β β β
β β βββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β JWT β security_context Conversion β β β
β β β β β β
β β β jwt_claims = validate_jwt_token(jwt) β β β
β β β security_context = { β β β
β β β "company": jwt_claims["organization"], β β β
β β β "business_unit": jwt_claims["bu"], β β β
β β β "team": jwt_claims["team"], β β β
β β β "user": jwt_claims["sub"] β β β
β β β } β β β
β β βββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ
β security_context
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MACAW AGENT LAYER β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MACAWAgent β β
β β β β
β β invoke_tool_via_local_agent( β β
β β tool_name, operation, params, β β
β β security_context=security_context β ORIGINAL! β β
β β ) β β
β β β β
β β # UNCHANGED - Uses existing flow β β
β β security_metadata.update(security_context) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ
β security_metadata (with user context)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β POLICY & ENFORCEMENT β
β βββββββββββββββββββ βββββββββββββββββββββββββββ β
β β PolicyResolver β β Policy Enforcement β β
β β β β Point (PEP) β β
β β β’ Hierarchical β ββββββββββββ β β β
β β Lookup β β β’ Alice: GPT-3.5 β β
β β β’ org β BU β β β 500 tokens β β
β β team β role β β β’ Bob: GPT-4 β β
β β β’ Dynamic β β 2000 tokens β β
β β Context β β β’ Audit Logging β β
β βββββββββββββββββββ βββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Identity Flow Patterns
Pattern 1: Single User Application
Alice's Workflow:
βββββββββββββββββ
Step 1: Authentication
βββββββββββββββ JWT βββββββββββββββββββ
β Alice logs βββββββββββΆβ Financial β
β into β β Analyzer β
β Keycloak β β β
β β β analyzer. β
β alice_jwt β β connect_with_ β
β β β jwt(alice_jwt) β
βββββββββββββββ βββββββββββββββββββ
Step 2: Business Operation
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Alice requests ββββββΆβ Normal OpenAI ββββββΆβ MACAW applies β
β Q4 analysis β β API call β β Alice's policiesβ
β β β β β β
β analyzer. β β client.chat. β β β’ GPT-3.5 only β
β analyze_report β β completions. β β β’ 500 tokens β
β ("Q4") β β create(...) β β β’ Audit logged β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Result: Alice gets appropriate analysis within her policy constraints
Pattern 2: Multi-User Orchestrator (SECURE)
Concurrent Multi-User Safety:
ββββββββββββββββββββββββββββ
Time T1: Alice's Request
βββββββββββββββ alice_jwt βββββββββββββββββββ security_context βββββββββββββββββββ
β Alice ββββββββββββββΆβ Shared βββββββββββββββββββββΆβ Alice's policiesβ
β Financial β β Orchestrator β β applied β
β Request β β β β β
βββββββββββββββ β Each request β βββββββββββββββββββ
β creates fresh β
Time T2: Bob's Request β security_contextβ
βββββββββββββββ bob_jwt β β security_context βββββββββββββββββββ
β Bob ββββββββββββββΆβ Same Instance! βββββββββββββββββββββΆβ Bob's policies β
β Analysis β β β β applied β
β Request β β NO STORED STATE β β β
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Key: NO identity bleed possible - each request is isolated
Pattern 3: Agent Chain with Delegation
Multi-Hop Agent Chain:
βββββββββββββββββββββ
Alice β Orchestrator β Tool A β Tool B
βββββββββββββββ alice_jwt βββββββββββββββββββ alice_context βββββββββββββββββββ
β Alice ββββββββββββββΆβ Orchestrator ββββββββββββββββββΆβ Tool Agent A β
β β β β β β
β "Process β β security_contextβ β Uses Alice's β
β my data" β β = { β β permissions β
β β β company: "FC", β β β
β β β bu: "Analytics"β alice_context β βββββββββββββββ β
β β β user: "alice" βββββββββββββββββΆβ βTool Agent B β β
β β β } β β β β β
β β β β β βUses Alice's β β
β β β β β βpermissions β β
βββββββββββββββ βββββββββββββββββββ β βββββββββββββββ β
βββββββββββββββββββ
Result: Alice's identity and policies flow through entire chain
Technical Deep Dive
JWT to Security Context Conversion
The heart of the new architecture is the clean conversion from JWT tokens to MACAW's native security_context format using the claims mapper:
# Using the claims mapper for JWT to security_context conversion
from macaw_agent.claims_mapper import ClaimsMapper
def _jwt_to_security_context(self, jwt_token: str) -> Dict[str, Any]:
"""Convert JWT to MACAW security_context format using claims mapper"""
# 1. Use claims mapper to handle multi-IDP conversion
claims_mapper = ClaimsMapper()
security_context = claims_mapper.map_jwt_to_security_context(jwt_token)
# 2. The claims mapper handles:
# - JWT validation and signature verification
# - Multi-provider detection (Keycloak, Azure AD, Okta, etc.)
# - Claims mapping per .claims-config.yaml configuration
# - Organization β company mapping for policy hierarchy
# - Role normalization across providers
return security_context
Original MACAW Flow Integration
The beauty of this architecture is that it leverages MACAW's existing security infrastructure without modification:
# In MACAWAgent.invoke_tool_via_local_agent() - UNCHANGED!
def invoke_tool_via_local_agent(self, tool_name, operation, params,
security_context=None):
"""Original MACAW method - no changes needed"""
# ... existing logic in _prepare_invocation() ...
# This line already existed and handles our JWT-derived context!
if security_context:
security_metadata.update(security_context)
# Context flows to PolicyResolver automatically
invocation.security_metadata = security_metadata
Policy Resolution with Dynamic Context
The security_context flows seamlessly through the policy resolution hierarchy:
PolicyResolver Hierarchical Lookup:
βββββββββββββββββββββββββββββββββββ
security_context = {
"company": "FinTech Corp",
"business_unit": "Analytics",
"team": "Reporting",
"user": "alice@fintech.com",
"roles": ["analyst"]
}
Lookup Chain:
1. base:role:analyst β GPT-3.5, 500 tokens (starting point)
2. restrict:org:fintech-corp β No secrets, audit required
3. restrict:bu:analytics β Low temperature, consistency mode
4. restrict:team:reporting β 9-6 EST only, specific data sources
5. filter:clearance:standard β No executive data access
Final Policy (Most Restrictive):
- Model: GPT-3.5 ONLY
- Tokens: 500 MAX
- Hours: 9-6 EST
- Data: Standard clearance only
- Audit: Full logging required
Multi-User Security Analysis
The Previous Vulnerability (Now Fixed)
Before: Delegation stored on agent instances
# DANGEROUS - Multiple users could interfere
alice_app.authenticate_with_delegation(alice_jwt) # Stores on instance
# ... later ...
bob_app.authenticate_with_delegation(bob_jwt) # OVERWRITES Alice!
# ... even later ...
alice_request() # Uses Bob's identity! π¨ SECURITY BREACH
After: Stateless per-request identity
# SAFE - Each request isolated
alice_app.connect_with_jwt(alice_jwt) # Just stores JWT
alice_request() # Creates fresh security_context for Alice
bob_app.connect_with_jwt(bob_jwt) # Different instance or same
bob_request() # Creates fresh security_context for Bob
# IMPOSSIBLE for interference - no shared state
Concurrent User Safety Proof
The architecture ensures multi-user safety through stateless design:
- No Shared State: JWT tokens stored per-adapter-instance
- Per-Request Context:
security_contextcreated fresh for each call - Isolated Processing: Each request thread has its own context
- Clean Separation: Adapter layer remains identity-agnostic
Proof by Design: Even if 1000 users hit the same orchestrator simultaneously, each request gets its own security_context derived from its own JWT, preventing any possibility of identity bleed.
Integration with IAM Setup
Two-Layer Identity Architecture
The wizard's IAM setup and runtime JWT flow work in perfect synergy:
Layer 1: Service Identity (Setup Time)
# macaw-agent.yaml (from wizard)
iam_provider: keycloak
iam_config:
domain: auth.company.com
client_id: macaw-service
client_secret: service-secret-key
Purpose:
- Establishes MACAW service identity
- Enables JWT validation capability
- Sets up trust with identity providers
Layer 2: User Identity (Runtime)
# Application code
analyzer.connect_with_jwt(alice_jwt) # Alice from Keycloak
analyzer.analyze_report("Q4") # Alice's policies applied
Purpose:
- Dynamic user identification per request
- User-specific policy enforcement
- Audit trail with correct attribution
The Complete Flow
Setup Phase (Admin):
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Admin runs βββββΆβ Wizard βββββΆβ MACAW Service β
β wizard β β configures β β trusts β
β β β Keycloak β β Keycloak β
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Runtime Phase (Users):
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Alice logs βββββΆβ Gets JWT from βββββΆβ App passes to β
β into app β β trusted β β MACAW (which β
β β β Keycloak β β can validate) β
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Result: Service setup enables user validation. No conflict, perfect synergy.
Benefits Analysis
For Developers
Before: Complex delegation management
# Developer had to understand:
client.authenticate_with_delegation(jwt)
client.invoke_tool_with_jwt(tool, params, jwt) # REMOVED - not in original SDK
response = client.macaw_client.complex_internal_method(...)
# Security vulnerabilities possible
# Multi-user scenarios dangerous
# Lots of MACAW-specific knowledge required
After: Simple, transparent security
# Developer just needs to understand:
analyzer = FinancialAnalyzer()
analyzer.connect_with_jwt(jwt) # Pass JWT once
result = analyzer.analyze_report("Q4") # Normal business logic
# Security automatic
# Multi-user safe
# No MACAW knowledge required
For Security Teams
- Cryptographically Secure: JWT validation with proper signature verification
- Non-Bypassable: All requests flow through MACAW policy enforcement
- Auditable: Complete trail with correct user attribution
- Scalable: Works with any number of concurrent users
- Standard Compliant: Uses industry-standard JWT/OIDC flows
For Operations Teams
- Simple Deployment: Standard JWT integration patterns
- Zero Vendor Lock-in: Works with any OIDC/JWT provider
- Monitoring Ready: Full audit trails and policy enforcement logs
- Debug Friendly: Clear separation of concerns makes troubleshooting easy
Future Extensions
This architecture provides a solid foundation for future enhancements:
1. Advanced Policy Features
# Future: Dynamic policy adjustment
security_context["risk_score"] = calculate_user_risk(user_history)
security_context["data_classification"] = detect_data_sensitivity(request)
2. Additional Identity Providers
# Future: Multi-IdP support
security_context = self._jwt_to_security_context(jwt_token, idp_hint="github")
3. Federation Scenarios
# Future: Cross-organization workflows
security_context["federation"] = {
"home_org": "FinTech Corp",
"visiting_org": "Partner Inc",
"delegation_scope": ["read_reports"]
}
Conclusion
The Identity Flow Architecture V2 represents a significant evolution in MACAW's security model. By leveraging existing design patterns while adding modern JWT integration, we've achieved:
- Developer Simplicity: Pass JWT once, get transparent security
- Enterprise Security: Cryptographic validation with policy enforcement
- Multi-User Safety: Stateless design prevents identity bleed
- Operational Excellence: Clear patterns with excellent debuggability
Most importantly, this architecture respects MACAW's original design philosophy of transparent security. Applications remain focused on business logic while MACAW handles all security concerns invisibly but thoroughly.
The result is an architecture that is both beautiful in its simplicity and robust in its security guarantees - exactly what enterprise-grade developer tools should aspire to be.
This document represents the culmination of extensive architectural analysis and represents the current state-of-the-art for MACAW's identity integration capabilities.
Copyright MACAW Security. All rights reserved.