Research/Architecture
Architecture

How JWT tokens flow through adapters and clients

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:

  1. No Shared State: JWT tokens stored per-adapter-instance
  2. Per-Request Context: security_context created fresh for each call
  3. Isolated Processing: Each request thread has its own context
  4. 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

  1. Cryptographically Secure: JWT validation with proper signature verification
  2. Non-Bypassable: All requests flow through MACAW policy enforcement
  3. Auditable: Complete trail with correct user attribution
  4. Scalable: Works with any number of concurrent users
  5. Standard Compliant: Uses industry-standard JWT/OIDC flows

For Operations Teams

  1. Simple Deployment: Standard JWT integration patterns
  2. Zero Vendor Lock-in: Works with any OIDC/JWT provider
  3. Monitoring Ready: Full audit trails and policy enforcement logs
  4. 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.

Ready to implement agentic access control?

Start with the Developer tier - free forever with full security features.