From 4beee46dc6c7642316e118a4d3aa51e4b407256e Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 20 May 2025 14:28:06 -0600 Subject: feat: add external authorization service (authzd) with JWT authentication - Add new authzd gRPC service implementing Envoy's external authorization API - Integrate JWT authentication filter in Envoy configuration with claim extraction - Update middleware to support both cookie-based and header-based user authentication - Add comprehensive test coverage for authorization service and server - Configure proper service orchestration with authzd, sparkled, and Envoy - Update build system and Docker configuration for multi-service deployment - Add grpcurl tool for gRPC service debugging and testing This enables fine-grained authorization control through Envoy's ext_authz filter while maintaining backward compatibility with existing cookie-based authentication. --- pkg/pls/log.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'pkg/pls') diff --git a/pkg/pls/log.go b/pkg/pls/log.go index 41efcbf..14eb7db 100644 --- a/pkg/pls/log.go +++ b/pkg/pls/log.go @@ -3,7 +3,9 @@ package pls import ( "context" + "github.com/rs/zerolog" "github.com/xlgmokha/x/pkg/log" + "google.golang.org/grpc" ) func LogError(ctx context.Context, err error) { @@ -11,3 +13,38 @@ func LogError(ctx context.Context, err error) { log.WithFields(ctx, log.Fields{"error": err}) } } + +func LogErrorNow(ctx context.Context, err error) { + defer FlushLog(ctx) + + LogError(ctx, err) +} + +func LogGRPC(logger *zerolog.Logger) grpc.UnaryServerInterceptor { + return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) { + ctx = logger.WithContext(ctx) + + defer FlushLog(ctx) + return handler(ctx, req) + } +} + +func LogGRPCStream(logger *zerolog.Logger) grpc.StreamServerInterceptor { + return func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + ctx := logger.WithContext(ss.Context()) + log.WithFields(ctx, log.Fields{"info": info}) + + defer FlushLog(ctx) + return handler(srv, ss) + } +} + +func FlushLog(ctx context.Context) { + zerolog.Ctx(ctx).Print() +} + +func LogNow(ctx context.Context, fields log.Fields) { + defer FlushLog(ctx) + + log.WithFields(ctx, fields) +} -- cgit v1.2.3