Repository navigation
fix(a2a): require client_id and client_secret for OAuth agents on create - #7673
Shanmukh-l33t wants to merge 2 commits into
Conversation
A2AAgentCreate accepted auth_type oauth with an oauth_config that carried no client credentials, so registration succeeded and the agent failed only at first invocation. The create validator now rejects a missing or blank client_id or client_secret with a 422 that names the field. Updates are unchanged because they may keep the stored credentials. Fixes IBM#7669. Signed-off-by: Shanmukh Dheekonda <Shanmukh-l33t@users.noreply.github.com>
marekdano
left a comment
There was a problem hiding this comment.
@Shanmukh-l33t - thanks for your contribution!
Please see our findings below
| grant_type = v.get("grant_type", _A2A_OAUTH_GRANT_TYPE) | ||
| if grant_type != _A2A_OAUTH_GRANT_TYPE: | ||
| raise ValueError(f"A2A agents support only the {_A2A_OAUTH_GRANT_TYPE} OAuth grant type, got '{grant_type}'") | ||
| if require_credentials: |
There was a problem hiding this comment.
Blocking: The check requires client_secret for every oauth_config. Token requests do not always need it.
_apply_token_endpoint_auth supports token_endpoint_auth_method values none and private_key_jwt. Neither method sends a client_secret. none needs no client_id either.
Create now rejects configs that worked before. The error text says the client_credentials grant requires both fields. That is not correct for these methods.
Fix:
- Skip the
client_secretcheck whentoken_endpoint_auth_methodisnoneorprivate_key_jwt. - Skip the
client_idcheck when it isnone. - Add tests for both methods.
There was a problem hiding this comment.
Fixed in 3f1084f. The credential check now skips client_secret for token_endpoint_auth_method none and private_key_jwt, and skips client_id for none. private_key_jwt still requires client_id (its assertion iss/sub come from it). Tests added for both methods, plus a negative case for private_key_jwt without client_id.
| The validated configuration. | ||
| """ | ||
| return _validate_a2a_oauth_config(v) | ||
| return _validate_a2a_oauth_config(v, require_credentials=True) |
There was a problem hiding this comment.
Blocking: This mode="before" field validator runs for every non-null oauth_config. It cannot read auth_type.
admin_add_a2a_agent assembles oauth_config from any oauth_* form field. It sends the config with the submitted auth_type. A bearer, basic or none agent that carries a partial oauth_config now gets a 422 for a missing credential.
Fix: move the check to a model_validator(mode="after"). Run it only when auth_type == "oauth".
There was a problem hiding this comment.
Fixed in 3f1084f. The check moved out of the mode="before" field validator into a model_validator(mode="after") that runs only when auth_type == "oauth". _validate_a2a_oauth_config is back to its original signature. A bearer/basic/none agent with a partial oauth_config no longer gets a 422.
| build({**CONFIG, "token_url": "http://10.0.0.5/token"}) | ||
|
|
||
|
|
||
| class TestA2AOAuthCredentialsRequiredOnCreate: |
There was a problem hiding this comment.
Non-blocking: Two cases have no test:
- A non-
oauthauth_typewith anoauth_config. token_endpoint_auth_methodnoneorprivate_key_jwton create.
Add both. They cover the two comments above.
There was a problem hiding this comment.
Added in 3f1084f: test_methods_that_send_no_secret_do_not_require_one (none with no credentials, private_key_jwt with only client_id), test_private_key_jwt_still_requires_client_id, and test_non_oauth_auth_type_ignores_partial_oauth_config (bearer/basic/none). Also merged current main (conflicts in schemas.py and test_admin.py resolved keeping both sides). Two upstream tests and one card-import test built an OAuth agent without credentials; they now supply client_id/client_secret.
Move the A2A OAuth credential check to a model_validator(mode=after) that runs only for auth_type=oauth, and skip client_secret for none/private_key_jwt and client_id for none. Signed-off-by: Shanmukh Dheekonda <Shanmukh-l33t@users.noreply.github.com>
Fixes #7669
Summary
A2AAgentCreateacceptedauth_type: "oauth"with anoauth_configthat had noclient_idorclient_secret. Registration succeeded and the agent read as active, and the failure only appeared at first invocation. A card import suggestion (grant type, token URL and scopes, no credentials) posted unchanged produces this state.Root cause
_validate_a2a_oauth_confignormalised the URLs and rejected grant types other thanclient_credentials, but never checked that the credentials that grant needs were present.Fix
_validate_a2a_oauth_configtakes arequire_credentialsflag.A2AAgentCreatepassesTrue, so a missing, empty or blankclient_idorclient_secretraises aValueErrornaming the field, which FastAPI returns as 422.A2AAgentUpdateis unchanged: an update may omit the credentials and keep the stored ones (the masked placeholder flow depends on this).Three existing admin form tests in
test_admin.pybuilt a credential-less config and expected success. They now expect the 422 and thatregister_agentis not called (one of them gets the same outcome with a config that only lacksclient_secret).Not in scope
auth_type: "oauth"with nooauth_configat all is still accepted on create. The issue is about a config that is present but lacks credentials.Reviewability
triageVerification
New tests, run on the unmodified parent commit (red), then with the fix (green):
Wider targeted run after the fix:
Not run:
make lintas a whole,make coverage, the schemas doctest for the new example (the doctest collection needs a configured.envthat this environment lacks), the live gateway suite, sqlite/postgres runs.ruffandblackreport the same findings on the touched files before and after the change.AI assistance was used to prepare this change; I reviewed the diff and ran the tests above.