feat(a2a): add TOTP second-factor authentication for A2A server/client [WIP - untested]#5147
Open
rjmendez wants to merge 3 commits intocrewAIInc:mainfrom
Open
feat(a2a): add TOTP second-factor authentication for A2A server/client [WIP - untested]#5147rjmendez wants to merge 3 commits intocrewAIInc:mainfrom
rjmendez wants to merge 3 commits intocrewAIInc:mainfrom
Conversation
Add TOTPServerAuthScheme and TOTPClientAuthScheme to enable TOTP-based MFA for A2A protocol endpoints. Supports per-peer seeds (identified by bearer token mapping) and single shared seed mode. Server: validates X-TOTP header with pyotp, fails closed (401 on missing/invalid). Client: injects X-TOTP header on every outgoing request. - New file: src/crewai/a2a/auth/totp_scheme.py - Updated auth __init__.py exports - Added pyotp>=2.9.0 dependency - Tests covering valid/missing/wrong/expired TOTP, per-peer seeds, client injection
Author
|
Status: Work in Progress — untested This PR is not yet ready for merge. Outstanding items before review:
Marking as draft pending those fixes. |
Author
Update: Middleware Integration CompleteAdded What's new in this commit:
The TOTP auth scheme is now fully integrated at both the authentication layer and the request middleware layer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In agent mesh deployments (multiple A2A agents communicating peer-to-peer), a stolen bearer token alone should not be sufficient to impersonate an agent or issue dangerous commands. TOTP as a second factor ensures that even if a token is compromised, an attacker cannot authenticate without the shared TOTP seed.
What This Adds
TOTPServerAuthScheme(server-side validation)ServerAuthScheme(e.g.,SimpleTokenAuth) as a delegate for bearer token validationX-TOTPheader with a valid 6-digit TOTP code on every request{"mrpink": "SEED1", "charlie": "SEED2"})pyotp.TOTP(seed).verify(code, valid_window=1)— allows ±30s clock driftTOTPClientAuthScheme(client-side injection)ClientAuthScheme(e.g.,BearerTokenAuth) as a delegateX-TOTP: <code>header on every outgoing requestA2A_TOTP_SEEDenv varUsage Example
Design Notes
valid_window=1allows ±30 seconds of clock drift between agents — sufficient for well-configured systems while limiting replay attack windowsServerAuthScheme/ClientAuthSchemeauthenticate_with_totp()is a separate method fromauthenticate()since the base ABC signature only passes the token — server middleware needs to extract and pass the X-TOTP header separatelySecretStr(viaCoercedSecretStr) to prevent accidental loggingChanges
src/crewai/a2a/auth/totp_scheme.py— new file with both schemessrc/crewai/a2a/auth/__init__.py— exports updatedpyproject.toml— addedpyotp>=2.9.0dependencytests/a2a/test_totp_auth.py— comprehensive testsTests Cover