Context
connectrpc/authn-go (96 stars) provides authentication middleware for Connect-RPC. It extracts auth info from requests and makes it available in the handler context via a typed interface.
Currently, each service calls identity.TokenService_Introspect individually to validate bearer tokens. This means:
- Auth logic is duplicated across services
- Some services may have subtly different token extraction
- Adding a new auth scheme (e.g., mTLS, API keys) requires changing every service
What authn-go provides
authn.NewMiddleware(func(ctx context.Context, req authn.Request) (any, error) {
// Call identity service to introspect token
token := req.Header().Get("Authorization")
claims, err := identityClient.Introspect(ctx, token)
if err != nil {
return nil, authn.Errorf("invalid token: %v", err)
}
return claims, nil
})
Then in any handler:
claims := authn.GetInfo[*Claims](ctx)
// claims.OrgID, claims.AgentID, claims.Scopes etc.
Integration with service-runtime
This belongs in service-runtime alongside the otelconnect interceptor (PR #132). Services compose interceptors:
mux.Handle(svcconnect.NewGovernanceServiceHandler(&handler{},
connect.WithInterceptors(
observability.ConnectOTelInterceptor(), // tracing
authmw.ConnectAuthInterceptor(identityClient), // auth
// future: validate.NewInterceptor() // validation
),
))
Design decision needed
The authmw package already exists in service-runtime. This issue is about evaluating whether connectrpc/authn-go replaces or wraps the existing implementation. Key question: does the existing authmw package already call TokenService_Introspect? If so, this may be a refactor to use authn-go's middleware pattern rather than a net-new addition.
References
Context
connectrpc/authn-go(96 stars) provides authentication middleware for Connect-RPC. It extracts auth info from requests and makes it available in the handler context via a typed interface.Currently, each service calls
identity.TokenService_Introspectindividually to validate bearer tokens. This means:What authn-go provides
Then in any handler:
Integration with service-runtime
This belongs in
service-runtimealongside the otelconnect interceptor (PR #132). Services compose interceptors:Design decision needed
The
authmwpackage already exists in service-runtime. This issue is about evaluating whetherconnectrpc/authn-goreplaces or wraps the existing implementation. Key question: does the existingauthmwpackage already callTokenService_Introspect? If so, this may be a refactor to use authn-go's middleware pattern rather than a net-new addition.References