Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions extras/scion-a2a-bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ docker run -p 8443:8443 -p 9090:9090 \
- `tasks/pushNotification/get` — list webhooks for a task
- `tasks/pushNotification/delete` — remove a webhook

## Transports

The bridge speaks all three A2A transports through the same a2a-go SDK request
handler, so behaviour (task lifecycle, streaming, push notifications) is
identical across them.

| Transport | Enabled by | Routing | Streaming |
|-----------|-----------|---------|-----------|
| JSON-RPC 2.0 over HTTP | always (`bridge.listen_address`) | per-request, from the URL path | SSE |
| gRPC | `bridge.grpc_listen_address` | fixed: first exposed agent of the first project | server streaming |
| HTTP+JSON (REST) | `bridge.rest_listen_address` | fixed: first exposed agent of the first project | SSE |

Authentication is the same on every transport: the configured `auth.scheme`
(`apiKey`, `bearer`, `hubUAT`, `hubJWT`, or `none`) is enforced for JSON-RPC,
gRPC, and REST alike. gRPC clients pass credentials as metadata (`x-api-key`
or `authorization: Bearer …`); REST clients pass the equivalent HTTP headers.
Per-user schemes (`hubUAT`, `hubJWT`) resolve the caller identity and use it
for Hub writes on all transports.

Auth can only be disabled per transport by explicitly setting
`bridge.grpc_insecure: true` / `bridge.rest_insecure: true`; the bridge refuses
to start with a transport enabled, `auth.scheme: none`, and no matching
insecure flag.

Both extra transports enforce the same 1 MB request body limit as JSON-RPC and
apply a rolling write deadline to SSE streams so long-lived streams are not cut
by the server write timeout.

## TLS

The A2A server listens on plain HTTP. **TLS must be terminated at a reverse proxy** (e.g. Caddy, nginx, or a cloud load balancer) in front of the bridge. The bridge logs a `WARN` at startup as a reminder. Do not expose the bridge port directly to the internet without a TLS-terminating proxy.
Expand All @@ -84,6 +112,8 @@ The A2A server listens on plain HTTP. **TLS must be terminated at a reverse prox
| Port | Purpose |
|------|---------|
| 8443 | A2A HTTP server (JSON-RPC, agent cards, health/metrics) |
| 8444 | A2A gRPC transport (optional, `bridge.grpc_listen_address`) |
| 8445 | A2A HTTP+JSON/REST transport (optional, `bridge.rest_listen_address`) |
| 9090 | Broker plugin RPC (Hub connects here to push agent messages) |

## Setup and onboarding (agent instructions)
Expand Down Expand Up @@ -131,7 +161,11 @@ Edit `scion-a2a-bridge.yaml`. The required fields are:
| `hub.user` | Admin identity the bridge uses for Hub API calls | `a2a-bridge@example.com` |
| `hub.signing_key` | Path to a file containing the Hub's base64-encoded HS256 signing key. Mutually exclusive with `hub.signing_key_secret`. | `/path/to/signing-key.b64` |
| `hub.signing_key_secret` | GCP Secret Manager resource name for the signing key. Mutually exclusive with `hub.signing_key`. | `projects/my-project/secrets/hub-signing-key` |
| `bridge.listen_address` | Address for the A2A HTTP server | `:8443` |
| `bridge.listen_address` | Address for the A2A HTTP server (JSON-RPC) | `:8443` |
| `bridge.grpc_listen_address` | Optional. Address for the A2A gRPC transport. Empty disables it. | `:8444` |
| `bridge.rest_listen_address` | Optional. Address for the A2A HTTP+JSON (REST) transport. Empty disables it. | `:8445` |
| `bridge.grpc_insecure` | Optional. Disable auth on the gRPC transport (explicit opt-in; required if `auth.scheme` is `none`). | `false` |
| `bridge.rest_insecure` | Optional. Disable auth on the REST transport (explicit opt-in; required if `auth.scheme` is `none`). | `false` |
| `bridge.external_url` | Public URL where A2A clients reach the bridge | `https://a2a.example.com` |
| `auth.api_key` | Static API key clients pass in the `X-API-Key` header. Supports env var expansion. | `${A2A_API_KEY}` |
| `projects[].slug` | Grove slug to expose. Add one entry per project. | `my-project` |
Expand Down Expand Up @@ -271,7 +305,7 @@ The container runs as non-root user `bridge` (UID 1000). The state database dire

## Known Limitations

- **No gRPC or REST transport.** The bridge only supports JSON-RPC 2.0 over HTTP. gRPC and HTTP+JSON/REST transports are not implemented.
- **gRPC and REST transports are single-agent.** JSON-RPC routes per request via `/projects/{project}/agents/{agent}/jsonrpc`. The gRPC and HTTP+JSON/REST transports have no per-request routing in the A2A spec, so every request is routed to the first exposed agent of the first configured project. Run one bridge instance per exposed agent if you need more.
- **Blocking-mode `input-required` flows.** In blocking mode, state-change messages are skipped for waiters so the actual content reply is delivered. A blocking `message/send` against an agent that transitions to `input-required` without sending content will time out (default 120s). Use non-blocking mode with push notifications or SSE for `input-required` flows.

## Security considerations
Expand Down
155 changes: 152 additions & 3 deletions extras/scion-a2a-bridge/cmd/scion-a2a-bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"flag"
"fmt"
"log/slog"
"net"
"net/http"
"os"
"os/signal"
Expand All @@ -32,9 +33,12 @@ import (
secretmanager "cloud.google.com/go/secretmanager/apiv1"
smpb "cloud.google.com/go/secretmanager/apiv1/secretmanagerpb"
"github.com/a2aproject/a2a-go/v2/a2a"
a2agrpc "github.com/a2aproject/a2a-go/v2/a2agrpc/v0"
"github.com/a2aproject/a2a-go/v2/a2asrv"
"github.com/a2aproject/a2a-go/v2/a2asrv/taskstore"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"gopkg.in/yaml.v3"

"github.com/GoogleCloudPlatform/scion/extras/scion-a2a-bridge/internal/bridge"
Expand Down Expand Up @@ -176,16 +180,22 @@ func main() {
srv := bridge.NewServer(b, cfg, metrics, log.With("component", "a2a-server"), sdkJSONRPCHandler)
srv.WarnOnOpenAuth()

// Bound non-streaming responses: blocking sends can take up to
// Timeouts.SendMessage, so allow that plus margin. SSE responses opt out of
// this deadline via SSEWriteDeadlineMiddleware, which installs a rolling
// per-write deadline instead.
writeTimeout := cfg.Timeouts.SendMessage + 30*time.Second

httpServer := &http.Server{
Addr: listenAddr,
Handler: srv.Handler(),
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
WriteTimeout: writeTimeout,
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20,
}

errCh := make(chan error, 1)
errCh := make(chan error, 3) // capacity matches the 3 server goroutines (HTTP, gRPC, REST)
go func() {
log.Warn("A2A server starting WITHOUT TLS — ensure TLS is terminated at a reverse proxy (e.g. Caddy, nginx, cloud LB)", "address", listenAddr)
log.Info("A2A protocol server starting", "address", listenAddr)
Expand All @@ -194,8 +204,125 @@ func main() {
}
}()

// Start gRPC server if configured.
// NOTE: gRPC and REST transports require a single-project, single-agent
// configuration because they lack per-request project/agent routing. The
// executor injects the configured default route into every request context.
// Auth uses the same schemes as the JSON-RPC transport (including the
// per-user hubUAT/hubJWT schemes) and can only be disabled by explicitly
// setting bridge.grpc_insecure / bridge.rest_insecure.
var grpcServer *grpc.Server
if cfg.Bridge.GRPCListenAddress != "" {
if len(cfg.Projects) == 0 || len(cfg.Projects[0].ExposedAgents) == 0 {
log.Error("gRPC transport requires at least one project with exposed agents in config")
os.Exit(1)
}
defaultRoute := bridge.RouteInfo{
ProjectSlug: cfg.Projects[0].Slug,
AgentSlug: cfg.Projects[0].ExposedAgents[0],
}
log.Warn("gRPC transport uses fixed routing — all requests go to the first configured agent",
"project", defaultRoute.ProjectSlug, "agent", defaultRoute.AgentSlug)

if !cfg.Bridge.GRPCInsecure {
log.Warn("gRPC transport: auth enabled — clients must provide credentials via gRPC metadata",
"scheme", cfg.Auth.Scheme)
} else {
log.Warn("⚠ gRPC transport: auth DISABLED (grpc_insecure: true) — any client can send requests without credentials",
"address", cfg.Bridge.GRPCListenAddress)
}

grpcServer = grpc.NewServer(
grpc.MaxRecvMsgSize(1<<20), // 1 MB, matching REST/JSON-RPC body limit
grpc.MaxConcurrentStreams(100),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 30 * time.Second,
PermitWithoutStream: true,
}),
grpc.ChainUnaryInterceptor(
srv.AuthUnaryInterceptor(),
bridge.RouteInfoUnaryInterceptor(defaultRoute),
),
grpc.ChainStreamInterceptor(
srv.AuthStreamInterceptor(),
bridge.RouteInfoStreamInterceptor(defaultRoute),
),
)
grpcHandler := a2agrpc.NewHandler(sdkRequestHandler)
grpcHandler.RegisterWith(grpcServer)

grpcListener, err := net.Listen("tcp", cfg.Bridge.GRPCListenAddress)
if err != nil {
log.Error("failed to listen for gRPC", "address", cfg.Bridge.GRPCListenAddress, "error", err)
os.Exit(1)
}

go func() {
log.Info("gRPC transport starting", "address", cfg.Bridge.GRPCListenAddress)
if err := grpcServer.Serve(grpcListener); err != nil {
errCh <- fmt.Errorf("gRPC server: %w", err)
}
}()
}

// Start REST server if configured.
var restServer *http.Server
if cfg.Bridge.RESTListenAddress != "" {
if len(cfg.Projects) == 0 || len(cfg.Projects[0].ExposedAgents) == 0 {
log.Error("REST transport requires at least one project with exposed agents in config")
os.Exit(1)
}
defaultRoute := bridge.RouteInfo{
ProjectSlug: cfg.Projects[0].Slug,
AgentSlug: cfg.Projects[0].ExposedAgents[0],
}
log.Warn("REST transport uses fixed routing — all requests go to the first configured agent",
"project", defaultRoute.ProjectSlug, "agent", defaultRoute.AgentSlug)
if !cfg.Bridge.RESTInsecure {
log.Warn("REST transport: auth enabled — clients must provide credentials via HTTP headers",
"scheme", cfg.Auth.Scheme)
} else {
log.Warn("⚠ REST transport: auth DISABLED (rest_insecure: true) — any client can send requests without credentials",
"address", cfg.Bridge.RESTListenAddress)
}

restHandler := srv.AuthHTTPMiddleware(bridge.MaxBytesReaderMiddleware(1<<20,
bridge.RouteInfoMiddleware(defaultRoute,
bridge.SSEWriteDeadlineMiddleware(
a2asrv.NewRESTHandler(
sdkRequestHandler,
a2asrv.WithTransportKeepAlive(cfg.Timeouts.SSEKeepalive),
),
),
),
))

restServer = &http.Server{
Addr: cfg.Bridge.RESTListenAddress,
Handler: restHandler,
ReadTimeout: 30 * time.Second,
WriteTimeout: writeTimeout, // SSE responses override this with a rolling deadline (SSEWriteDeadlineMiddleware).
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20,
}

go func() {
log.Info("REST transport starting", "address", cfg.Bridge.RESTListenAddress)
if err := restServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
errCh <- fmt.Errorf("REST server: %w", err)
}
}()
}

transports := []string{"JSON-RPC"}
if cfg.Bridge.GRPCListenAddress != "" {
transports = append(transports, "gRPC")
}
if cfg.Bridge.RESTListenAddress != "" {
transports = append(transports, "REST")
}
log.Info("scion-a2a-bridge ready",
"transport", "JSON-RPC",
"transports", transports,
"sdk", "a2a-go/v2",
)

Expand All @@ -217,6 +344,28 @@ func main() {
log.Error("failed to stop A2A server", "error", err)
}

if grpcServer != nil {
grpcStopped := make(chan struct{})
go func() {
grpcServer.GracefulStop()
close(grpcStopped)
}()
select {
case <-grpcStopped:
log.Info("gRPC server stopped gracefully")
case <-shutdownCtx.Done():
log.Warn("gRPC graceful shutdown timed out, forcing stop")
grpcServer.Stop()
}
}
Comment thread
zeroasterisk marked this conversation as resolved.

if restServer != nil {
if err := restServer.Shutdown(shutdownCtx); err != nil {
log.Error("failed to stop REST server", "error", err)
}
log.Info("REST server stopped")
}

// Drain background goroutines before closing the store.
b.Shutdown()

Expand Down
4 changes: 3 additions & 1 deletion extras/scion-a2a-bridge/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.28
github.com/prometheus/client_golang v1.23.2
github.com/prometheus/client_model v0.6.2
google.golang.org/grpc v1.81.1
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -20,6 +21,7 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
cloud.google.com/go/compute/metadata v0.9.0 // indirect
cloud.google.com/go/iam v1.11.0 // indirect
github.com/a2aproject/a2a-go v0.3.15 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/fatih/color v1.16.0 // indirect
Expand All @@ -46,6 +48,7 @@ require (
go.opentelemetry.io/otel/trace v1.43.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.21.0 // indirect
Expand All @@ -57,7 +60,6 @@ require (
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260615183401-62b3387ff324 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260610212136-7ab31c22f7ad // indirect
google.golang.org/grpc v1.81.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)

Expand Down
2 changes: 2 additions & 0 deletions extras/scion-a2a-bridge/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ cloud.google.com/go/iam v1.11.0 h1:KieQ9Pb+LLPak1O3Rv3GgCxhnmkYf7Xyh0P5HfF1jFM=
cloud.google.com/go/iam v1.11.0/go.mod h1:KP+nKGugNJW4LcLx1uEZcq1ok5sQHFaQehQNl4QDgV4=
cloud.google.com/go/secretmanager v1.16.0 h1:19QT7ZsLJ8FSP1k+4esQvuCD7npMJml6hYzilxVyT+k=
cloud.google.com/go/secretmanager v1.16.0/go.mod h1://C/e4I8D26SDTz1f3TQcddhcmiC3rMEl0S1Cakvs3Q=
github.com/a2aproject/a2a-go v0.3.15 h1:h5YpCiPq3jxQ5rIns7oDjPag3ivP8u817AzdA4F+NiI=
github.com/a2aproject/a2a-go v0.3.15/go.mod h1:I7Cm+a1oL+UT6zMoP+roaRE5vdfUa1iQGVN8aSOuZ0I=
github.com/a2aproject/a2a-go/v2 v2.3.1 h1:QWMdOX2UsJ8BJmjs952eo1FRyGsOVl0gFCKeM76AgGE=
github.com/a2aproject/a2a-go/v2 v2.3.1/go.mod h1:mkZr8y2bUgAVQsjs/5fHK7xrRlAHDybMEyxWh2tKRC8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
Loading