Skip to main content

Module auth

Module auth 

Source
Expand description

Server-side authentication interceptors.

These implement ServerInterceptor and reject unauthenticated requests before the handler runs. They read the request’s HTTP headers from the CallContext — which the JSON-RPC, REST, gRPC, and WebSocket bindings all populate — so a single interceptor guards every transport.

InterceptorValidatesFeature
ApiKeyAuthInterceptorA configurable header against allowed keys (constant-time)always
BearerTokenAuthInterceptorAuthorization: Bearer <token> against allowed tokens (constant-time)always
JwtAuthInterceptor (auth-jwt feature)A signed JWT (HS256/RS256/ES256), with static or remote (JWKS) keysauth-jwt

§Error mapping

An interceptor rejects a request by returning an A2aError; these return A2aError::unauthenticated, which each binding answers with its own status (ADR 0014, audit N36): HTTP 401 with a WWW-Authenticate challenge on both HTTP bindings (the JSON-RPC body stays -32600), gRPC UNAUTHENTICATED. A custom interceptor refusing an authenticated caller returns A2aError::permission_denied for 403 / PERMISSION_DENIED. The WebSocket binding checks per message after the upgrade, so it has no status to send and answers the body alone. None of these interceptors reveals why a credential was rejected.

§Example

use a2a_protocol_server::auth::BearerTokenAuthInterceptor;
use a2a_protocol_server::RequestHandlerBuilder;

let handler = RequestHandlerBuilder::new(Exec)
    .with_agent_card(card())
    .with_interceptor(BearerTokenAuthInterceptor::new(["secret-token-1", "secret-token-2"]))
    .build()
    .unwrap();

Modules§

caller_id
The caller identities the bundled authenticators record (audit register R12).
jwtauth-jwt
JWT bearer-token authentication (HS256 / RS256 / ES256).
throttle
Throttling a peer that keeps failing authentication (spec §13.4: agents SHOULD implement rate limiting to prevent brute-force attacks).

Structs§

ApiKeyAuthInterceptor
Rejects requests whose API-key header is absent or not in the allowed set.
AuthFailureThrottle
Refuses a peer that has failed authentication too often; see the module docs.
AuthFailureThrottleConfig
Configuration for an AuthFailureThrottle.
AuthenticatedPrincipal
A resolved authenticated principal, stashed for downstream interceptors.
BearerTokenAuthInterceptor
Rejects requests whose Authorization: Bearer <token> is absent or whose token is not in the allowed set.
CredentialSet
The credentials an interceptor accepts. Cloning gives another handle to the same set.
ForwardedClientCert
Where a trusted proxy forwards the client certificate it verified, and which peers are trusted to forward one.
Jwks
A set of asymmetric verification keys (an RFC 7517 JWK Set).
JwtAuthInterceptor
A ServerInterceptor that authenticates requests with a signed JWT.
JwtValidator
The set of claim checks applied after a JWT’s signature verifies.
MutualTlsAuthInterceptor
Names the caller from the certificate it presented in a mutual-TLS handshake (CallContext::peer_certificate), and refuses a call that arrived without one.

Constants§

AWS_ALB_CERT_HEADER
The header an AWS Application Load Balancer in mutual-TLS verify mode forwards the leaf certificate in.
ENVOY_XFCC_HEADER
The header Envoy and Istio forward the client certificate in.
MAX_ACTORS
The most actors a chain may name; a longer one is refused.
MIN_HS256_SECRET_LEN
The shortest HS256 secret JwtValidator accepts, in bytes.

Type Aliases§

SharedPrincipal
Convenience alias for a shared principal.