go-agent: github.com/sqreen/go-agent/sdk/middleware/sqgrpc Index | Files

package sqgrpc

import "github.com/sqreen/go-agent/sdk/middleware/sqgrpc"

This package provides gRPC interceptors, which are Sqreen's middleware functions for gRPC allowing to monitor and protect the received requests. In protection mode, it can block and redirect requests according to their IP addresses or identified users using `Identify()` and `MatchSecurityResponse()` methods. SDK methods can be called from request handlers by using the request event record, which can be accessed using `sdk.FromContext()` on the request context.

Usage example:

myServer := grpc.NewServer(

// Example of a unary RPC doing a custom event.
func (s *MyService) MyUnaryRPC(ctx context.Context, req *pb.MyRequest) (*pb.MyResponse, error) {
	// ...

// Example of a streaming RPC identifying a user and checking if it should
// be blocked.
func (s *MyService) MyStreamRPC(req *pb.MyRequest, stream pb.MyService_MyStreamRPCServer) error {
	// Example of globally identifying a user and checking if the request
	// should be aborted.
	uid := sdk.EventUserIdentifiersMap{"uid": "my-uid"}
	sqUser := sdk.FromContext(stream.Ctx).ForUser(uid)
	sqUser.Identify() // Globally associate this user to the current request
	if _, err := sqUser.MatchSecurityResponse(); err != nil {
		// Return this error to stop further handling the request and let
		// Sqreen's	middleware apply and abort the request.
		return err
	// ... not blocked ...


Package Files


func StreamServerInterceptor Uses

func StreamServerInterceptor() grpc.StreamServerInterceptor

func UnaryServerInterceptor Uses

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

Package sqgrpc imports 12 packages (graph). Updated 2019-07-26. Refresh now. Tools for package owners.